diff --git a/hygain-ir-controller.ino b/hygain-ir-controller.ino
index bacd376..67f46bf 100644
--- a/hygain-ir-controller.ino
+++ b/hygain-ir-controller.ino
@@ -14,6 +14,7 @@ const char* password = "xxxxxxx";
AsyncWebServer server(80);
const char* input_heading = "heading";
+const char* input_memory = "memory";
char headingmap[360];
@@ -58,43 +59,43 @@ const char index_html[] PROGMEM = R"rawliteral(
- | | | | | | | | | | | | |
+ | | | | | | | | | | | | |
- | | | | | | | | | | | | |
+ | | | | | | | | | | | | |
- | | | | | | | | | | | | |
+ | | | | | | | | | | | | |
- | | | | | | N | | | | | | |
+ | | | | | | N | | | | | | |
- | | | | | | | | | | | | |
+ | | | | | | | | | | | | |
- | | | | | | | | | | | | |
+ | | | | | | | | | | | | |
- | | | W | | | | | | E | | | |
+ | | | W | | | | | | E | | | |
- | | | | | | | | | | | | |
+ | | | | | | | | | | | | |
- | | | | | | | | | | | | |
+ | | | | | | | | | | | | |
- | | | | | | S | | | | | | |
+ | | | | | | S | | | | | | |
- | | | | | | | | | | | | |
+ | | | | | | | | | | | | |
- | | | | | | | | | | | | |
+ | | | | | | | | | | | | |
- | | | | | | | | | | | | |
+ | | | | | | | | | | | | |
@@ -117,6 +118,32 @@ const uint16_t getValueByKey(char key) {
}
+char lookupLetter(int angle) {
+ // Adjust angle to be within 0 and 360
+ angle %= 360;
+ if (angle < 0) {
+ angle += 360;
+ }
+
+ // Define the lookup table
+ const int angles[] = {0, 15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180,
+ 195, 210, 225, 240, 255, 270, 285, 300, 315, 330, 345, 360};
+ const char letters[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'A'};
+
+ // Find the closest angle in the table
+ int closestAngleIndex = 0;
+ for (int i = 1; i < 26; ++i) {
+ if (abs(angles[i] - angle) < abs(angles[closestAngleIndex] - angle)) {
+ closestAngleIndex = i;
+ }
+ }
+
+ // Return the corresponding letter
+ return letters[closestAngleIndex];
+}
+
+
void setup() {
// Start serial
@@ -167,18 +194,23 @@ void setup() {
server.on("/get", HTTP_GET, [] (AsyncWebServerRequest *request) {
String input_message;
- String input_parameter;
+ char mem;
+ if (request->hasParam(input_memory)) {
+ input_message = request->getParam(input_memory)->value();
+ mem = input_message[0];
+ }
if (request->hasParam(input_heading)) {
- input_message = request->getParam(input_heading)->value();
- input_parameter = input_heading;
+ int angle = request->getParam(input_heading)->value().toInt();
+
+ char letter = lookupLetter(angle);
+ mem = letter;
}
else {
input_message = "No message sent";
- input_parameter = "none";
}
- Serial.println(input_message);
- uint16_t val = getValueByKey(input_message[0]);
+ Serial.println(String(mem));
+ uint16_t val = getValueByKey(mem);
Serial.println("IR Code: " + String(val));
irsend.sendNEC(0x0, val, 2);
delay(500);