152 lines
5.2 KiB
C
152 lines
5.2 KiB
C
/*
|
|
* home_screen.c
|
|
*
|
|
* Created on: Aug 7, 2023
|
|
* Author: leo
|
|
*/
|
|
|
|
#include <src/core/lv_disp.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
|
|
#include "PSE_unit_edit_screen.h"
|
|
|
|
#include "PSE_unit.h"
|
|
#include "lvgl.h"
|
|
|
|
static lv_obj_t* parent_screen;
|
|
|
|
static void back_button_handler(lv_event_t * e){
|
|
lv_event_code_t code = lv_event_get_code(e);
|
|
|
|
if(code == LV_EVENT_CLICKED) {
|
|
// Save
|
|
lv_scr_load_anim(parent_screen, LV_SCR_LOAD_ANIM_FADE_ON, 100, 100, true);
|
|
}
|
|
}
|
|
|
|
static lv_coord_t widg_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 widg_row_dsc[] = {LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST};
|
|
|
|
static lv_obj_t* flow_widget(lv_obj_t* parent, pse_unit* unit){
|
|
// The main container
|
|
lv_obj_t* cont = lv_obj_create(parent);
|
|
lv_obj_set_size(cont, lv_pct(24), lv_pct(100));
|
|
lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_COLUMN);
|
|
// lv_obj_add_event_cb(cont, unit_widget_clicked_handler, LV_EVENT_ALL, pse_unit);
|
|
|
|
// flow setting
|
|
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, "Debit : \n%d.%d\nmL/mn", unit->flow / 1000, unit->flow % 1000);
|
|
return cont;
|
|
}
|
|
static lv_obj_t* volume_widget(lv_obj_t* parent, pse_unit* unit){
|
|
// The main container
|
|
lv_obj_t* cont = lv_obj_create(parent);
|
|
lv_obj_set_size(cont, lv_pct(24), lv_pct(100));
|
|
lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_COLUMN);
|
|
// lv_obj_add_event_cb(cont, unit_widget_clicked_handler, LV_EVENT_ALL, pse_unit);
|
|
|
|
// volume setting
|
|
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, "Volume : \n%d.%d\nmL", unit->set_volume / 1000, unit->set_volume % 1000);
|
|
return cont;
|
|
}
|
|
static lv_obj_t* syringe_widget(lv_obj_t* parent, pse_unit* unit){
|
|
// The main container
|
|
lv_obj_t* cont = lv_obj_create(parent);
|
|
lv_obj_set_size(cont, lv_pct(24), lv_pct(100));
|
|
lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_COLUMN);
|
|
// lv_obj_add_event_cb(cont, unit_widget_clicked_handler, LV_EVENT_ALL, pse_unit);
|
|
|
|
pse_syringe* syringe = unit->syringe;
|
|
// syringe setting
|
|
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, "Seringue : \n%s\nD %d.%d mm", syringe->name, syringe->diameter/1000, syringe->diameter%1000);
|
|
return cont;
|
|
}
|
|
static lv_obj_t* controls_widget(lv_obj_t* parent, pse_unit* unit){
|
|
// The main container
|
|
lv_obj_t* cont = lv_obj_create(parent);
|
|
lv_obj_set_size(cont, lv_pct(24), lv_pct(100));
|
|
lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_COLUMN);
|
|
// lv_obj_add_event_cb(cont, unit_widget_clicked_handler, LV_EVENT_ALL, pse_unit);
|
|
|
|
// forward
|
|
lv_obj_t* forw = lv_btn_create(cont);
|
|
lv_obj_t* forw_label = lv_label_create(forw);
|
|
lv_obj_set_width(forw, lv_pct(100));
|
|
lv_obj_set_flex_grow(forw, 1);
|
|
lv_label_set_text(forw_label, LV_SYMBOL_LEFT);
|
|
lv_obj_center(forw_label);
|
|
// backward
|
|
lv_obj_t* back = lv_btn_create(cont);
|
|
lv_obj_t* back_label = lv_label_create(back);
|
|
lv_obj_set_width(back, lv_pct(100));
|
|
lv_obj_set_flex_grow(back, 1);
|
|
lv_label_set_text(back_label, LV_SYMBOL_RIGHT);
|
|
lv_obj_center(back_label);
|
|
// set Home
|
|
lv_obj_t* home = lv_btn_create(cont);
|
|
lv_obj_t* home_label = lv_label_create(home);
|
|
lv_obj_set_width(home, lv_pct(100));
|
|
lv_obj_set_flex_grow(home, 1);
|
|
lv_label_set_text(home_label, LV_SYMBOL_HOME);
|
|
lv_obj_center(home_label);
|
|
return cont;
|
|
}
|
|
|
|
void PSE_unit_edit_screen_Gen(lv_obj_t* parent, pse_unit* unit){
|
|
parent_screen = parent;
|
|
// Create a new screen
|
|
lv_obj_t* scr = lv_obj_create(NULL);
|
|
|
|
// create the top menu on the top 20%
|
|
lv_obj_t* top_menu = lv_obj_create(scr);
|
|
lv_obj_set_align(top_menu, LV_ALIGN_TOP_LEFT);
|
|
lv_obj_set_size(top_menu, lv_pct(100), lv_pct(20));
|
|
lv_obj_set_style_pad_all(top_menu, 5, 0);
|
|
|
|
// add a back button
|
|
lv_obj_t* back_button = lv_btn_create(top_menu);
|
|
lv_obj_set_size(back_button, lv_pct(10), lv_pct(100));
|
|
lv_obj_set_align(back_button, LV_ALIGN_TOP_LEFT);
|
|
lv_obj_add_event_cb(back_button, back_button_handler, LV_EVENT_ALL, NULL);
|
|
|
|
// add the back label
|
|
lv_obj_t* back_label = lv_label_create(back_button);
|
|
lv_label_set_text(back_label, LV_SYMBOL_LEFT);
|
|
lv_obj_center(back_label);
|
|
|
|
// grid layout for the widgets
|
|
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_set_size(units_grid, lv_pct(100), lv_pct(80));
|
|
lv_obj_set_style_pad_all(units_grid, 5, 0);
|
|
lv_obj_set_layout(units_grid, LV_LAYOUT_GRID);
|
|
|
|
lv_obj_set_grid_dsc_array(units_grid, widg_col_dsc, widg_row_dsc);
|
|
|
|
// Flow widget
|
|
lv_obj_t* flow = flow_widget(units_grid, unit);
|
|
lv_obj_set_grid_cell(flow, LV_GRID_ALIGN_CENTER, 0, 1, LV_GRID_ALIGN_CENTER, 0, 1);
|
|
// Set volume widget
|
|
lv_obj_t* vol = volume_widget(units_grid, unit);
|
|
lv_obj_set_grid_cell(vol, LV_GRID_ALIGN_CENTER, 1, 1, LV_GRID_ALIGN_CENTER, 0, 1);
|
|
// Syringe widget
|
|
lv_obj_t* syringe = syringe_widget(units_grid, unit);
|
|
lv_obj_set_grid_cell(syringe, LV_GRID_ALIGN_CENTER, 2, 1, LV_GRID_ALIGN_CENTER, 0, 1);
|
|
// controls widget
|
|
lv_obj_t* controls = controls_widget(units_grid, unit);
|
|
lv_obj_set_grid_cell(controls, LV_GRID_ALIGN_CENTER, 3, 1, LV_GRID_ALIGN_CENTER, 0, 1);
|
|
|
|
// fade in the new screen
|
|
lv_scr_load_anim(scr, LV_SCR_LOAD_ANIM_FADE_ON, 100, 100, false);
|
|
}
|