Browse Source

optional auto connect for volcano console commands.

Thomas Buck 1 year ago
parent
commit
0d8e77dd69
2 changed files with 33 additions and 2 deletions
  1. 32
    0
      src/console.c
  2. 1
    2
      src/volcano.c

+ 32
- 0
src/console.c View File

39
 #define CNSL_BUFF_SIZE 1024
39
 #define CNSL_BUFF_SIZE 1024
40
 #define CNSL_REPEAT_MS 500
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
 static char cnsl_line_buff[CNSL_BUFF_SIZE + 1];
58
 static char cnsl_line_buff[CNSL_BUFF_SIZE + 1];
43
 static uint32_t cnsl_buff_pos = 0;
59
 static uint32_t cnsl_buff_pos = 0;
44
 
60
 
197
     } else if (strcmp(line, "bat") == 0) {
213
     } else if (strcmp(line, "bat") == 0) {
198
         draw_battery_indicator();
214
         draw_battery_indicator();
199
     } else if (strcmp(line, "vrct") == 0) {
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
         int16_t r = volcano_get_current_temp();
220
         int16_t r = volcano_get_current_temp();
201
         println("volcano current temp: %.1f", r / 10.0);
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
     } else if (strcmp(line, "vrtt") == 0) {
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
         int16_t r = volcano_get_target_temp();
231
         int16_t r = volcano_get_target_temp();
204
         println("volcano target temp: %.1f", r / 10.0);
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
     } else {
237
     } else {
206
         println("unknown command \"%s\"", line);
238
         println("unknown command \"%s\"", line);
207
     }
239
     }

+ 1
- 2
src/volcano.c View File

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

Loading…
Cancel
Save