pse unit struct
This commit is contained in:
parent
285890cb9c
commit
b234381ebc
31
Core/Inc/PSE_unit.h
Normal file
31
Core/Inc/PSE_unit.h
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* PSE_unit.h
|
||||
*
|
||||
* Created on: Aug 9, 2023
|
||||
* Author: leo
|
||||
*/
|
||||
|
||||
#ifndef INC_PSE_UNIT_H_
|
||||
#define INC_PSE_UNIT_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct{
|
||||
char name[16]; // brand / name
|
||||
uint16_t diameter; // diameter (in µm)
|
||||
} pse_syringe;
|
||||
|
||||
typedef enum {PORT_X, PORT_Y, PORT_Z, PORT_E} pse_ports;
|
||||
|
||||
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)
|
||||
uint32_t set_volume; // volume to stop at (0 for no max)
|
||||
pse_syringe* syringe; // associated syringe
|
||||
} pse_unit;
|
||||
|
||||
void load_units(pse_unit* units, uint8_t unit_num);
|
||||
|
||||
#endif
|
@ -8,6 +8,8 @@
|
||||
#ifndef INC_HOME_SCREEN_H_
|
||||
#define INC_HOME_SCREEN_H_
|
||||
|
||||
void Home_Screen_Gen(void);
|
||||
#include "PSE_unit.h"
|
||||
|
||||
void Home_Screen_Gen(pse_unit* units, uint8_t pse_unit_num);
|
||||
|
||||
#endif /* INC_HOME_SCREEN_H_ */
|
||||
|
21
Core/Src/PSE_unit.c
Normal file
21
Core/Src/PSE_unit.c
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* PSE_unit.c
|
||||
*
|
||||
* Created on: Aug 9, 2023
|
||||
* Author: leo
|
||||
*/
|
||||
|
||||
#include "PSE_unit.h"
|
||||
|
||||
// Dummy loading function until I decide between loading from SPIFlash or SD-MMC
|
||||
void load_units(pse_unit* units, uint8_t unit_num){
|
||||
for(int i = 0; i < unit_num; i++){
|
||||
units[i] = (pse_unit){
|
||||
.enabled = i%2,
|
||||
.port = i,
|
||||
.flow = 1500,
|
||||
.volume = 0,
|
||||
.set_volume = 0,
|
||||
};
|
||||
}
|
||||
}
|
@ -5,17 +5,18 @@
|
||||
* Author: leo
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "lvgl.h"
|
||||
|
||||
#define PSE_UNITS_NUM 4 // number of units (4 in our case, X, Y, Z and extr)
|
||||
#include "PSE_unit.h"
|
||||
|
||||
static void run_handler(lv_event_t * e){
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
|
||||
if(code == LV_EVENT_VALUE_CHANGED) {
|
||||
lv_obj_t* button = lv_event_get_target(e);
|
||||
lv_obj_t* button = lv_event_get_current_target(e);
|
||||
lv_obj_t* label = lv_obj_get_child(button, 0);
|
||||
lv_state_t state = lv_obj_get_state(button);
|
||||
if(state & LV_STATE_CHECKED){
|
||||
@ -30,7 +31,24 @@ static void run_handler(lv_event_t * e){
|
||||
static lv_coord_t units_col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST};
|
||||
static lv_coord_t units_row_dsc[] = {LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST};
|
||||
|
||||
static lv_obj_t* PSE_unit_widget(lv_obj_t* parent){
|
||||
|
||||
static void unit_widget_enabled_handler(lv_event_t * e){
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
|
||||
if(code == LV_EVENT_VALUE_CHANGED) {
|
||||
lv_obj_t* button = lv_event_get_current_target(e);
|
||||
lv_obj_t* label = lv_obj_get_child(button, 0);
|
||||
lv_state_t state = lv_obj_get_state(button);
|
||||
if(state & LV_STATE_CHECKED){
|
||||
lv_label_set_text(label, LV_SYMBOL_CLOSE);
|
||||
}
|
||||
else{
|
||||
lv_label_set_text(label, LV_SYMBOL_OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static lv_obj_t* PSE_unit_widget(lv_obj_t* parent, pse_unit* pse_unit){
|
||||
// The main container
|
||||
lv_obj_t* cont = lv_obj_create(parent);
|
||||
lv_obj_set_size(cont, lv_pct(24), lv_pct(100));
|
||||
@ -40,13 +58,13 @@ static lv_obj_t* PSE_unit_widget(lv_obj_t* parent){
|
||||
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(flow, "-----.--\nuL/mn");
|
||||
lv_label_set_text_fmt(flow, "%d.%d\nuL/mn", pse_unit->flow / 1000, pse_unit->flow % 1000);
|
||||
|
||||
// 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(vol, "-----.--\nmL");
|
||||
lv_label_set_text_fmt(vol, "%d.%d\nmL", pse_unit->volume / 1000, pse_unit->volume % 1000);
|
||||
|
||||
// home button
|
||||
lv_obj_t* home = lv_btn_create(cont);
|
||||
@ -58,14 +76,20 @@ static lv_obj_t* PSE_unit_widget(lv_obj_t* parent){
|
||||
// enabled button
|
||||
lv_obj_t* enabled = lv_btn_create(cont);
|
||||
lv_obj_t* enabled_label = lv_label_create(enabled);
|
||||
lv_obj_set_width(enabled, lv_pct(100));
|
||||
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_set_flex_grow(enabled, 1);
|
||||
lv_obj_center(enabled_label);
|
||||
lv_label_set_text(enabled_label, LV_SYMBOL_OK);
|
||||
if(!pse_unit->enabled){
|
||||
lv_obj_add_state(enabled, LV_STATE_CHECKED);
|
||||
lv_event_send(enabled, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
}
|
||||
return cont;
|
||||
}
|
||||
|
||||
void Home_Screen_Gen(void){
|
||||
void Home_Screen_Gen(pse_unit* pse_units, uint8_t pse_unit_num){
|
||||
// Create a new screen
|
||||
lv_obj_t* scr = lv_obj_create(NULL);
|
||||
|
||||
@ -96,8 +120,8 @@ void Home_Screen_Gen(void){
|
||||
|
||||
lv_obj_set_grid_dsc_array(units_grid, units_col_dsc, units_row_dsc);
|
||||
|
||||
for(int i = 0; i < PSE_UNITS_NUM; i++){
|
||||
lv_obj_t* obj = PSE_unit_widget(units_grid);
|
||||
for(int i = 0; i < pse_unit_num; i++){
|
||||
lv_obj_t* obj = PSE_unit_widget(units_grid, &pse_units[i]);
|
||||
lv_obj_set_grid_cell(obj, LV_GRID_ALIGN_CENTER, i, 1, LV_GRID_ALIGN_CENTER, 0, 1);
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "ADS7843.h"
|
||||
|
||||
#include "home_screen.h"
|
||||
#include "PSE_unit.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@ -209,7 +210,9 @@ int main(void)
|
||||
// initialize the Touchscreen Driver
|
||||
ADS7843_Init(&Touch_Def);
|
||||
|
||||
Home_Screen_Gen();
|
||||
pse_unit pse_units[PSE_UNITS_NUM];
|
||||
load_units(pse_units, PSE_UNITS_NUM);
|
||||
Home_Screen_Gen(pse_units, PSE_UNITS_NUM);
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
|
Loading…
x
Reference in New Issue
Block a user