From 7bcb3a7afa7bb6ca19d1c33939bd28d2a9db5b98 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 13 Sep 2023 18:09:20 +0200 Subject: [PATCH] dummy volume delired readout --- Core/Inc/PSE_unit.h | 6 +++++- Core/Src/PSE_unit.c | 8 ++++++++ Core/Src/PSE_unit_edit_screen.c | 3 +++ Core/Src/home_screen.c | 26 ++++++++++++++++++++++---- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/Core/Inc/PSE_unit.h b/Core/Inc/PSE_unit.h index f099824..b32d8d4 100644 --- a/Core/Inc/PSE_unit.h +++ b/Core/Inc/PSE_unit.h @@ -49,11 +49,13 @@ typedef struct{ uint8_t enabled; pse_ports port; // physical port on which this unit is connected uint32_t flow; // flow (in µL.min-1) - uint32_t volume; // current volume dispensed (in µL) + int32_t volume; // current volume dispensed (in µL) uint32_t set_volume; // volume to stop at (0 for no max) pse_syringe* syringe; // associated syringe pse_stepper_conf* stepper_conf; // hardware configuration for the associated stepper pse_home_display* home_display; // Widgets for updating the home screen + int32_t start_pos; // movement start position for volume calculation + uint32_t nL_per_step; // pL delivered per step } pse_unit; @@ -61,4 +63,6 @@ void load_units(pse_unit* units, pse_syringe* syringes, pse_stepper_conf* steppe void load_units_short(pse_unit* units, uint8_t unit_num, uint16_t ws_ind); void save_units(pse_unit* units, uint8_t unit_num, uint16_t ws_ind); +void pse_unit_compute_volume_delivered(pse_unit* unit); +void pse_unit_compute_volume_per_step(pse_unit* unit); #endif diff --git a/Core/Src/PSE_unit.c b/Core/Src/PSE_unit.c index dd5b124..d75affa 100644 --- a/Core/Src/PSE_unit.c +++ b/Core/Src/PSE_unit.c @@ -121,3 +121,11 @@ void save_units(pse_unit* units, uint8_t unit_num, uint16_t ws_ind){ f_close(&saveFile); free(filename); } + +void pse_unit_compute_volume_delivered(pse_unit* unit){ + unit->volume = (int64_t)1 * (unit->stepper_conf->steps_counter - unit->start_pos) * unit->nL_per_step / 1000; +} + +void pse_unit_compute_volume_per_step(pse_unit* unit){ + unit->nL_per_step = 10; +} diff --git a/Core/Src/PSE_unit_edit_screen.c b/Core/Src/PSE_unit_edit_screen.c index 9cc2e22..bd43e7d 100644 --- a/Core/Src/PSE_unit_edit_screen.c +++ b/Core/Src/PSE_unit_edit_screen.c @@ -33,6 +33,9 @@ static void back_button_handler(lv_event_t * e){ // update stepper pwm generation pse_stepper_planer_compute_sps(c_pse_unit); + // compute volume delivered per steps + pse_unit_compute_volume_per_step(c_pse_unit); + // go back to the main menu Home_Screen_Gen(c_pse_units, c_pse_units_num, true); } diff --git a/Core/Src/home_screen.c b/Core/Src/home_screen.c index 8745ac1..9ff7a28 100644 --- a/Core/Src/home_screen.c +++ b/Core/Src/home_screen.c @@ -7,6 +7,7 @@ #include #include +#include #include "lvgl.h" @@ -20,6 +21,19 @@ static int units_num; static uint16_t workspace_index = 0; static lv_obj_t* ws_label; +static lv_timer_t* volume_readout_update_timer; + +void volume_readout_update(lv_timer_t* timer){ + for(int i = 0; i < units_num; i++){ + if(units[i].enabled){ + pse_home_display* disp = units[i].home_display; + pse_unit_compute_volume_delivered(&units[i]); + int32_t volume = units[i].volume; + lv_label_set_text_fmt(disp->volume, "%d.%.3lu\nmL", volume / 1000, abs(volume) % 1000); + } + } +} + static void run_handler(lv_event_t * e){ lv_event_code_t code = lv_event_get_code(e); @@ -31,10 +45,13 @@ static void run_handler(lv_event_t * e){ lv_label_set_text(label, LV_SYMBOL_PAUSE); pse_sp_set_dir_all(units, units_num, 1); pse_sp_start_all(units, units_num); + + volume_readout_update_timer = lv_timer_create(volume_readout_update, 100, NULL); } else{ lv_label_set_text(label, LV_SYMBOL_PLAY); pse_sp_stop_all(units, units_num); + lv_timer_del(volume_readout_update_timer); } } } @@ -84,6 +101,7 @@ static void unit_widget_clicked_handler(lv_event_t* e){ lv_event_code_t code = lv_event_get_code(e); if(code == LV_EVENT_CLICKED) { + if(volume_readout_update_timer != NULL) lv_timer_del(volume_readout_update_timer); pse_unit* unit = lv_event_get_user_data(e); PSE_unit_edit_screen_Gen(units, unit, units_num, workspace_index); } @@ -92,8 +110,8 @@ static void unit_widget_clicked_handler(lv_event_t* e){ static void update_readouts_widgets(){ for(int i = 0; i < units_num; i++){ pse_unit* pse_unit = &units[i]; - lv_label_set_text_fmt(pse_unit->home_display->flow, "%02lu.%03lu\nmL/mn", pse_unit->flow / 1000, pse_unit->flow % 1000); - lv_label_set_text_fmt(pse_unit->home_display->volume, "%lu.%lu\nmL", pse_unit->volume / 1000, pse_unit->volume % 1000); + lv_label_set_text_fmt(pse_unit->home_display->flow, "%u.%03u\nmL/mn", pse_unit->flow / 1000, pse_unit->flow % 1000); + // lv_label_set_text_fmt(pse_unit->home_display->volume, "%lu.%lu\nmL", pse_unit->volume / 1000, pse_unit->volume % 1000); lv_obj_t* enabled = pse_unit->home_display->enabled; lv_obj_t* enabled_label = lv_obj_get_child(enabled, 0); @@ -143,14 +161,14 @@ static lv_obj_t* PSE_unit_widget(lv_obj_t* parent, pse_unit* pse_unit){ lv_obj_t* flow = lv_label_create(cont); lv_obj_set_width(flow, lv_pct(100)); lv_obj_set_flex_grow(flow, 1); - lv_label_set_text_fmt(flow, "%02lu.%03lu\nmL/mn", pse_unit->flow / 1000, pse_unit->flow % 1000); + lv_label_set_text_fmt(flow, "%02u.%03u\nmL/mn", pse_unit->flow / 1000, pse_unit->flow % 1000); pse_unit->home_display->flow = flow; // volume delivered readout lv_obj_t* vol = lv_label_create(cont); lv_obj_set_width(vol, lv_pct(100)); lv_obj_set_flex_grow(vol, 1); - lv_label_set_text_fmt(vol, "%lu.%lu\nmL", pse_unit->volume / 1000, pse_unit->volume % 1000); + lv_label_set_text_fmt(vol, "%d.%03u\nmL", pse_unit->volume / 1000, abs(pse_unit->volume) % 1000); pse_unit->home_display->volume = vol; // home button