瀏覽代碼

volcano brightness and auto shutoff conf

Thomas Buck 5 月之前
父節點
當前提交
fc1635c03a
共有 4 個檔案被更改,包括 110 行新增1 行删除
  1. 12
    0
      include/volcano.h
  2. 6
    0
      src/console.c
  3. 32
    0
      src/state_volcano_conf.c
  4. 60
    1
      src/volcano.c

+ 12
- 0
include/volcano.h 查看文件

@@ -55,4 +55,16 @@ enum volcano_state volcano_get_state(void);
55 55
 int8_t volcano_get_vibration(void);
56 56
 int8_t volcano_get_display_cooling(void);
57 57
 
58
+// returns seconds, or < 0 on error
59
+int16_t volcano_get_auto_shutoff(void);
60
+
61
+// v in seconds, returns < 0 on error
62
+int8_t volcano_set_auto_shutoff(uint16_t v);
63
+
64
+// returns 0-10, or < 0 on error
65
+int8_t volcano_get_brightness(void);
66
+
67
+// v in 0-10, returns < 0 on error
68
+int8_t volcano_set_brightness(uint8_t v);
69
+
58 70
 #endif // __VOLCANO_H__

+ 6
- 0
src/console.c 查看文件

@@ -277,6 +277,12 @@ static void cnsl_interpret(const char *line) {
277 277
         r = volcano_get_display_cooling();
278 278
         println("volcano display cooling: %d", r);
279 279
 
280
+        int16_t time = volcano_get_auto_shutoff();
281
+        println("volcano auto shutoff: %d", time);
282
+
283
+        r = volcano_get_brightness();
284
+        println("volcano brightness: %d", r);
285
+
280 286
 #ifdef TEST_VOLCANO_AUTO_CONNECT
281 287
         ble_disconnect();
282 288
 #endif // TEST_VOLCANO_AUTO_CONNECT

+ 32
- 0
src/state_volcano_conf.c 查看文件

@@ -35,6 +35,8 @@ static bool connected = false;
35 35
 static bool val_celsius = false;
36 36
 static bool val_vibrate = false;
37 37
 static bool val_disp_cool = false;
38
+static uint16_t val_auto_shutoff = 0;
39
+static uint8_t val_brightness = 0;
38 40
 
39 41
 void state_volcano_conf_target(bd_addr_t addr, bd_addr_type_t type) {
40 42
     debug("%s %d", bd_addr_to_str(addr), type);
@@ -75,6 +77,26 @@ static void enter_cb(int selection) {
75 77
         state_value_return(STATE_VOLCANO_CONF);
76 78
         state_switch(STATE_VALUE);
77 79
         break;
80
+
81
+    case 3:
82
+        // Auto Shutoff
83
+        state_value_set(&val_auto_shutoff,
84
+                        sizeof(val_auto_shutoff),
85
+                        0, 60 * 60, VAL_STEP_INCREMENT, 60,
86
+                        "Auto Shutoff");
87
+        state_value_return(STATE_VOLCANO_CONF);
88
+        state_switch(STATE_VALUE);
89
+        break;
90
+
91
+    case 4:
92
+        // Brightness
93
+        state_value_set(&val_brightness,
94
+                        sizeof(val_brightness),
95
+                        0, 100, VAL_STEP_INCREMENT, 10,
96
+                        "Brightness");
97
+        state_value_return(STATE_VOLCANO_CONF);
98
+        state_switch(STATE_VALUE);
99
+        break;
78 100
     }
79 101
 }
80 102
 
@@ -84,6 +106,10 @@ static void send_values(void) {
84 106
     volcano_set_vibration(val_vibrate);
85 107
     sleep_ms(150);
86 108
     volcano_set_display_cooling(val_disp_cool);
109
+    sleep_ms(150);
110
+    volcano_set_auto_shutoff(val_auto_shutoff);
111
+    sleep_ms(150);
112
+    volcano_set_brightness(val_brightness);
87 113
 }
88 114
 
89 115
 static void fetch_values(void) {
@@ -97,6 +123,10 @@ static void fetch_values(void) {
97 123
 
98 124
     r = volcano_get_display_cooling();
99 125
     val_disp_cool = (r == 1);
126
+
127
+    val_auto_shutoff = volcano_get_auto_shutoff();
128
+
129
+    val_brightness = volcano_get_brightness();
100 130
 }
101 131
 
102 132
 static void exit_cb(void) {
@@ -139,6 +169,8 @@ static void draw(struct menu_state *menu) {
139 169
     ADD_STATIC_ELEMENT("Celsius");
140 170
     ADD_STATIC_ELEMENT("Vibrate");
141 171
     ADD_STATIC_ELEMENT("Disp. Cool");
172
+    ADD_STATIC_ELEMENT("Auto Shutoff");
173
+    ADD_STATIC_ELEMENT("Brightness");
142 174
 
143 175
     if (menu->selection < 0) {
144 176
         menu->selection = 0;

+ 60
- 1
src/volcano.c 查看文件

@@ -30,6 +30,8 @@
30 30
 #define UUID_WRITE_SRVC   0x00
31 31
 #define UUID_CURRENT_TEMP 0x01
32 32
 #define UUID_TARGET_TEMP  0x03
33
+#define UUID_BRIGHTNESS   0x05
34
+#define UUID_SHUTOFF_TIME 0x0D
33 35
 #define UUID_HEATER_ON    0x0F
34 36
 #define UUID_HEATER_OFF   0x10
35 37
 #define UUID_PUMP_ON      0x13
@@ -305,7 +307,6 @@ int8_t volcano_set_display_cooling(bool value) {
305 307
         debug("ble_write unexpected value %d", r);
306 308
     }
307 309
     return r;
308
-
309 310
 }
310 311
 
311 312
 int8_t volcano_get_display_cooling(void) {
@@ -322,3 +323,61 @@ int8_t volcano_get_display_cooling(void) {
322 323
     uint32_t *v = (uint32_t *)buff;
323 324
     return (*v & MASK_PRJSTAT2_DISPLAY_ON_COOLING) ? 0 : 1;
324 325
 }
326
+
327
+int16_t volcano_get_auto_shutoff(void) {
328
+    uuid_base[1] = UUID_SRVC_2;
329
+    uuid_base[3] = UUID_SHUTOFF_TIME;
330
+
331
+    uint8_t buff[2];
332
+    int32_t r = ble_read(uuid_base, buff, sizeof(buff));
333
+    if (r != sizeof(buff)) {
334
+        debug("ble_read unexpected value %ld", r);
335
+        return -1;
336
+    }
337
+
338
+    uint16_t *v = (uint16_t *)buff;
339
+    return *v;
340
+
341
+}
342
+
343
+int8_t volcano_set_auto_shutoff(uint16_t v) {
344
+    uuid_base[1] = UUID_SRVC_2;
345
+    uuid_base2[1] = UUID_SRVC_2;
346
+    uuid_base[3] = UUID_WRITE_SRVC;
347
+    uuid_base2[3] = UUID_SHUTOFF_TIME;
348
+
349
+    int8_t r = ble_write(uuid_base, uuid_base2, (uint8_t *)&v, sizeof(v));
350
+    if (r != 0) {
351
+        debug("ble_write unexpected value %d", r);
352
+    }
353
+    return r;
354
+}
355
+
356
+int8_t volcano_get_brightness(void) {
357
+    uuid_base[1] = UUID_SRVC_2;
358
+    uuid_base[3] = UUID_BRIGHTNESS;
359
+
360
+    uint8_t buff[2];
361
+    int32_t r = ble_read(uuid_base, buff, sizeof(buff));
362
+    if (r != sizeof(buff)) {
363
+        debug("ble_read unexpected value %ld", r);
364
+        return -1;
365
+    }
366
+
367
+    uint16_t *v = (uint16_t *)buff;
368
+    return *v;
369
+}
370
+
371
+int8_t volcano_set_brightness(uint8_t val) {
372
+    uuid_base[1] = UUID_SRVC_2;
373
+    uuid_base2[1] = UUID_SRVC_2;
374
+    uuid_base[3] = UUID_WRITE_SRVC;
375
+    uuid_base2[3] = UUID_BRIGHTNESS;
376
+
377
+    uint16_t v = val;
378
+    int8_t r = ble_write(uuid_base, uuid_base2, (uint8_t *)&v, sizeof(v));
379
+    if (r != 0) {
380
+        debug("ble_write unexpected value %d", r);
381
+    }
382
+    return r;
383
+}

Loading…
取消
儲存