Browse Source

can also edit workflow steps

Thomas Buck 11 months ago
parent
commit
e1bfb1b191
7 changed files with 69 additions and 27 deletions
  1. 2
    1
      include/state_value.h
  2. 3
    3
      include/workflow.h
  3. 32
    2
      src/state_edit_workflow.c
  4. 4
    2
      src/state_settings.c
  5. 15
    6
      src/state_value.c
  6. 3
    3
      src/state_volcano_run.c
  7. 10
    10
      src/workflow.c

+ 2
- 1
include/state_value.h View File

29
 
29
 
30
 void state_value_set(void *value, size_t length,
30
 void state_value_set(void *value, size_t length,
31
                      ssize_t min, ssize_t max,
31
                      ssize_t min, ssize_t max,
32
-                     enum value_step_mode mode, ssize_t step);
32
+                     enum value_step_mode mode, ssize_t step,
33
+                     const char *name);
33
 void state_value_return(enum system_state state);
34
 void state_value_return(enum system_state state);
34
 
35
 
35
 void state_value_enter(void);
36
 void state_value_enter(void);

+ 3
- 3
include/workflow.h View File

54
 
54
 
55
     uint16_t index;
55
     uint16_t index;
56
     uint16_t count;
56
     uint16_t count;
57
-    struct wf_step step;
57
+    struct wf_step *step;
58
     uint16_t start_val, curr_val;
58
     uint16_t start_val, curr_val;
59
 };
59
 };
60
 
60
 
71
 void wf_move_step_down(uint16_t index, uint16_t step);
71
 void wf_move_step_down(uint16_t index, uint16_t step);
72
 void wf_move_step_up(uint16_t index, uint16_t step);
72
 void wf_move_step_up(uint16_t index, uint16_t step);
73
 
73
 
74
-struct wf_step wf_get_step(uint16_t index, uint16_t step);
75
-const char *wf_step_str(struct wf_step step);
74
+struct wf_step *wf_get_step(uint16_t index, uint16_t step);
75
+const char *wf_step_str(struct wf_step *step);
76
 
76
 
77
 struct wf_state wf_status(void);
77
 struct wf_state wf_status(void);
78
 void wf_start(uint16_t index);
78
 void wf_start(uint16_t index);

+ 32
- 2
src/state_edit_workflow.c View File

20
 #include <string.h>
20
 #include <string.h>
21
 
21
 
22
 #include "config.h"
22
 #include "config.h"
23
+#include "mem.h"
23
 #include "menu.h"
24
 #include "menu.h"
24
 #include "workflow.h"
25
 #include "workflow.h"
25
 #include "state.h"
26
 #include "state.h"
27
+#include "state_value.h"
26
 #include "state_edit_workflow.h"
28
 #include "state_edit_workflow.h"
27
 
29
 
28
 static uint16_t wf_index = 0;
30
 static uint16_t wf_index = 0;
29
 
31
 
30
 static void enter_cb(int selection) {
32
 static void enter_cb(int selection) {
33
+    static char buff[20];
34
+
31
     if ((selection >= 0) && (selection < wf_steps(wf_index))) {
35
     if ((selection >= 0) && (selection < wf_steps(wf_index))) {
32
-        // TODO edit value
36
+        struct wf_step *step = wf_get_step(wf_index, selection);
37
+        switch (step->op) {
38
+        case OP_SET_TEMPERATURE:
39
+        case OP_WAIT_TEMPERATURE:
40
+            snprintf(buff, sizeof(buff),
41
+                     "%s Temp.",
42
+                     step->op == OP_WAIT_TEMPERATURE ? "Wait" : "Set");
43
+            state_value_set(&step->val,
44
+                            sizeof(step->val),
45
+                            400, 2300, VAL_STEP_INCREMENT, 10,
46
+                            buff);
47
+            break;
48
+
49
+        case OP_WAIT_TIME:
50
+        case OP_PUMP_TIME:
51
+            snprintf(buff, sizeof(buff),
52
+                     "%s Time",
53
+                     step->op == OP_WAIT_TIME ? "Wait" : "Pump");
54
+            state_value_set(&step->val,
55
+                            sizeof(step->val),
56
+                            0, 60000, VAL_STEP_INCREMENT, 1000,
57
+                            buff);
58
+            break;
59
+        }
60
+
61
+        state_value_return(STATE_EDIT_WORKFLOW);
62
+        state_switch(STATE_VALUE);
33
     }
63
     }
34
 }
64
 }
35
 
65
 
77
             pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, "  ");
107
             pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, "  ");
78
         }
108
         }
79
 
109
 
80
-        struct wf_step step = wf_get_step(wf_index, i);
110
+        struct wf_step *step = wf_get_step(wf_index, i);
81
         pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos,
111
         pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos,
