-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmenus.cpp
339 lines (280 loc) · 14.1 KB
/
menus.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
#include <Arduino.h>
#include "menus.h"
#include "hardware.h"
#include "serial.h"
// motor on/off
const char pgmstr_motor_on[] PROGMEM = "Driver: on";
const char pgmstr_motor_off[] PROGMEM = "Driver: off";
bool is_motor_on(){ return motors[last_entered_motor_menu].is_on(); }
void do_motor_on(){ motors[last_entered_motor_menu].on(); }
void do_motor_off(){ motors[last_entered_motor_menu].off(); }
MenuItemToggleCallable motor_on_off(&is_motor_on, pgmstr_motor_on, pgmstr_motor_off, &do_motor_off, &do_motor_on);
// motor start/stop
const char pgmstr_motor_start[] PROGMEM = "Run continuously";
const char pgmstr_motor_stop[] PROGMEM = "Stop !!";
bool is_motor_running(){ return motors[last_entered_motor_menu].running; }
void do_motor_start(){
motors[last_entered_motor_menu].rpm(motors[last_entered_motor_menu].rpm());
motors[last_entered_motor_menu].start(true);
}
void do_motor_stop(){ motors[last_entered_motor_menu].stop(); }
MenuItemToggleCallable motor_start_stop(&is_motor_running, pgmstr_motor_stop, pgmstr_motor_start, &do_motor_stop, &do_motor_start);
// motor manual steps
const char pgmstr_manual_steps[] PROGMEM = "Manual steps";
MenuMotorManualSteps menu_motor_manual_steps;
MenuItem motor_manual_steps(pgmstr_manual_steps, &menu_motor_manual_steps);
// motor speed
MenuRangeMotorRPM menu_motor_speed;
MenuItem motor_speed(pgmstr_speed_rpm, &menu_motor_speed);
// motor accel
MenuRangeMotorAccel menu_motor_accel;
MenuItem motor_accel(pgmstr_accel_rpms, &menu_motor_accel);
// motor decel
MenuRangeMotorDecel menu_motor_decel;
MenuItem motor_decel(pgmstr_decel_rpms, &menu_motor_decel);
// motor direction
const char pgmstr_direction_true[] PROGMEM = "Direction: " MOTOR_DIR_1;
const char pgmstr_direction_false[] PROGMEM = "Direction: " MOTOR_DIR_0;
bool get_motor_direction(){ return motors[last_entered_motor_menu].dir(); }
void set_motor_direction_left(){ motors[last_entered_motor_menu].dir(true); }
void set_motor_direction_right(){ motors[last_entered_motor_menu].dir(false); }
MenuItemToggleCallable motor_direction(&get_motor_direction, pgmstr_direction_true, pgmstr_direction_false,
&set_motor_direction_right, &set_motor_direction_left);
// motor double edge
const char pgmstr_double_edge_on[] PROGMEM = "Double edge: on";
const char pgmstr_double_edge_off[] PROGMEM = "Double edge: off";
bool is_motor_dedge_on(){ return motors[last_entered_motor_menu].driver.dedge(); }
void do_motor_dedge_on(){ motors[last_entered_motor_menu].driver.dedge(true); }
void do_motor_dedge_off(){ motors[last_entered_motor_menu].driver.dedge(false); }
MenuItemToggleCallable motor_dedge_on_off(&is_motor_dedge_on, pgmstr_double_edge_on, pgmstr_double_edge_off,
&do_motor_dedge_off, &do_motor_dedge_on);
// motor vsense
const char pgmstr_vsense_on[] PROGMEM = "Vsense: on";
const char pgmstr_vsense_off[] PROGMEM = "Vsense: off";
bool is_motor_vsense_on(){ return motors[last_entered_motor_menu].driver.vsense(); }
void do_motor_vsense_on(){ motors[last_entered_motor_menu].driver.vsense(true); }
void do_motor_vsense_off(){ motors[last_entered_motor_menu].driver.vsense(false); }
MenuItemToggleCallable motor_vsense_on_off(&is_motor_vsense_on, pgmstr_vsense_on, pgmstr_vsense_off,
&do_motor_vsense_off, &do_motor_vsense_on);
// motor enable pwm mode
const char pgmstr_pwm_mode_on[] PROGMEM = "PWM Mode: on";
const char pgmstr_pwm_mode_off[] PROGMEM = "PWM Mode: off";
bool is_motor_en_pwm_mode_on(){ return motors[last_entered_motor_menu].driver.en_pwm_mode(); }
void do_motor_en_pwm_mode_on(){ motors[last_entered_motor_menu].driver.en_pwm_mode(true); }
void do_motor_en_pwm_mode_off(){ motors[last_entered_motor_menu].driver.en_pwm_mode(false); }
MenuItemToggleCallable motor_en_pwm_mode_on_off(&is_motor_en_pwm_mode_on, pgmstr_pwm_mode_on, pgmstr_pwm_mode_off,
&do_motor_en_pwm_mode_off, &do_motor_en_pwm_mode_on);
// motor pwm autoscale
const char pgmstr_pwm_autoscale_on[] PROGMEM = "PWM Autoscale: on";
const char pgmstr_pwm_autoscale_off[] PROGMEM = "PWM Autoscale: off";
bool is_motor_pwm_autoscale_on(){ return motors[last_entered_motor_menu].driver.pwm_autoscale(); }
void do_motor_pwm_autoscale_on(){ motors[last_entered_motor_menu].driver.pwm_autoscale(true); }
void do_motor_pwm_autoscale_off(){ motors[last_entered_motor_menu].driver.pwm_autoscale(false); }
MenuItemToggleCallable motor_pwm_autoscale_on_off(&is_motor_pwm_autoscale_on, pgmstr_pwm_autoscale_on, pgmstr_pwm_autoscale_off,
&do_motor_pwm_autoscale_off, &do_motor_pwm_autoscale_on);
// motor interpolate
const char pgmstr_interpolate_on[] PROGMEM = "Interpolation: on";
const char pgmstr_interpolate_off[] PROGMEM = "Interpolation: off";
bool is_motor_intpol_on(){ return motors[last_entered_motor_menu].driver.intpol(); }
void do_motor_intpol_on(){ motors[last_entered_motor_menu].driver.intpol(true); }
void do_motor_intpol_off(){ motors[last_entered_motor_menu].driver.intpol(false); }
MenuItemToggleCallable motor_intpol_on_off(&is_motor_intpol_on, pgmstr_interpolate_on, pgmstr_interpolate_off,
&do_motor_intpol_off, &do_motor_intpol_on);
// motor invert direction
const char pgmstr_invert_direction_on[] PROGMEM = "Invert dir.: on";
const char pgmstr_invert_direction_off[] PROGMEM = "Invert dir.: off";
bool is_motor_invert_direction_on(){ return motors[last_entered_motor_menu].invert_direction; }
void do_motor_invert_direction_on(){ motors[last_entered_motor_menu].invert_direction = true; }
void do_motor_invert_direction_off(){ motors[last_entered_motor_menu].invert_direction = false; }
MenuItemToggleCallable motor_invert_direction_on_off(&is_motor_invert_direction_on, pgmstr_invert_direction_on,
pgmstr_invert_direction_off, &do_motor_invert_direction_off, &do_motor_invert_direction_on);
// motor current
MenuListMotorCurrent menu_motor_current;
MenuItem motor_current(pgmstr_current, &menu_motor_current);
// motor hold current multiplier
MenuRangeMotorHoldMultiplier menu_motor_hold_current_multiplier;
MenuItem motor_hold_current_multiplier(pgmstr_hold_multiplier, &menu_motor_hold_current_multiplier);
// motor microstepping
MenuListMotorMicrostepping menu_motor_msteps;
MenuItem motor_msteps(pgmstr_microstepping, &menu_motor_msteps);
// motor blank time
MenuListMotorBlankTime menu_motor_blank_time;
MenuItem motor_blank_time(pgmstr_blank_time, &menu_motor_blank_time);
// motor off time
MenuRangeMotorOffTime menu_motor_off_time;
MenuItem motor_off_time(pgmstr_off_time, &menu_motor_off_time);
// motor semin
MenuRangeMotorSEMIN menu_motor_semin;
MenuItem motor_semin(pgmstr_smartenergy_min, &menu_motor_semin);
// motor semax
MenuRangeMotorSEMAX menu_motor_semax;
MenuItem motor_semax(pgmstr_smartenergy_max, &menu_motor_semax);
// motor maximum power
void do_motor_maximum_power(){
motors[last_entered_motor_menu].driver.semin(0);
motors[last_entered_motor_menu].driver.vsense(false);
motors[last_entered_motor_menu].driver.hold_multiplier(1);
motors[last_entered_motor_menu].driver.irun(31);
motors[last_entered_motor_menu].driver.ihold(31);
motors[last_entered_motor_menu].driver.TCOOLTHRS(0);
}
const char pgmstr_maximum_power[] PROGMEM = "Maximum power";
MenuItemCallable motor_maximum_power(pgmstr_maximum_power, do_motor_maximum_power, false);
// motor show stallguard
const char pgmstr_stallguard[] PROGMEM = "stallGuard";
const char pgmstr_show_stallguard[] PROGMEM = "Show stallGuard";
static TMC2130_n::DRV_STATUS_t mot_drv_status{0};
uint16_t get_motor_stallguard_value(){
mot_drv_status.sr = motors[last_entered_motor_menu].driver.DRV_STATUS();
return mot_drv_status.sg_result;
}
uint16_t get_motor_actual_current(){
return motors[last_entered_motor_menu].driver.cs2rms(mot_drv_status.cs_actual);
}
MenuItemDynamicCallable<uint16_t> motor_stallguard_value_item(pgmstr_stallguard, &get_motor_stallguard_value);
MenuItemDynamicCallable<uint16_t> motor_actual_current_item(pgmstr_current, &get_motor_actual_current);
MenuItem* const motor_stallguard_value_items[] PROGMEM = {
&back,
&motor_stallguard_value_item,
&motor_actual_current_item,
};
Menu menu_motor_stallguard_value(motor_stallguard_value_items, sizeof(motor_stallguard_value_items) / 2);
MenuItem motor_stallguard_value(pgmstr_show_stallguard, &menu_motor_stallguard_value);
// motor stallguard sensitivity
MenuRangeMotorSgThreshold menu_motor_sg_threshold;
MenuItem motor_sg_threshold(pgmstr_sg_thres, &menu_motor_sg_threshold);
// motor stop on stallguard
bool is_motor_stop_on_stallguard_on(){ return motors[last_entered_motor_menu].stop_on_stallguard; }
void do_motor_stop_on_stallguard_on(){ motors[last_entered_motor_menu].stop_on_stallguard = true; }
void do_motor_stop_on_stallguard_off(){ motors[last_entered_motor_menu].stop_on_stallguard = false; }
const char pgmstr_stop_on_stallguard_on[] PROGMEM = "Stop on sg: on";
const char pgmstr_stop_on_stallguard_off[] PROGMEM = "Stop on sg: off";
MenuItemToggleCallable motor_stop_on_stallguard_on_off(&is_motor_stop_on_stallguard_on,
pgmstr_stop_on_stallguard_on, pgmstr_stop_on_stallguard_off, &do_motor_stop_on_stallguard_off, &do_motor_stop_on_stallguard_on);
// motor print stallguard to serial
bool is_motor_stallguard_to_serial_on(){ return motors[last_entered_motor_menu].print_stallguard_to_serial; }
void do_motor_stallguard_to_serial_on(){ motors[last_entered_motor_menu].print_stallguard_to_serial = true; }
void do_motor_stallguard_to_serial_off(){ motors[last_entered_motor_menu].print_stallguard_to_serial = false; }
const char pgmstr_echo_to_serial_on[] PROGMEM = "Echo to serial: on";
const char pgmstr_echo_to_serial_off[] PROGMEM = "Echo to serial: off";
MenuItemToggleCallable motor_stallguard_to_serial_on_off(&is_motor_stallguard_to_serial_on,
pgmstr_echo_to_serial_on, pgmstr_echo_to_serial_off, &do_motor_stallguard_to_serial_off, &do_motor_stallguard_to_serial_on);
// motor stallguard
MenuItem* const motor_stallguard_items[] PROGMEM = {
&back,
&motor_stallguard_value,
&motor_sg_threshold,
&motor_stop_on_stallguard_on_off,
&motor_stallguard_to_serial_on_off,
};
Menu menu_motor_stallguard(motor_stallguard_items, sizeof(motor_stallguard_items) / 2);
MenuItem motor_stallguard(pgmstr_stallguard, &menu_motor_stallguard);
// motor show position & speed
const char pgmstr_pos[] PROGMEM = "Pos";
// const char pgmstr_pos_r[] PROGMEM = "Pos r.";
// const char pgmstr_pos_us[] PROGMEM = "Pos us.";
const char pgmstr_speed[] PROGMEM = "Speed";
const char pgmstr_plan_speed[] PROGMEM = "Plan. speed";
const char pgmstr_target[] PROGMEM = "Target";
const char pgmstr_show_pos_speed[] PROGMEM = "Show pos. & speed";
int32_t get_motor_actual_position(){
return motors[last_entered_motor_menu].position_usteps;
}
float get_motor_actual_speed(){
return motors[last_entered_motor_menu]._rpm;
}
float get_motor_planned_speed(){
return motors[last_entered_motor_menu].planned.rpm;
}
float get_motor_target_speed(){
return motors[last_entered_motor_menu].target_rpm;
}
MenuItemDynamicCallable<int32_t> motor_actual_position_item(pgmstr_pos, &get_motor_actual_position);
MenuItemDynamicCallable<float> motor_actual_speed_item(pgmstr_speed, &get_motor_actual_speed);
MenuItemDynamicCallable<float> motor_planned_speed_item(pgmstr_plan_speed, &get_motor_planned_speed);
MenuItemDynamicCallable<float> motor_target_speed_item(pgmstr_target, &get_motor_target_speed);
MenuItem* const motor_position_speed_items[] PROGMEM = {
&back,
&motor_actual_position_item,
&motor_actual_speed_item,
&motor_planned_speed_item,
&motor_target_speed_item,
};
Menu menu_motor_position_speed(motor_position_speed_items, sizeof(motor_position_speed_items) / 2);
MenuItem motor_position_speed(pgmstr_show_pos_speed, &menu_motor_position_speed);
// motor show position & direction
const char pgmstr_plan_pos[] PROGMEM = "Plan. pos";
const char pgmstr_direction[] PROGMEM = "Direction";
const char pgmstr_plan_dir[] PROGMEM = "Plan. dir";
const char pgmstr_show_pos_dir[] PROGMEM = "Show pos. & dir";
int32_t get_motor_planned_position(){
return motors[last_entered_motor_menu].planned.position_usteps;
}
uint16_t get_motor_actual_direction(){
return motors[last_entered_motor_menu].dir();
}
uint16_t get_motor_planned_direction(){
return motors[last_entered_motor_menu].planned.direction;
}
MenuItemDynamicCallable<int32_t> motor_planned_position_item(pgmstr_plan_pos, &get_motor_planned_position);
MenuItemDynamicCallable<uint16_t> motor_actual_direction_item(pgmstr_direction, &get_motor_actual_direction);
MenuItemDynamicCallable<uint16_t> motor_planned_direction_item(pgmstr_plan_dir, &get_motor_planned_direction);
MenuItem* const motor_position_direction_items[] PROGMEM = {
&back,
&motor_actual_position_item,
&motor_planned_position_item,
&motor_actual_direction_item,
&motor_planned_direction_item,
};
Menu menu_motor_position_direction(motor_position_direction_items, sizeof(motor_position_direction_items) / 2);
MenuItem motor_position_direction(pgmstr_show_pos_dir, &menu_motor_position_direction);
// motor
const char pgmstr_motor_x[] PROGMEM = "Motor X";
const char pgmstr_motor_y[] PROGMEM = "Motor Y";
const char pgmstr_motor_z[] PROGMEM = "Motor Z";
const char pgmstr_motor_e[] PROGMEM = "Motor E";
MenuItem* const motor_items[] PROGMEM = {
&back,
&motor_on_off,
&motor_speed,
&motor_direction,
&motor_start_stop,
&motor_manual_steps,
&motor_position_speed,
&motor_position_direction,
&motor_accel,
&motor_decel,
&motor_stallguard,
&motor_current,
&motor_hold_current_multiplier,
&motor_vsense_on_off,
&motor_msteps,
&motor_blank_time,
&motor_off_time,
&motor_dedge_on_off,
&motor_semin,
&motor_semax,
&motor_en_pwm_mode_on_off,
&motor_pwm_autoscale_on_off,
&motor_intpol_on_off,
&motor_invert_direction_on_off,
&motor_maximum_power,
};
MenuMotor menu_motor_x(MOTOR_X, motor_items, sizeof(motor_items) / 2);
MenuMotor menu_motor_y(MOTOR_Y, motor_items, sizeof(motor_items) / 2);
MenuMotor menu_motor_z(MOTOR_Z, motor_items, sizeof(motor_items) / 2);
MenuMotor menu_motor_e(MOTOR_E, motor_items, sizeof(motor_items) / 2);
MenuItem motor_x(pgmstr_motor_x, &menu_motor_x);
MenuItem motor_y(pgmstr_motor_y, &menu_motor_y);
MenuItem motor_z(pgmstr_motor_z, &menu_motor_z);
MenuItem motor_e(pgmstr_motor_e, &menu_motor_e);
// main menu
#ifndef CUSTOM_MENU
MenuItem* const main_menu_items[] PROGMEM = {
&motor_x,
&motor_y,
&motor_z,
&motor_e,
};
Menu main_menu(main_menu_items, sizeof(main_menu_items) / 2);
#endif