소스 검색

show volcano version and runtime

Thomas Buck 11 달 전
부모
커밋
8f8903435d
5개의 변경된 파일83개의 추가작업 그리고 12개의 파일을 삭제
  1. 11
    9
      include/menu.h
  2. 10
    2
      include/volcano.h
  3. 7
    0
      src/console.c
  4. 6
    1
      src/state_volcano_conf.c
  5. 49
    0
      src/volcano.c

+ 11
- 9
include/menu.h 파일 보기

@@ -45,17 +45,19 @@ void menu_run(void (*cb)(struct menu_state *), bool centered);
45 45
 
46 46
 extern bool menu_got_input;
47 47
 
48
-#define ADD_STATIC_ELEMENT(name) {\
49
-    menu->length += 1; \
50
-    if (((menu->length - 1) >= menu->off) \
51
-        && ((menu->length - 1 - menu->off) < menu->lines)) { \
52
-        if ((menu->length - 1) == menu->selection) { \
48
+#define ADD_STATIC_ELEMENT(format, ...) {                                \
49
+    menu->length += 1;                                                   \
50
+    if (((menu->length - 1) >= menu->off)                                \
51
+        && ((menu->length - 1 - menu->off) < menu->lines)) {             \
52
+        if ((menu->length - 1) == menu->selection) {                     \
53 53
             pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, "> "); \
54
-        } else { \
54
+        } else {                                                         \
55 55
             pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, "  "); \
56
-        } \
57
-        pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, name "\n"); \
58
-    } \
56
+        }                                                                \
57
+        pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos,            \
58
+                        format __VA_OPT__(,) __VA_ARGS__);               \
59
+        pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, "\n");     \
60
+    }                                                                    \
59 61
 }
60 62
 
61 63
 #endif // __MENU_H__

+ 10
- 2
include/volcano.h 파일 보기

@@ -24,6 +24,8 @@
24 24
 
25 25
 #include "models.h"
26 26
 