82
                         "% 2d: %s\n", i, wf_step_str(step));
112
                         "% 2d: %s\n", i, wf_step_str(step));
83
     }
113
     }

+ 4
- 2
src/state_settings.c View File

34
         // Auto Connect
34
         // Auto Connect
35
         state_value_set(&mem_data()->wf_auto_connect,
35
         state_value_set(&mem_data()->wf_auto_connect,
36
                         sizeof(mem_data()->wf_auto_connect),
36
                         sizeof(mem_data()->wf_auto_connect),
37
-                        0, 1, VAL_STEP_INCREMENT, 1);
37
+                        0, 1, VAL_STEP_INCREMENT, 1,
38
+                        "Auto Connect");
38
         state_value_return(STATE_SETTINGS);
39
         state_value_return(STATE_SETTINGS);
39
         state_switch(STATE_VALUE);
40
         state_switch(STATE_VALUE);
40
         break;
41
         break;
43
         // Brightness
44
         // Brightness
44
         state_value_set(&mem_data()->backlight,
45
         state_value_set(&mem_data()->backlight,
45
                         sizeof(mem_data()->backlight),
46
                         sizeof(mem_data()->backlight),
46
-                        0x00FF, 0xFF00, VAL_STEP_SHIFT, 1);
47
+                        0x00FF, 0xFF00, VAL_STEP_SHIFT, 1,
48
+                        "Brightness");
47
         state_value_return(STATE_SETTINGS);
49
         state_value_return(STATE_SETTINGS);
48
         state_switch(STATE_VALUE);
50
         state_switch(STATE_VALUE);
49
         break;
51
         break;

+ 15
- 6
src/state_value.c View File

30
 static ssize_t val_min = 0;
30
 static ssize_t val_min = 0;
31
 static ssize_t val_max = 0;
31
 static ssize_t val_max = 0;
32
 static ssize_t val_step = 0;
32
 static ssize_t val_step = 0;
33
+static const char *val_name = NULL;
33
 
34
 
34
 static enum value_step_mode val_mode = VAL_STEP_INCREMENT;
35
 static enum value_step_mode val_mode = VAL_STEP_INCREMENT;
35
 static enum system_state val_ret_state = STATE_SCAN;
36
 static enum system_state val_ret_state = STATE_SCAN;
38
 
39
 
39
 void state_value_set(void *value, size_t length,
40
 void state_value_set(void *value, size_t length,
40
                      ssize_t min, ssize_t max,
41
                      ssize_t min, ssize_t max,
41
-                     enum value_step_mode mode, ssize_t step) {
42
+                     enum value_step_mode mode, ssize_t step,
43
+                     const char *name) {
42
     val_p = value;
44
     val_p = value;
43
     val_len = length;
45
     val_len = length;
44
     val_min = min;
46
     val_min = min;
45
     val_max = max;
47
     val_max = max;
46
     val_mode = mode;
48
     val_mode = mode;
47
     val_step = step;
49
     val_step = step;
50
+    val_name = name;
48
 }
51
 }
49
 
52
 
50
 void state_value_return(enum system_state state) {
53
 void state_value_return(enum system_state state) {
55
     static char buff[100];
58
     static char buff[100];
56
     static size_t pos = 0;
59
     static size_t pos = 0;
57
 
60
 
58
-    if ((val_p == NULL) || (val_len <= 0)) {
61
+    if ((val_p == NULL) || (val_len <= 0) || (val_name == NULL)) {
59
         pos += snprintf(buff, sizeof(buff),
62
         pos += snprintf(buff, sizeof(buff),
60
                         "error");
63
                         "error");
61
     } else {
64
     } else {
62
-        pos += snprintf(buff, sizeof(buff),
63
-                        "%d", val);
65
+        if (val_mode == VAL_STEP_INCREMENT) {
66
+            pos += snprintf(buff, sizeof(buff),
67
+                            "%s:\n%d -> %d -> %d",
68
+                            val_name, val_min / val_step, val / val_step, val_max / val_step);
69
+        } else {
70
+            pos += snprintf(buff, sizeof(buff),
71
+                            "%s:\n%04X -> %04X -> %04X",
72
+                            val_name, val_min, val, val_max);
73
+        }
64
     }
74
     }
65
 
75
 
66
-    text_box(buff, false,
76
+    text_box(buff, true,
67
              "fixed_10x20",
77
              "fixed_10x20",
68
              0, LCD_WIDTH,
78
              0, LCD_WIDTH,
69
              50, TEXT_BOX_HEIGHT(20, 2),
79
              50, TEXT_BOX_HEIGHT(20, 2),
103
 
113
 
104
     if (((v > 0) && (val >= val_max))
114
     if (((v > 0) && (val >= val_max))
105
         || ((v < 0) && (val <= val_min))) {
115
         || ((v < 0) && (val <= val_min))) {
106
-        debug("val=%d v=%d", val, v);
107
         return;
116
         return;
108
     }
117
     }
109
 
118
 

+ 3
- 3
src/state_volcano_run.c View File

91
     pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos,
91
     pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos,
92
                     "step %d / %d\n", state.index, state.count);
92
                     "step %d / %d\n", state.index, state.count);
93
 
93
 
94
-    switch (state.step.op) {
94
+    switch (state.step->op) {
95
     case OP_SET_TEMPERATURE:
95
     case OP_SET_TEMPERATURE:
96
         pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos,
96
         pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos,
97
                         "\n%s", wf_step_str(state.step));
97
                         "\n%s", wf_step_str(state.step));
104
                         "%.1f -> %.1f -> %.1f",
104
                         "%.1f -> %.1f -> %.1f",
105
                         state.start_val / 10.0f,
105
                         state.start_val / 10.0f,
106
                         state.curr_val / 10.0f,
106
                         state.curr_val / 10.0f,
107
-                        state.step.val / 10.0f);
107
+                        state.step->val / 10.0f);
108
         break;
