unit enable & interrupt auto disable
This commit is contained in:
parent
defa22a3e8
commit
87d1554cf0
@ -22,6 +22,8 @@ void pse_stepper_planer_tick(pse_unit* units, uint8_t units_num);
|
|||||||
void pse_sp_start_all(pse_unit* units, int unit_num);
|
void pse_sp_start_all(pse_unit* units, int unit_num);
|
||||||
void pse_sp_stop_all(pse_unit* units, int unit_num);
|
void pse_sp_stop_all(pse_unit* units, int unit_num);
|
||||||
|
|
||||||
|
void pse_sp_set_timer(TIM_HandleTypeDef* tim);
|
||||||
|
|
||||||
void pse_stepper_planer_compute_sps(pse_unit* unit);
|
void pse_stepper_planer_compute_sps(pse_unit* unit);
|
||||||
|
|
||||||
#endif /* INC_PSE_STEPPER_PLANER_H_ */
|
#endif /* INC_PSE_STEPPER_PLANER_H_ */
|
||||||
|
@ -47,11 +47,16 @@ static void unit_widget_enabled_handler(lv_event_t * e){
|
|||||||
lv_obj_t* button = lv_event_get_current_target(e);
|
lv_obj_t* button = lv_event_get_current_target(e);
|
||||||
lv_obj_t* label = lv_obj_get_child(button, 0);
|
lv_obj_t* label = lv_obj_get_child(button, 0);
|
||||||
lv_state_t state = lv_obj_get_state(button);
|
lv_state_t state = lv_obj_get_state(button);
|
||||||
|
|
||||||
|
|
||||||
|
pse_unit* unit = lv_event_get_user_data(e);
|
||||||
if(state & LV_STATE_CHECKED){
|
if(state & LV_STATE_CHECKED){
|
||||||
lv_label_set_text(label, LV_SYMBOL_CLOSE);
|
lv_label_set_text(label, LV_SYMBOL_OK);
|
||||||
|
unit->enabled = 0;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
lv_label_set_text(label, LV_SYMBOL_OK);
|
lv_label_set_text(label, LV_SYMBOL_CLOSE);
|
||||||
|
unit->enabled = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,10 +102,10 @@ static lv_obj_t* PSE_unit_widget(lv_obj_t* parent, pse_unit* pse_unit){
|
|||||||
lv_obj_t* enabled_label = lv_label_create(enabled);
|
lv_obj_t* enabled_label = lv_label_create(enabled);
|
||||||
lv_obj_set_width(enabled, lv_pct(100));
|
lv_obj_set_width(enabled, lv_pct(100));
|
||||||
lv_obj_add_flag(enabled, LV_OBJ_FLAG_CHECKABLE);
|
lv_obj_add_flag(enabled, LV_OBJ_FLAG_CHECKABLE);
|
||||||
lv_obj_add_event_cb(enabled, unit_widget_enabled_handler, LV_EVENT_ALL, NULL);
|
lv_obj_add_event_cb(enabled, unit_widget_enabled_handler, LV_EVENT_ALL, pse_unit);
|
||||||
lv_obj_set_flex_grow(enabled, 1);
|
lv_obj_set_flex_grow(enabled, 1);
|
||||||
lv_obj_center(enabled_label);
|
lv_obj_center(enabled_label);
|
||||||
lv_label_set_text(enabled_label, LV_SYMBOL_OK);
|
lv_label_set_text(enabled_label, LV_SYMBOL_CLOSE);
|
||||||
if(!pse_unit->enabled){
|
if(!pse_unit->enabled){
|
||||||
lv_obj_add_state(enabled, LV_STATE_CHECKED);
|
lv_obj_add_state(enabled, LV_STATE_CHECKED);
|
||||||
lv_event_send(enabled, LV_EVENT_VALUE_CHANGED, NULL);
|
lv_event_send(enabled, LV_EVENT_VALUE_CHANGED, NULL);
|
||||||
|
@ -256,7 +256,7 @@ int main(void)
|
|||||||
ADS7843_Init(&Touch_Def);
|
ADS7843_Init(&Touch_Def);
|
||||||
|
|
||||||
load_units(pse_units, pse_syringes, pse_stepper_confs, PSE_UNITS_NUM);
|
load_units(pse_units, pse_syringes, pse_stepper_confs, PSE_UNITS_NUM);
|
||||||
HAL_TIM_Base_Start_IT(&htim4);
|
pse_sp_set_timer(&htim4);
|
||||||
Home_Screen_Gen(pse_units, PSE_UNITS_NUM);
|
Home_Screen_Gen(pse_units, PSE_UNITS_NUM);
|
||||||
/* USER CODE END 2 */
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
|
@ -11,6 +11,9 @@
|
|||||||
|
|
||||||
#include "pse_stepper_planer.h"
|
#include "pse_stepper_planer.h"
|
||||||
|
|
||||||
|
static int units_running = 0; // counter of currently running units, to disable interrupts when unnecessary
|
||||||
|
static TIM_HandleTypeDef* htim; // main interrupt timer handle
|
||||||
|
|
||||||
void pse_stepper_planer_tick(pse_unit* units, uint8_t units_num){
|
void pse_stepper_planer_tick(pse_unit* units, uint8_t units_num){
|
||||||
for(int i = 0; i < units_num; i++){
|
for(int i = 0; i < units_num; i++){
|
||||||
pse_stepper_conf* c = units[i].stepper_conf;
|
pse_stepper_conf* c = units[i].stepper_conf;
|
||||||
@ -30,9 +33,20 @@ void pse_stepper_planer_tick(pse_unit* units, uint8_t units_num){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void pse_sp_start_axis(pse_stepper_conf* conf){
|
void pse_sp_start_axis(pse_stepper_conf* conf){
|
||||||
|
if(HAL_GPIO_ReadPin(conf->EN_GPIO_Port, conf->EN_GPIO_Pin) == GPIO_PIN_SET){
|
||||||
|
if(units_running == 0)
|
||||||
|
HAL_TIM_Base_Start_IT(htim);
|
||||||
|
units_running++;
|
||||||
|
}
|
||||||
|
|
||||||
HAL_GPIO_WritePin(conf->EN_GPIO_Port, conf->EN_GPIO_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(conf->EN_GPIO_Port, conf->EN_GPIO_Pin, GPIO_PIN_RESET);
|
||||||
}
|
}
|
||||||
void pse_sp_stop_axis(pse_stepper_conf* conf){
|
void pse_sp_stop_axis(pse_stepper_conf* conf){
|
||||||
|
if(HAL_GPIO_ReadPin(conf->EN_GPIO_Port, conf->EN_GPIO_Pin) == GPIO_PIN_RESET){
|
||||||
|
units_running--;
|
||||||
|
if(units_running == 0)
|
||||||
|
HAL_TIM_Base_Stop_IT(htim);
|
||||||
|
}
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,14 +65,24 @@ void pse_stepper_planer_compute_sps(pse_unit* unit){
|
|||||||
|
|
||||||
|
|
||||||
void pse_sp_start_all(pse_unit* units, int units_num){
|
void pse_sp_start_all(pse_unit* units, int units_num){
|
||||||
|
HAL_TIM_Base_Start_IT(htim);
|
||||||
|
units_running = units_num;
|
||||||
|
|
||||||
for(int i = 0; i < units_num; i++){
|
for(int i = 0; i < units_num; i++){
|
||||||
if(units[i].enabled)
|
if(units[i].enabled)
|
||||||
pse_sp_start_axis(units[i].stepper_conf);
|
pse_sp_start_axis(units[i].stepper_conf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void pse_sp_stop_all(pse_unit* units, int units_num){
|
void pse_sp_stop_all(pse_unit* units, int units_num){
|
||||||
|
HAL_TIM_Base_Stop_IT(htim);
|
||||||
|
units_running = 0;
|
||||||
|
|
||||||
for(int i = 0; i < units_num; i++){
|
for(int i = 0; i < units_num; i++){
|
||||||
if(units[i].enabled)
|
if(units[i].enabled)
|
||||||
pse_sp_stop_axis(units[i].stepper_conf);
|
pse_sp_stop_axis(units[i].stepper_conf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pse_sp_set_timer(TIM_HandleTypeDef* tim){
|
||||||
|
htim = tim;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user