]> mj.ucw.cz Git - home-hw.git/commitdiff
test-sinclair: Debugging RC
authorMartin Mares <mj@ucw.cz>
Fri, 14 Jul 2023 15:42:27 +0000 (17:42 +0200)
committerMartin Mares <mj@ucw.cz>
Fri, 14 Jul 2023 15:42:27 +0000 (17:42 +0200)
test-sinclair/main.c

index 7cfe1b427507c088a3400adc54b38175196b4f92..5e90ecf8d864bb21f10dacf2f201b01ed6ca643d 100644 (file)
@@ -370,9 +370,9 @@ enum rc_mode {
        MODE_DEHUMIDIFY,
 };
 
-static byte rc_mode;           // MODE_xxx
-static byte rc_fan;            // 0-3
-static byte rc_temp;           // 17-30
+static byte rc_mode = MODE_COOL;       // MODE_xxx
+static byte rc_fan;                    // 0-3
+static byte rc_temp = 17;              // 17-30
 
 static void rc_init(void)
 {
@@ -424,7 +424,7 @@ void tim4_isr(void)
                bool val;       // 1=pulse, 0=break
                uint duration;  // in μs
 
-               switch (rc_tick++) {
+               switch (rc_tick) {
                        case 0:
                                // Better be safe
                                return;
@@ -433,11 +433,13 @@ void tim4_isr(void)
                                // Initial / final marker
                                val = 0;
                                duration = 3600;
+                               // debug_putc('#');
                                break;
                        case 110:
                                // Inter-packet gap
                                val = 0;
                                duration = 10000;
+                               // debug_putc('$');
                                break;
                        case 111:
                                // End of message
@@ -447,17 +449,23 @@ void tim4_isr(void)
                                if (rc_tick % 2) {
                                        val = 1;
                                        duration = 565;
+                                       // debug_putc('*');
                                } else {
                                        // Even ticks 4 to 106 transmit 52 bits of data
                                        uint i = 12 + (rc_tick - 4) / 2;
                                        val = 0;
-                                       if (rc_pattern[i>>5] & (1 << (i & 31)))
+                                       if (rc_pattern[i>>5] & (0x80000000 >> (i & 31))) {
                                                duration = 1471;
-                                       else
+                                               // debug_putc('B');
+                                       } else {
                                                duration = 480;
+                                               // debug_putc('A');
+                                       }
                                }
                }
 
+               rc_tick++;
+
                if (val)
                        gpio_set(GPIOA, GPIO8);
                else
@@ -475,7 +483,9 @@ static void rc_send(void)
                return;
 
        rc_encode();
-       debug_printf("RC sending: %05x %08x\n", (uint) rc_pattern[0], (uint) rc_pattern[1]);
+       debug_printf("RC sending: %05x %08x (mode=%d, fan=%d, temp=%d)\n",
+               (uint) rc_pattern[0], (uint) rc_pattern[1],
+               rc_mode, rc_fan, rc_temp);
        rc_tick = 1;
 
        timer_set_period(TIM4, 1);