108
         break;
109
 
109
 
110
     case OP_WAIT_TIME:
110
     case OP_WAIT_TIME:
115
                         "%.0f -> %.0f -> %.0f",
115
                         "%.0f -> %.0f -> %.0f",
116
                         state.start_val / 1000.0f,
116
                         state.start_val / 1000.0f,
117
                         state.curr_val / 1000.0f,
117
                         state.curr_val / 1000.0f,
118
-                        state.step.val / 1000.0f);
118
+                        state.step->val / 1000.0f);
119
         break;
119
         break;
120
     }
120
     }
121
 
121
 

+ 10
- 10
src/workflow.c View File

134
     mem_data()->wf[index].steps[step] = tmp;
134
     mem_data()->wf[index].steps[step] = tmp;
135
 }
135
 }
136
 
136
 
137
-struct wf_step wf_get_step(uint16_t index, uint16_t step) {
137
+struct wf_step *wf_get_step(uint16_t index, uint16_t step) {
138
     if (index >= mem_data()->wf_count) {
138
     if (index >= mem_data()->wf_count) {
139
         debug("invalid index %d", index);
139
         debug("invalid index %d", index);
140
-        return mem_data()->wf[0].steps[0];
140
+        return NULL;
141
     }
141
     }
142
-    return mem_data()->wf[index].steps[step];
142
+    return &mem_data()->wf[index].steps[step];
143
 }
143
 }
144
 
144
 
145
-const char *wf_step_str(struct wf_step step) {
145
+const char *wf_step_str(struct wf_step *step) {
146
     static char buff[20];
146
     static char buff[20];
147
 
147
 
148
-    switch (step.op) {
148
+    switch (step->op) {
149
     case OP_SET_TEMPERATURE:
149
     case OP_SET_TEMPERATURE:
150
         snprintf(buff, sizeof(buff),
150
         snprintf(buff, sizeof(buff),
151
-                 "set temp %.1f C", step.val / 10.0f);
151
+                 "set temp %.1f C", step->val / 10.0f);
152
         break;
152
         break;
153
 
153
 
154
     case OP_WAIT_TEMPERATURE:
154
     case OP_WAIT_TEMPERATURE:
155
         snprintf(buff, sizeof(buff),
155
         snprintf(buff, sizeof(buff),
156
-                 "wait temp %.1f C", step.val / 10.0f);
156
+                 "wait temp %.1f C", step->val / 10.0f);
157
         break;
157
         break;
158
 
158
 
159
     case OP_WAIT_TIME:
159
     case OP_WAIT_TIME:
160
     case OP_PUMP_TIME:
160
     case OP_PUMP_TIME:
161
         snprintf(buff, sizeof(buff),
161
         snprintf(buff, sizeof(buff),
162
                  "%s time %.1f s",
162
                  "%s time %.1f s",
163
-                 (step.op == OP_WAIT_TIME) ? "wait" : "pump",
164
-                 step.val / 1000.0f);
163
+                 (step->op == OP_WAIT_TIME) ? "wait" : "pump",
164
+                 step->val / 1000.0f);
165
         break;
165
         break;
166
     }
166
     }
167
 
167
 
189
         .status = status,
189
         .status = status,
190
         .index = step,
190
         .index = step,
191
         .count = mem_data()->wf[wf_i].count,
191
         .count = mem_data()->wf[wf_i].count,
192
-        .step = mem_data()->wf[wf_i].steps[step],
192
+        .step = &mem_data()->wf[wf_i].steps[step],
193
         .start_val = start_val,
193
         .start_val = start_val,
194
         .curr_val = curr_val,
194
         .curr_val = curr_val,
195
     };
195
     };

Loading…
Cancel
Save