add a reverse option and associated ui
This commit is contained in:
parent
5fb0c92111
commit
65789dd269
@ -54,6 +54,7 @@ typedef struct{
|
|||||||
// unit definition
|
// unit definition
|
||||||
typedef struct{
|
typedef struct{
|
||||||
uint8_t enabled;
|
uint8_t enabled;
|
||||||
|
uint8_t reversed; // is the unit reversed (syringue pointing to the motor or away from it)
|
||||||
pse_ports port; // physical port on which this unit is connected
|
pse_ports port; // physical port on which this unit is connected
|
||||||
uint32_t flow; // flow (in µL.min-1)
|
uint32_t flow; // flow (in µL.min-1)
|
||||||
int32_t volume; // current volume dispensed (in µL)
|
int32_t volume; // current volume dispensed (in µL)
|
||||||
|
@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
void pse_sp_start_axis(pse_stepper_conf* conf, pse_stepper_status* status);
|
void pse_sp_start_axis(pse_stepper_conf* conf, pse_stepper_status* status);
|
||||||
void pse_sp_stop_axis(pse_stepper_conf* conf);
|
void pse_sp_stop_axis(pse_stepper_conf* conf);
|
||||||
void pse_sp_set_dir(pse_stepper_conf* conf, int dir);
|
void pse_sp_set_dir(pse_unit* unit, int dir);
|
||||||
int pse_sp_get_dir(pse_stepper_conf* conf);
|
int pse_sp_get_dir(pse_unit* unit);
|
||||||
void pse_stepper_planer_tick(pse_unit* unit);
|
void pse_stepper_planer_tick(pse_unit* unit);
|
||||||
void pse_sp_jog_speed(pse_stepper_conf* conf, pse_stepper_status* sta, int status);
|
void pse_sp_jog_speed(pse_stepper_conf* conf, pse_stepper_status* sta, int status);
|
||||||
|
|
||||||
|
@ -23,6 +23,17 @@ static pse_unit* c_pse_unit;
|
|||||||
static uint8_t c_pse_units_num;
|
static uint8_t c_pse_units_num;
|
||||||
static uint16_t ws_index;
|
static uint16_t ws_index;
|
||||||
|
|
||||||
|
static void reverse_button_handler(lv_event_t * e){
|
||||||
|
lv_event_code_t code = lv_event_get_code(e);
|
||||||
|
lv_obj_t* button = lv_event_get_current_target(e);
|
||||||
|
lv_obj_t* label = lv_obj_get_child(button, 0);
|
||||||
|
|
||||||
|
c_pse_unit->reversed = !c_pse_unit->reversed;
|
||||||
|
lv_label_set_text(label, c_pse_unit->reversed?LV_SYMBOL_PREV:LV_SYMBOL_NEXT);
|
||||||
|
|
||||||
|
save_units(c_pse_units, c_pse_units_num, ws_index);
|
||||||
|
}
|
||||||
|
|
||||||
static void back_button_handler(lv_event_t * e){
|
static void back_button_handler(lv_event_t * e){
|
||||||
lv_event_code_t code = lv_event_get_code(e);
|
lv_event_code_t code = lv_event_get_code(e);
|
||||||
|
|
||||||
@ -192,7 +203,7 @@ static void jog_forward_button_handler(lv_event_t* e){
|
|||||||
|
|
||||||
if(code == LV_EVENT_PRESSED) {
|
if(code == LV_EVENT_PRESSED) {
|
||||||
pse_sp_jog_speed(unit->stepper_conf, unit->stepper_status, 1);
|
pse_sp_jog_speed(unit->stepper_conf, unit->stepper_status, 1);
|
||||||
pse_sp_set_dir(unit->stepper_conf, 1);
|
pse_sp_set_dir(unit, 1);
|
||||||
pse_sp_start_axis(unit->stepper_conf, unit->stepper_status);
|
pse_sp_start_axis(unit->stepper_conf, unit->stepper_status);
|
||||||
}
|
}
|
||||||
else if(code == LV_EVENT_RELEASED){
|
else if(code == LV_EVENT_RELEASED){
|
||||||
@ -207,7 +218,7 @@ static void jog_backward_button_handler(lv_event_t* e){
|
|||||||
|
|
||||||
if(code == LV_EVENT_PRESSED) {
|
if(code == LV_EVENT_PRESSED) {
|
||||||
pse_sp_jog_speed(unit->stepper_conf, unit->stepper_status, 1);
|
pse_sp_jog_speed(unit->stepper_conf, unit->stepper_status, 1);
|
||||||
pse_sp_set_dir(unit->stepper_conf, 0);
|
pse_sp_set_dir(unit, 0);
|
||||||
pse_sp_start_axis(unit->stepper_conf, unit->stepper_status);
|
pse_sp_start_axis(unit->stepper_conf, unit->stepper_status);
|
||||||
}
|
}
|
||||||
else if(code == LV_EVENT_RELEASED){
|
else if(code == LV_EVENT_RELEASED){
|
||||||
@ -287,6 +298,16 @@ void PSE_unit_edit_screen_Gen(pse_unit* units, pse_unit* c_unit, uint8_t units_n
|
|||||||
lv_label_set_text(back_label, LV_SYMBOL_LEFT);
|
lv_label_set_text(back_label, LV_SYMBOL_LEFT);
|
||||||
lv_obj_center(back_label);
|
lv_obj_center(back_label);
|
||||||
|
|
||||||
|
// add a reverse button
|
||||||
|
lv_obj_t* reverse_button = lv_btn_create(top_menu);
|
||||||
|
lv_obj_set_size(reverse_button, lv_pct(10), lv_pct(100));
|
||||||
|
lv_obj_set_align(reverse_button, LV_ALIGN_TOP_RIGHT);
|
||||||
|
lv_obj_add_event_cb(reverse_button, reverse_button_handler, LV_EVENT_CLICKED, NULL);
|
||||||
|
// and it's button
|
||||||
|
lv_obj_t* reverse_label = lv_label_create(reverse_button);
|
||||||
|
lv_label_set_text(reverse_label, c_unit->reversed?LV_SYMBOL_PREV:LV_SYMBOL_NEXT);
|
||||||
|
lv_obj_center(reverse_label);
|
||||||
|
|
||||||
// grid layout for the widgets
|
// grid layout for the widgets
|
||||||
lv_obj_t* units_grid = lv_obj_create(scr);
|
lv_obj_t* units_grid = lv_obj_create(scr);
|
||||||
lv_obj_align_to(units_grid, top_menu, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
|
lv_obj_align_to(units_grid, top_menu, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
|
||||||
|
@ -18,7 +18,7 @@ void pse_stepper_planer_tick(pse_unit* unit){
|
|||||||
pse_stepper_status* s = unit->stepper_status;
|
pse_stepper_status* s = unit->stepper_status;
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(c->STEP_GPIO_Port, c->STEP_GPIO_Pin);
|
HAL_GPIO_TogglePin(c->STEP_GPIO_Port, c->STEP_GPIO_Pin);
|
||||||
s->steps_counter += (pse_sp_get_dir(c)?1:-1) * HAL_GPIO_ReadPin(c->STEP_GPIO_Port, c->STEP_GPIO_Pin);
|
s->steps_counter += (pse_sp_get_dir(unit)?1:-1) * HAL_GPIO_ReadPin(c->STEP_GPIO_Port, c->STEP_GPIO_Pin);
|
||||||
if(s->stop_at_limit && s->steps_counter == s->stop_steps){
|
if(s->stop_at_limit && s->steps_counter == s->stop_steps){
|
||||||
pse_sp_jog_speed(c, s, 0);
|
pse_sp_jog_speed(c, s, 0);
|
||||||
pse_sp_stop_axis(c);
|
pse_sp_stop_axis(c);
|
||||||
@ -36,12 +36,15 @@ void pse_sp_stop_axis(pse_stepper_conf* conf){
|
|||||||
HAL_GPIO_WritePin(conf->EN_GPIO_Port, conf->EN_GPIO_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(conf->EN_GPIO_Port, conf->EN_GPIO_Pin, GPIO_PIN_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pse_sp_set_dir(pse_stepper_conf* conf, int dir){
|
void pse_sp_set_dir(pse_unit* unit, int dir){
|
||||||
HAL_GPIO_WritePin(conf->DIR_GPIO_Port, conf->DIR_GPIO_Pin, dir);
|
pse_stepper_conf* conf = unit->stepper_conf;
|
||||||
|
HAL_GPIO_WritePin(conf->DIR_GPIO_Port, conf->DIR_GPIO_Pin, unit->reversed?-dir:dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
int pse_sp_get_dir(pse_stepper_conf* conf){
|
int pse_sp_get_dir(pse_unit* unit){
|
||||||
return HAL_GPIO_ReadPin(conf->DIR_GPIO_Port, conf->DIR_GPIO_Pin);
|
pse_stepper_conf* conf = unit->stepper_conf;
|
||||||
|
int val = HAL_GPIO_ReadPin(conf->DIR_GPIO_Port, conf->DIR_GPIO_Pin);
|
||||||
|
return (unit->reversed?-val:val);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division
|
// https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division
|
||||||
@ -100,7 +103,7 @@ void pse_stepper_planer_compute_sps(pse_unit* unit){
|
|||||||
|
|
||||||
void pse_sp_set_dir_all(pse_unit* units, int units_num, int dir){
|
void pse_sp_set_dir_all(pse_unit* units, int units_num, int dir){
|
||||||
for(int i = 0; i < units_num; i++){
|
for(int i = 0; i < units_num; i++){
|
||||||
pse_sp_set_dir(units[i].stepper_conf, dir);
|
pse_sp_set_dir(&units[i], dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user