Browse Source

volcano brightness and auto shutoff conf

Thomas Buck 11 months ago
parent
commit
fc1635c03a
4 changed files with 110 additions and 1 deletions
  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 View File

55
 int8_t volcano_get_vibration(void);
55
 int8_t volcano_get_vibration(void);
56
 int8_t volcano_get_display_cooling(void);
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
 #endif // __VOLCANO_H__
70
 #endif // __VOLCANO_H__

+ 6
- 0
src/console.c View File

277
         r = volcano_get_display_cooling();
277
         r = volcano_get_display_cooling();
278
         println("volcano display cooling: %d", r);
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
 #ifdef TEST_VOLCANO_AUTO_CONNECT
286
 #ifdef TEST_VOLCANO_AUTO_CONNECT
281
         ble_disconnect();
287
         ble_disconnect();
282
 #endif // TEST_VOLCANO_AUTO_CONNECT
288
 #endif // TEST_VOLCANO_AUTO_CONNECT

+ 32
- 0
src/state_volcano_conf.c View File

35
 static bool val_celsius = false;
35
 static bool val_celsius = false;
36
 static bool val_vibrate = false;
36
 static bool val_vibrate = false;
37
 static bool val_disp_cool = false;
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
 void state_volcano_conf_target(bd_addr_t addr, bd_addr_type_t type) {
41
 void state_volcano_conf_target(bd_addr_t addr, bd_addr_type_t type) {
40
     debug("%s %d", bd_addr_to_str(addr), type);
42
     debug("%s %d", bd_addr_to_str(addr), type);
75
         state_value_return(STATE_VOLCANO_CONF);
77
         state_value_return(STATE_VOLCANO_CONF);
76
         state_switch(STATE_VALUE);
78
         state_switch(STATE_VALUE);
77
         break;
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
     volcano_set_vibration(val_vibrate);
106
     volcano_set_vibration(val_vibrate);
85
     sleep_ms(150);
107
     sleep_ms(150);
86
     volcano_set_display_cooling(val_disp_cool);
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
 static void fetch_values(void) {
115
 static void fetch_values(void) {
97
 
123
 
98
     r = volcano_get_display_cooling();
124
     r = volcano_get_display_cooling();
99
     val_disp_cool = (r == 1);
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
 static void exit_cb(void) {
132
 static void exit_cb(void) {
139
     ADD_STATIC_ELEMENT("Celsius");
169
     ADD_STATIC_ELEMENT("Celsius");
140
     ADD_STATIC_ELEMENT("Vibrate");
170
     ADD_STATIC_ELEMENT("Vibrate");
141
     ADD_STATIC_ELEMENT("Disp. Cool");
171
     ADD_STATIC_ELEMENT("Disp. Cool");
172
+    ADD_STATIC_ELEMENT("Auto Shutoff");
173
+    ADD_STATIC_ELEMENT("Brightness");
142
 
174
 
143
     if (menu->selection < 0) {
175
     if (menu->selection < 0) {
144
         menu->selection = 0;
176
         menu->selection = 0;

+ 60
- 1
src/volcano.c View File

30
 #define UUID_WRITE_SRVC   0x00
30
 #define UUID_WRITE_SRVC   0x00
31
 #define UUID_CURRENT_TEMP 0x01
31
 #define UUID_CURRENT_TEMP 0x01
32
 #define UUID_TARGET_TEMP  0x03
32
 #define UUID_TARGET_TEMP  0x03
33
+#define UUID_BRIGHTNESS   0x05
34
+#define UUID_SHUTOFF_TIME 0x0D
33
 #define UUID_HEATER_ON    0x0F
35
 #define UUID_HEATER_ON    0x0F
34
 #define UUID_HEATER_OFF   0x10
36
 #define UUID_HEATER_OFF   0x10
35
 #define UUID_PUMP_ON      0x13
37
 #define UUID_PUMP_ON      0x13
305
         debug("ble_write unexpected value %d", r);
307
         debug("ble_write unexpected value %d", r);
306
     }
308
     }
307
     return r;
309
     return r;
308
-
309
 }
310
 }
310
 
311
 
311
 int8_t volcano_get_display_cooling(void) {
312
 int8_t volcano_get_display_cooling(void) {
322
     uint32_t *v = (uint32_t *)buff;
323
     uint32_t *v = (uint32_t *)buff;
323
     return (*v & MASK_PRJSTAT2_DISPLAY_ON_COOLING) ? 0 : 1;
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…
Cancel
Save