Ver código fonte

untested venty handler

Thomas Buck 11 meses atrás
pai
commit
a241f8695b
13 arquivos alterados com 522 adições e 9 exclusões
  1. 2
    0
      CMakeLists.txt
  2. 1
    0
      README.md
  3. 5
    1
      include/models.h
  4. 1
    0
      include/state.h
  5. 30
    0
      include/state_venty.h
  6. 43
    0
      include/venty.h
  7. 1
    0
      picowota
  8. 2
    1
      src/console.c
  9. 33
    6
      src/models.c
  10. 6
    0
      src/state.c
  11. 11
    1
      src/state_scan.c
  12. 178
    0
      src/state_venty.c
  13. 209
    0
      src/venty.c

+ 2
- 0
CMakeLists.txt Ver arquivo

@@ -95,6 +95,8 @@ target_sources(gadget PUBLIC
95 95
     src/state_value.c
96 96
     src/textbox.c
97 97
     src/state_volcano_conf.c
98
+    src/venty.c
99
+    src/state_venty.c
98 100
 
99 101
     ${CMAKE_CURRENT_BINARY_DIR}/fatfs/ff.c
100 102
     ${CMAKE_CURRENT_BINARY_DIR}/fatfs/ffunicode.c

+ 1
- 0
README.md Ver arquivo

@@ -4,6 +4,7 @@ Supports:
4 4
 
5 5
  * workflows for the Volcano Hybrid
6 6
  * basic status and settings for Crafty+
7
+ * some settings for Venty (untested)
7 8
 
8 9
 For use with Raspberry Pi Pico W boards with the [Waveshare Pico LCD 1.3](https://www.waveshare.com/wiki/Pico-LCD-1.3) and the [Pimoroni Pico Lipo Shim](https://shop.pimoroni.com/products/pico-lipo-shim).
9 10
 

+ 5
- 1
include/models.h Ver arquivo

@@ -25,6 +25,7 @@ enum known_devices {
25 25
     DEV_UNKNOWN = 0,
26 26
     DEV_VOLCANO,
27 27
     DEV_CRAFTY,
28
+    DEV_VENTY,
28 29
 };
29 30
 
30 31
 enum unit {
@@ -34,6 +35,9 @@ enum unit {
34 35
 };
35 36
 
36 37
 enum known_devices models_filter_name(const char *name);
37
-int8_t models_get_serial(const uint8_t *data, size_t data_len, char *buff, size_t buff_len);
38
+
39
+int8_t models_get_serial(enum known_devices dev, const char *name,
40
+                         const uint8_t *data, size_t data_len,
41
+                         char *buff, size_t buff_len);
38 42
 
39 43
 #endif // __MODELS_H__

+ 1
- 0
include/state.h Ver arquivo

@@ -30,6 +30,7 @@ enum system_state {
30 30
     STATE_ABOUT,
31 31
     STATE_VALUE,
32 32
     STATE_VOLCANO_CONF,
33
+    STATE_VENTY,
33 34
 
34 35
     STATE_INVALID,
35 36
 };

+ 30
- 0
include/state_venty.h Ver arquivo

@@ -0,0 +1,30 @@
1
+/*
2
+ * state_venty.h
3
+ *
4
+ * Copyright (c) 2023 Thomas Buck (thomas@xythobuz.de)
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * See <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+#ifndef __STATE_VENTY_H__
20
+#define __STATE_VENTY_H__
21
+
22
+#include <ble.h>
23
+
24
+void state_venty_target(bd_addr_t addr, bd_addr_type_t type);
25
+
26
+void state_venty_enter(void);
27
+void state_venty_exit(void);
28
+void state_venty_run(void);
29
+
30
+#endif // __STATE_VENTY_H__

+ 43
- 0
include/venty.h Ver arquivo

@@ -0,0 +1,43 @@
1
+/*
2
+ * venty.h
3
+ *
4
+ * Copyright (c) 2023 Thomas Buck (thomas@xythobuz.de)
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * See <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+#ifndef __VENTY_H__
20
+#define __VENTY_H__
21
+
22
+#include <stdint.h>
23
+#include <stdbool.h>
24
+
25
+// in 1/10th degrees C, or < 0 on error
26
+int16_t venty_get_target_temp(void);
27
+
28
+// v in 1/10th degrees C, returns < 0 on error
29
+int8_t venty_set_target_temp(uint16_t value);
30
+
31
+// returns < 0 on error
32
+int8_t venty_set_heater_state(bool value);
33
+int8_t venty_set_eco_current(bool value);
34
+int8_t venty_set_eco_voltage(bool value);
35
+
36
+// in percent, or < 0 on error
37
+int8_t venty_get_battery_state(void);
38
+
39
+// bool, or < 0 on error
40
+int8_t venty_get_eco_current(void);
41
+int8_t venty_get_eco_voltage(void);
42
+
43
+#endif // __VENTY_H__

+ 1
- 0
picowota

@@ -0,0 +1 @@
1
+Subproject commit ac8960b274f0f76013364a9b83325036cb52f030

+ 2
- 1
src/console.c Ver arquivo

@@ -165,7 +165,8 @@ static void cnsl_interpret(const char *line) {
165 165
                 char info[32] = "";
166 166
                 enum known_devices dev = models_filter_name(results[i].name);
167 167
                 if (dev != DEV_UNKNOWN) {
168
-                    models_get_serial(results[i].data, results[i].data_len,
168
+                    models_get_serial(dev, results[i].name,
169
+                                      results[i].data, results[i].data_len,
169 170
                                       info, sizeof(info));
170 171
                 }
171 172
                 uint32_t age = to_ms_since_boot(get_absolute_time()) - results[i].time;

+ 33
- 6
src/models.c Ver arquivo

@@ -31,22 +31,49 @@ enum known_devices models_filter_name(const char *name) {
31 31
         return DEV_VOLCANO;
32 32
     } else if (strcmp(name, "STORZ&BICKEL") == 0) {
33 33
         return DEV_CRAFTY;
34
+    } else if (str_startswith(name, "S&B VY")) {
35
+        return DEV_VENTY;
34 36
     } else {
35 37
         return DEV_UNKNOWN;
36 38
     }
37 39
 }
38 40
 
39
-int8_t models_get_serial(const uint8_t *data, size_t data_len, char *buff, size_t buff_len) {
40
-    if ((data == NULL) || (data_len <= 0) || (buff == NULL) || (buff_len <= 0)) {
41
+int8_t models_get_serial(enum known_devices dev, const char *name,
42
+                         const uint8_t *data, size_t data_len,
43
+                         char *buff, size_t buff_len) {
44
+    if ((name == NULL) || (data == NULL)
45
+        || (buff == NULL) || (buff_len <= 0)) {
41 46
         return -1;
42 47
     }
43 48
 
44
-    const size_t serial_len = 8;
45
-    const size_t serial_off = 2;
46
-    if ((data_len < (serial_len + serial_off)) || (buff_len < (serial_len + 1))) {
49
+    size_t serial_len, serial_off, src_len;
50
+    const uint8_t *src;
51
+
52
+    switch (dev) {
53
+    case DEV_VOLCANO:
54
+    case DEV_CRAFTY:
55
+        serial_len = 8;
56
+        serial_off = 2;
57
+        src = data;
58
+        src_len = data_len;
59
+        break;
60
+
61
+    case DEV_VENTY:
62
+        serial_len = 8;
63
+        serial_off = 4;
64
+        src = (const uint8_t *)name;
65
+        src_len = strlen(name);
66
+        break;
67
+
68
+    default:
47 69
         return -2;
48 70
     }
49
-    memcpy(buff, data + serial_off, serial_len);
71
+
72
+    if ((src_len < (serial_len + serial_off)) || (buff_len < (serial_len + 1))) {
73
+        return -3;
74
+    }
75
+
76
+    memcpy(buff, src + serial_off, serial_len);
50 77
     buff[serial_len] = '\0';
51 78
 
52 79
     return 0;

+ 6
- 0
src/state.c Ver arquivo

@@ -27,6 +27,7 @@
27 27
 #include "state_about.h"
28 28
 #include "state_value.h"
29 29
 #include "state_volcano_conf.h"
30
+#include "state_venty.h"
30 31
 #include "state.h"
31 32
 
32 33
 #define stringify(name) # name
@@ -90,6 +91,11 @@ static const struct state states[STATE_INVALID + 1] = {
90 91
         .exit = state_volcano_conf_exit,
91 92
         .run = state_volcano_conf_run,
92 93
     }, {
94
+        .name = stringify(STATE_VENTY),
95
+        .enter = state_venty_enter,
96
+        .exit = state_venty_exit,
97
+        .run = state_venty_run,
98
+    }, {
93 99
         .name = stringify(STATE_INVALID),
94 100
         .enter = NULL,
95 101
         .exit = NULL,

+ 11
- 1
src/state_scan.c Ver arquivo

@@ -31,6 +31,7 @@
31 31
 #include "state_volcano_run.h"
32 32
 #include "state_volcano_conf.h"
33 33
 #include "state_crafty.h"
34
+#include "state_venty.h"
34 35
 #include "state_scan.h"
35 36
 
36 37
 static struct ble_scan_result results[BLE_MAX_SCAN_RESULTS] = {0};
@@ -54,6 +55,9 @@ static void enter_cb(int selection) {
54 55
             } else if (dev == DEV_CRAFTY) {
55 56
                 state_crafty_target(results[i].addr, results[i].type);
56 57
                 state_switch(STATE_CRAFTY);
58
+            } else if (dev == DEV_VENTY) {
59
+                state_venty_target(results[i].addr, results[i].type);
60
+                state_switch(STATE_VENTY);
57 61
             }
58 62
             return;
59 63
         }
@@ -81,6 +85,9 @@ static void edit_cb(int selection) {
81 85
             } else if (dev == DEV_CRAFTY) {
82 86
                 state_crafty_target(results[i].addr, results[i].type);
83 87
                 state_switch(STATE_CRAFTY);
88
+            } else if (dev == DEV_VENTY) {
89
+                state_venty_target(results[i].addr, results[i].type);
90
+                state_switch(STATE_VENTY);
84 91
             }
85 92
             return;
86 93
         }
@@ -160,10 +167,13 @@ static void draw(struct menu_state *menu) {
160 167
             pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, "Volcano ");
161 168
         } else if (dev == DEV_CRAFTY) {
162 169
             pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, "Crafty+ ");
170
+        } else if (dev == DEV_VENTY) {
171
+            pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, "Venty ");
163 172
         }
164 173
 
165 174
         char info[32] = "";
166
-        if (models_get_serial(results[i].data, results[i].data_len,
175
+        if (models_get_serial(dev, results[i].name,
176
+                              results[i].data, results[i].data_len,
167 177
                               info, sizeof(info)) < 0) {
168 178
             strcpy(info, "-error-");
169 179
         }

+ 178
- 0
src/state_venty.c Ver arquivo

@@ -0,0 +1,178 @@
1
+/*
2
+ * state_venty.c
3
+ *
4
+ * Copyright (c) 2023 Thomas Buck (thomas@xythobuz.de)
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * See <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+#include <stdio.h>
20
+#include <string.h>
21
+
22
+#include "config.h"
23
+#include "menu.h"
24
+#include "venty.h"
25
+#include "log.h"
26
+#include "state.h"
27
+#include "state_value.h"
28
+#include "state_venty.h"
29
+
30
+static bd_addr_t ble_addr = {0};
31
+static bd_addr_type_t ble_type = 0;
32
+static bool wait_for_connect = false;
33
+static bool wait_for_disconnect = false;
34
+static bool connected = false;
35
+
36
+static bool heater_state = false;
37
+static int16_t target_temp = 0;
38
+static int8_t battery = 0;
39
+static int8_t eco_current = 0;
40
+static int8_t eco_voltage = 0;
41
+
42
+void state_venty_target(bd_addr_t addr, bd_addr_type_t type) {
43
+    memcpy(ble_addr, addr, sizeof(bd_addr_t));
44
+    ble_type = type;
45
+
46
+    connected = false;
47
+}
48
+
49
+static void enter_cb(int selection) {
50
+    switch (selection) {
51
+    case 0:
52
+        // Target
53
+        state_value_set(&target_temp,
54
+                        sizeof(target_temp),
55
+                        400, 2100, VAL_STEP_INCREMENT, 10,
56
+                        "Target");
57
+        state_value_return(STATE_VENTY);
58
+        state_switch(STATE_VALUE);
59
+        break;
60
+
61
+    case 1:
62
+        // Heater
63
+        state_value_set(&heater_state,
64
+                        sizeof(heater_state),
65
+                        0, 1, VAL_STEP_INCREMENT, 1,
66
+                        "Heater");
67
+        state_value_return(STATE_VENTY);
68
+        state_switch(STATE_VALUE);
69
+        break;
70
+
71
+    case 2:
72
+        // Eco Current
73
+        state_value_set(&eco_current,
74
+                        sizeof(eco_current),
75
+                        0, 1, VAL_STEP_INCREMENT, 1,
76
+                        "Eco Amps");
77
+        state_value_return(STATE_VENTY);
78
+        state_switch(STATE_VALUE);
79
+        break;
80
+
81
+    case 3:
82
+        // Eco Voltage
83
+        state_value_set(&eco_voltage,
84
+                        sizeof(eco_voltage),
85
+                        0, 1, VAL_STEP_INCREMENT, 1,
86
+                        "Eco Volt");
87
+        state_value_return(STATE_VENTY);
88
+        state_switch(STATE_VALUE);
89
+        break;
90
+    }
91
+}
92
+
93
+static void send_values(void) {
94
+    venty_set_heater_state(heater_state);
95
+    sleep_ms(250);
96
+    venty_set_target_temp(target_temp);
97
+    sleep_ms(250);
98
+    venty_set_eco_current(eco_current);
99
+    sleep_ms(250);
100
+    venty_set_eco_voltage(eco_voltage);
101
+}
102
+
103
+
104
+static void fetch_values(void) {
105
+    venty_set_heater_state(false);
106
+    heater_state = false;
107
+
108
+    target_temp = venty_get_target_temp();
109
+    battery = venty_get_battery_state();
110
+    eco_current = venty_get_eco_current();
111
+    eco_voltage = venty_get_eco_voltage();
112
+}
113
+
114
+static void exit_cb(void) {
115
+    debug("venty disconnect");
116
+    ble_disconnect();
117
+    wait_for_disconnect = true;
118
+}
119
+
120
+void state_venty_enter(void) {
121
+    menu_init(enter_cb, NULL, NULL, exit_cb);
122
+
123
+    if (!connected) {
124
+        debug("venty connect");
125
+        ble_connect(ble_addr, ble_type);
126
+        wait_for_connect = true;
127
+    } else {
128
+        debug("venty write");
129
+        send_values();
130
+    }
131
+}
132
+
133
+void state_venty_exit(void) {
134
+    menu_deinit();
135
+}
136
+
137
+static void draw(struct menu_state *menu) {
138
+    if (wait_for_connect) {
139
+        snprintf(menu->buff, MENU_MAX_LEN,
140
+                 "\nConnecting");
141
+        return;
142
+    } else if (wait_for_disconnect) {
143
+        snprintf(menu->buff, MENU_MAX_LEN,
144
+                 "\nDisconnecting");
145
+        return;
146
+    }
147
+
148
+    int pos = 0;
149
+    menu->length = 0;
150
+
151
+    ADD_STATIC_ELEMENT("Target (%d C)", target_temp / 10);
152
+    ADD_STATIC_ELEMENT("Heater (%d)", heater_state);
153
+    ADD_STATIC_ELEMENT("Eco Amps (%d)", eco_current);
154
+    ADD_STATIC_ELEMENT("Eco Volt (%d)", eco_voltage);
155
+    ADD_STATIC_ELEMENT("Battery: %d %%", battery);
156
+
157
+    if (menu->selection < 0) {
158
+        menu->selection = 0;
159
+    }
160
+}
161
+
162
+void state_venty_run(void) {
163
+    if (wait_for_connect && ble_is_connected()) {
164
+        wait_for_connect = false;
165
+        connected = true;
166
+        debug("venty start");
167
+        fetch_values();
168
+    }
169
+
170
+    menu_run(draw, true);
171
+
172
+    if (wait_for_disconnect && !ble_is_connected()) {
173
+        wait_for_disconnect = false;
174
+        connected = false;
175
+        debug("venty done");
176
+        state_switch(STATE_SCAN);
177
+    }
178
+}

+ 209
- 0
src/venty.c Ver arquivo

@@ -0,0 +1,209 @@
1
+/*
2
+ * venty.c
3
+ *
4
+ * Copyright (c) 2023 Thomas Buck (thomas@xythobuz.de)
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * See <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+#include "config.h"
20
+#include "log.h"
21
+#include "ble.h"
22
+#include "main.h"
23
+#include "venty.h"
24
+
25
+#define VENTY_READ_TIMEOUT_MS 500
26
+
27
+enum venty_values {
28
+    MASK_SET_TEMPERATURE = 1 << 1,
29
+    MASK_SET_BOOST       = 1 << 2,
30
+    MASK_SET_SUPERBOOST  = 1 << 3,
31
+    MASK_HEATER          = 1 << 5,
32
+    MASK_SETTINGS        = 1 << 7,
33
+};
34
+
35
+enum venty_settings {
36
+    SETTING_UNIT                = 1 << 0,
37
+    SETTING_SETPOINT_REACHED    = 1 << 1,
38
+    SETTING_FACTORY_RESET       = 1 << 2,
39
+    SETTING_ECOMODE_CHARGE      = 1 << 3,
40
+    SETTING_BUTTON_CHANGED      = 1 << 4,
41
+    SETTING_ECOMODE_VOLTAGE     = 1 << 5,
42
+    SETTING_BOOST_VISUALIZATION = 1 << 6,
43
+};
44
+
45
+// "00000000-5354-4f52-5a26-4249434b454c"
46
+static uint8_t uuid_service[16] = {
47
+    0x00, 0x00, 0x00, 0x00, 0x53, 0x54, 0x4f, 0x52,
48
+    0x5a, 0x26, 0x42, 0x49, 0x43, 0x4b, 0x45, 0x4c,
49
+};
50
+
51
+// "00000001-5354-4f52-5a26-4249434b454c"
52
+static uint8_t uuid_characteristic[16] = {
53
+    0x00, 0x00, 0x00, 0x01, 0x53, 0x54, 0x4f, 0x52,
54
+    0x5a, 0x26, 0x42, 0x49, 0x43, 0x4b, 0x45, 0x4c,
55
+};
56
+
57
+static int8_t venty_cmd(uint8_t *rx, size_t rx_len,
58
+                        const uint8_t *tx, size_t tx_len) {
59
+    int8_t r = ble_notification_enable(uuid_service, uuid_characteristic);
60
+    if (r < 0) {
61
+        debug("ble_notification_enable failed: %d", r);
62
+        ble_notification_disable(uuid_service, uuid_characteristic);
63
+        return r;
64
+    }
65
+
66
+    r = ble_write(uuid_service, uuid_characteristic,
67
+                         tx, tx_len);
68
+    if (r < 0) {
69
+        debug("ble_write failed: %d", r);
70
+        ble_notification_disable(uuid_service, uuid_characteristic);
71
+        return r;
72
+    }
73
+
74
+    uint32_t start_time = to_ms_since_boot(get_absolute_time());
75
+    while (!ble_notification_ready()) {
76
+        sleep_ms(1);
77
+        main_loop_hw();
78
+
79
+        uint32_t now = to_ms_since_boot(get_absolute_time());
80
+        if ((now - start_time) >= VENTY_READ_TIMEOUT_MS) {
81
+            debug("timeout waiting for notification");
82
+            ble_notification_disable(uuid_service, uuid_characteristic);
83
+            return -1;
84
+        }
85
+    }
86
+
87
+    uint8_t uuid[16] = {0};
88
+    uint16_t len = ble_notification_get(rx, rx_len, uuid);
89
+
90
+    if (memcmp(uuid, uuid_characteristic, 16) != 0) {
91
+        debug("got notification for unexpected uuid");
92
+        len = 0;
93
+    }
94
+
95
+    ble_notification_disable(uuid_service, uuid_characteristic);
96
+    return (len <= 0) ? -1 : 0;
97
+}
98
+
99
+int16_t venty_get_target_temp(void) {
100
+    uint8_t cmd[20] = {0};
101
+    uint8_t buff[20] = {0};
102
+
103
+    cmd[0] = 1;
104
+
105
+    int8_t r = venty_cmd(buff, sizeof(buff), cmd, sizeof(cmd));
106
+    if (r < 0) {
107
+        return r;
108
+    }
109
+
110
+    int16_t *val = (int16_t *)(buff + 4);
111
+    return *val;
112
+}
113
+
114
+int8_t venty_set_target_temp(uint16_t value) {
115
+    uint8_t cmd[20] = {0};
116
+    uint8_t buff[20] = {0};
117
+
118
+    cmd[0] = 1;
119
+    cmd[1] = MASK_SET_TEMPERATURE;
120
+    uint16_t *val = (uint16_t *)(cmd + 4);
121
+    *val = value;
122
+
123
+    int8_t r = venty_cmd(buff, sizeof(buff), cmd, sizeof(cmd));
124
+    return r;
125
+}
126
+
127
+int8_t venty_set_heater_state(bool value) {
128
+    uint8_t cmd[20] = {0};
129
+    uint8_t buff[20] = {0};
130
+
131
+    cmd[0] = 1;
132
+    cmd[1] = MASK_HEATER;
133
+    cmd[11] = value ? 1 : 0;
134
+
135
+    int8_t r = venty_cmd(buff, sizeof(buff), cmd, sizeof(cmd));
136
+    return r;
137
+}
138
+
139
+int8_t venty_get_battery_state(void) {
140
+    uint8_t cmd[20] = {0};
141
+    uint8_t buff[20] = {0};
142
+
143
+    cmd[0] = 1;
144
+
145
+    int8_t r = venty_cmd(buff, sizeof(buff), cmd, sizeof(cmd));
146
+    if (r < 0) {
147
+        return r;
148
+    }
149
+
150
+    int8_t *val = (int8_t *)(buff + 8);
151
+    return *val;
152
+}
153
+
154
+int8_t venty_get_eco_current(void) {
155
+    uint8_t cmd[20] = {0};
156
+    uint8_t buff[20] = {0};
157
+
158
+    cmd[0] = 1;
159
+
160
+    int8_t r = venty_cmd(buff, sizeof(buff), cmd, sizeof(cmd));
161
+    if (r < 0) {
162
+        return r;
163
+    }
164
+
165
+    int8_t *val = (int8_t *)(buff + 14);
166
+    return (*val & SETTING_ECOMODE_CHARGE) ? 1 : 0;
167
+
168
+}
169
+
170
+int8_t venty_get_eco_voltage(void) {
171
+    uint8_t cmd[20] = {0};
172
+    uint8_t buff[20] = {0};
173
+
174
+    cmd[0] = 1;
175
+
176
+    int8_t r = venty_cmd(buff, sizeof(buff), cmd, sizeof(cmd));
177
+    if (r < 0) {
178
+        return r;
179
+    }
180
+
181
+    int8_t *val = (int8_t *)(buff + 14);
182
+    return (*val & SETTING_ECOMODE_VOLTAGE) ? 1 : 0;
183
+}
184
+
185
+int8_t venty_set_eco_current(bool value) {
186
+    uint8_t cmd[20] = {0};
187
+    uint8_t buff[20] = {0};
188
+
189
+    cmd[0] = 1;
190
+    cmd[1] = MASK_SETTINGS;
191
+    cmd[14] = value ? SETTING_ECOMODE_CHARGE : 0;
192
+    cmd[15] = SETTING_ECOMODE_CHARGE;
193
+
194
+    int8_t r = venty_cmd(buff, sizeof(buff), cmd, sizeof(cmd));
195
+    return r;
196
+}
197
+
198
+int8_t venty_set_eco_voltage(bool value) {
199
+    uint8_t cmd[20] = {0};
200
+    uint8_t buff[20] = {0};
201
+
202
+    cmd[0] = 1;
203
+    cmd[1] = MASK_SETTINGS;
204
+    cmd[14] = value ? SETTING_ECOMODE_VOLTAGE : 0;
205
+    cmd[15] = SETTING_ECOMODE_VOLTAGE;
206
+
207
+    int8_t r = venty_cmd(buff, sizeof(buff), cmd, sizeof(cmd));
208
+    return r;
209
+}

Carregando…
Cancelar
Salvar