27
+#define VOLCANO_FW_LEN 12
28
+
27 29
 enum volcano_state {
28 30
     VOLCANO_STATE_NONE = 0,
29 31
     VOLCANO_STATE_HEATER = (1 << 0),
@@ -61,10 +63,16 @@ int16_t volcano_get_auto_shutoff(void);
61 63
 // v in seconds, returns < 0 on error
62 64
 int8_t volcano_set_auto_shutoff(uint16_t v);
63 65
 
64
-// returns 0-10, or < 0 on error
66
+// returns 0 - 100, or < 0 on error
65 67
 int8_t volcano_get_brightness(void);
66 68
 
67
-// v in 0-10, returns < 0 on error
69
+// v in 0 - 100, returns < 0 on error
68 70
 int8_t volcano_set_brightness(uint8_t v);
69 71
 
72
+// val is filled with VOLCANO_FW_LEN bytes, returns < 0 on error
73
+int8_t volcano_get_firmware(char *val);
74
+
75
+// returns minutes, or < 0 on error
76
+int32_t volcano_get_runtime(void);
77
+
70 78
 #endif // __VOLCANO_H__

+ 7
- 0
src/console.c 파일 보기

@@ -283,6 +283,13 @@ static void cnsl_interpret(const char *line) {
283 283
         r = volcano_get_brightness();
284 284
         println("volcano brightness: %d", r);
285 285
 
286
+        char fw[VOLCANO_FW_LEN + 1] = {0};
287
+        r = volcano_get_firmware(fw);
288
+        println("volcano firmware: %s", fw);
289
+
290
+        int32_t rt = volcano_get_runtime();
291
+        println("volcano runtime: %ld min", rt);
292
+
286 293
 #ifdef TEST_VOLCANO_AUTO_CONNECT
287 294
         ble_disconnect();
288 295
 #endif // TEST_VOLCANO_AUTO_CONNECT

+ 6
- 1
src/state_volcano_conf.c 파일 보기

@@ -37,6 +37,8 @@ static bool val_vibrate = false;
37 37
 static bool val_disp_cool = false;
38 38
 static uint16_t val_auto_shutoff = 0;
39 39
 static uint8_t val_brightness = 0;
40
+static char val_fw[VOLCANO_FW_LEN] = {0};
41
+static int32_t val_rt = 0;
40 42
 
41 43
 void state_volcano_conf_target(bd_addr_t addr, bd_addr_type_t type) {
42 44
     debug("%s %d", bd_addr_to_str(addr), type);
@@ -125,8 +127,9 @@ static void fetch_values(void) {
125 127
     val_disp_cool = (r == 1);
126 128
 
127 129
     val_auto_shutoff = volcano_get_auto_shutoff();
128
-
129 130
     val_brightness = volcano_get_brightness();
131
+    volcano_get_firmware(val_fw);
132
+    val_rt = volcano_get_runtime();
130 133
 }
131 134
 
132 135
 static void exit_cb(void) {
@@ -171,6 +174,8 @@ static void draw(struct menu_state *menu) {
171 174
     ADD_STATIC_ELEMENT("Disp. Cool");
172 175
     ADD_STATIC_ELEMENT("Auto Shutoff");
173 176
     ADD_STATIC_ELEMENT("Brightness");
177
+    ADD_STATIC_ELEMENT("FW: %s", val_fw);
178
+    ADD_STATIC_ELEMENT("RT: %.1f h", val_rt / 60.0f);
174 179
 
175 180
     if (menu->selection < 0) {
176 181
         menu->selection = 0;

+ 49
- 0
src/volcano.c 파일 보기

@@ -22,6 +22,7 @@
22 22
 #include "volcano.h"
23 23
 
24 24
 #define UUID_SRVC_1       0x10
25
+#define UUID_FIRMWARE     0x03
25 26
 #define UUID_PRJSTAT1     0x0C
26 27
 #define UUID_PRJSTAT2     0x0D
27 28
 #define UUID_PRJSTAT3     0x0E
@@ -36,6 +37,8 @@
36 37
 #define UUID_HEATER_OFF   0x10
37 38
 #define UUID_PUMP_ON      0x13
38 39
 #define UUID_PUMP_OFF     0x14
40
+#define UUID_HEAT_HOURS   0x15
41
+#define UUID_HEAT_MINUTES 0x16
39 42
 
40 43
 #define MASK_PRJSTAT1_HEIZUNG_ENA        0x0020
41 44
 #define MASK_PRJSTAT1_AUTOBLESHUTDOWN    0x0200
@@ -381,3 +384,49 @@ int8_t volcano_set_brightness(uint8_t val) {
381 384
     }
382 385
     return r;
383 386
 }
387
+
388
+int8_t volcano_get_firmware(char *val) {
389
+    if (val == NULL) {
390
+        return -1;
391
+    }
392
+
393
+    uuid_base[1] = UUID_SRVC_1;
394
+    uuid_base[3] = UUID_FIRMWARE;
395
+
396
+    uint8_t buff[VOLCANO_FW_LEN];
397
+    int32_t r = ble_read(uuid_base, buff, sizeof(buff));
398
+    if (r != sizeof(buff)) {
399
+        debug("ble_read unexpected value %ld", r);
400
+        return -1;
401
+    }
402
+
403
+    memcpy(val, buff, sizeof(buff));
404
+    return 0;
405
+}
406
+
407
+int32_t volcano_get_runtime(void) {
408
+    int32_t val = 0;
409
+
410
+    uuid_base[1] = UUID_SRVC_2;
411
+    uuid_base[3] = UUID_HEAT_HOURS;
412
+
413
+    uint32_t buff;
414
+    int32_t r = ble_read(uuid_base, (uint8_t *)&buff, sizeof(buff));
415
+    if (r != sizeof(buff)) {
416
+        debug("ble_read 1 unexpected value %ld", r);
417
+        return -1;
418
+    }
419
+
420
+    val = buff * 60;
421
+    uuid_base[3] = UUID_HEAT_MINUTES;
422
+
423
+    uint16_t buff2;
424
+    r = ble_read(uuid_base, (uint8_t *)&buff2, sizeof(buff2));
425
+    if (r != sizeof(buff2)) {
426
+        debug("ble_read 2 unexpected value %ld", r);
427
+        return -1;
428
+    }
429
+
430
+    val += buff2;
431
+    return val;
432
+}

Loading…
취소
저장