Przeglądaj źródła

optional auto connect for volcano console commands.

Thomas Buck 7 miesięcy temu
rodzic
commit
0d8e77dd69
2 zmienionych plików z 33 dodań i 2 usunięć
  1. 32
    0
      src/console.c
  2. 1
    2
      src/volcano.c

+ 32
- 0
src/console.c Wyświetl plik

@@ -39,6 +39,22 @@
39 39
 #define CNSL_BUFF_SIZE 1024
40 40
 #define CNSL_REPEAT_MS 500
41 41
 
42
+//#define TEST_VOLCANO_AUTO_CONNECT "xx:xx:xx:xx:xx:xx 1"
43
+
44
+#define VOLCANO_AUTO_CONNECT {                                    \
45
+    ble_scan(BLE_SCAN_OFF);                                       \
46
+    bd_addr_t addr;                                               \
47
+    bd_addr_type_t type;                                          \
48
+    const char *foo = TEST_VOLCANO_AUTO_CONNECT;                  \
49
+    sscanf(foo, "%02hhX:%02hhX:%02hhX:%02hhX:%02hhX:%02hhX %hhu", \
50
+            &addr[0], &addr[1], &addr[2], &addr[3],               \
51
+            &addr[4], &addr[5], &type);                           \
52
+    ble_connect(addr, type);                                      \
53
+    while (!ble_is_connected()) {                                 \
54
+        sleep_ms(1);                                              \
55
+    }                                                             \
56
+}
57
+
42 58
 static char cnsl_line_buff[CNSL_BUFF_SIZE + 1];
43 59
 static uint32_t cnsl_buff_pos = 0;
44 60
 
@@ -197,11 +213,27 @@ static void cnsl_interpret(const char *line) {
197 213
     } else if (strcmp(line, "bat") == 0) {
198 214
         draw_battery_indicator();
199 215
     } else if (strcmp(line, "vrct") == 0) {
216
+#ifdef TEST_VOLCANO_AUTO_CONNECT
217
+        VOLCANO_AUTO_CONNECT
218
+#endif // TEST_VOLCANO_AUTO_CONNECT
219
+
200 220
         int16_t r = volcano_get_current_temp();
201 221
         println("volcano current temp: %.1f", r / 10.0);
222
+
223
+#ifdef TEST_VOLCANO_AUTO_CONNECT
224
+        ble_disconnect();
225
+#endif // TEST_VOLCANO_AUTO_CONNECT
202 226
     } else if (strcmp(line, "vrtt") == 0) {
227
+#ifdef TEST_VOLCANO_AUTO_CONNECT
228
+        VOLCANO_AUTO_CONNECT
229
+#endif // TEST_VOLCANO_AUTO_CONNECT
230
+
203 231
         int16_t r = volcano_get_target_temp();
204 232
         println("volcano target temp: %.1f", r / 10.0);
233
+
234
+#ifdef TEST_VOLCANO_AUTO_CONNECT
235
+        ble_disconnect();
236
+#endif // TEST_VOLCANO_AUTO_CONNECT
205 237
     } else {
206 238
         println("unknown command \"%s\"", line);
207 239
     }

+ 1
- 2
src/volcano.c Wyświetl plik

@@ -23,7 +23,6 @@
23 23
 #include "volcano.h"
24 24
 
25 25
 // Volcano UUIDs are always the same, except for the 4th byte
26
-
27 26
 #define UUID_CURRENT_TEMP 0x01
28 27
 #define UUID_TARGET_TEMP  0x03
29 28
 #define UUID_HEATER_ON    0x0F
@@ -31,7 +30,7 @@
31 30
 #define UUID_PUMP_ON      0x13
32 31
 #define UUID_PUMP_OFF     0x14
33 32
 
34
-// "101100FF-5354-4f52-5a26-4249434b454c"
33
+// "101100xx-5354-4f52-5a26-4249434b454c"
35 34
 static uint8_t uuid_base[16] = {
36 35
     0x10, 0x11, 0x00, 0xFF, 0x53, 0x54, 0x4f, 0x52,
37 36
     0x5a, 0x26, 0x42, 0x49, 0x43, 0x4b, 0x45, 0x4c,

Ładowanie…
Anuluj
Zapisz