cash2ecash

cash2ecash: cash acceptor that issues digital cash (experimental)
Log | Files | Refs | Submodules | README | LICENSE

commit 1d9962076f2c6f755278b5d24a9f219f7f4bad2b
parent a859fc5b00b83ea236de68a90c93accd6c09c7aa
Author: Manuel Geissbühler <manuel@debian>
Date:   Sat, 28 Dec 2024 11:36:35 +0100

testing

Diffstat:
Msrc/cash2ecash.cpp | 9++++++---
Msrc/gui/screen.hpp | 43++++++++++++++++---------------------------
Msrc/gui/screenWelcomme.hpp | 45+++++++++++++++++++++------------------------
3 files changed, 43 insertions(+), 54 deletions(-)

diff --git a/src/cash2ecash.cpp b/src/cash2ecash.cpp @@ -2,6 +2,7 @@ #include <cstdio> #include <iostream> #include <ostream> +#include <src/misc/lv_types.h> @@ -9,8 +10,10 @@ #include "utils.hpp" #include "gui.hpp" - - +//callback function for button start +void startButtonCb(lv_event_t *e){ + std::cout << "button start was clicked" << std::endl; +} // Global Definitions enum state_e { INIT, SLEEP, IDLE, CONNECTION, ACCEPTCASH, DONE }; @@ -19,7 +22,7 @@ enum state_e state = INIT; char test; char *string; Gui gui; -ScreenWelcome welcome(800,480); +ScreenWelcome welcome(800, 480, &startButtonCb); void guiDriver(); int main(int argc, char *argv[]){ diff --git a/src/gui/screen.hpp b/src/gui/screen.hpp @@ -6,6 +6,7 @@ #include <src/core/lv_obj_pos.h> #include <src/core/lv_obj_style.h> #include <src/core/lv_obj_style_gen.h> +#include <src/font/lv_font.h> #include <src/layouts/flex/lv_flex.h> #include <src/layouts/grid/lv_grid.h> #include <src/layouts/lv_layout.h> @@ -38,6 +39,9 @@ class Screen { int32_t columnDesc[4] = {160, 448, 192, LV_GRID_TEMPLATE_LAST}; int32_t rowDesc[3] = {134, 346, LV_GRID_TEMPLATE_LAST}; + lv_style_t buttonsContainerStyle; + + protected: uint16_t width, height; @@ -47,8 +51,8 @@ class Screen { lv_obj_t *buttonsContainer; lv_obj_t *mainContentContainer; - //array for buttons - std::vector<lv_obj_t*> buttons; + lv_style_t buttonDefaultStyle; + lv_style_t instructionDefaultStyle; public: Screen(uint16_t width, uint16_t height) : width(width), height(height) @@ -82,40 +86,25 @@ class Screen { color.red = 0; lv_obj_set_style_bg_color(mainContentContainer, color, 0); - //set style & flow of buttons - static lv_style_t buttonsContainerStyle; + //set style & flow of buttons container lv_style_init(&buttonsContainerStyle); lv_style_set_flex_flow(&buttonsContainerStyle, LV_FLEX_FLOW_COLUMN_REVERSE); lv_style_set_flex_main_place(&buttonsContainerStyle, LV_FLEX_ALIGN_END); lv_style_set_flex_cross_place(&buttonsContainerStyle, LV_FLEX_ALIGN_CENTER); lv_style_set_layout(&buttonsContainerStyle, LV_LAYOUT_FLEX); - lv_style_set_pad_column(&buttonsContainerStyle, 0); + lv_style_set_pad_left(&buttonsContainerStyle, 5); + lv_style_set_pad_right(&buttonsContainerStyle, 5); lv_obj_add_style(buttonsContainer, &buttonsContainerStyle, 0); - //lv_obj_set_layout(buttonsContainer, LV_LAYOUT_FLEX); - //lv_obj_set_flex_flow(buttonsContainer, LV_FLEX_FLOW_COLUMN_REVERSE); - //lv_obj_set_flex_align(buttonsContainer, LV_FLEX_ALIGN_END, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_EVENLY); - - //add 3 buttons for testing purposes - lv_obj_t *button; - lv_obj_t *label; - int i; - for (i=0; i<3; i++) { - button = lv_button_create(buttonsContainer); - buttons.push_back(button); - lv_obj_set_size(button, LV_PCT(100),72); - label = lv_label_create(button); - lv_label_set_text_fmt(label, "button %d", i); - lv_obj_center(label); - } + //create default style for buttons + lv_style_init(&buttonDefaultStyle); + lv_style_set_size(&buttonDefaultStyle, LV_PCT(100), 72); + + //create default style for the instructions Text + lv_style_init(&instructionDefaultStyle); + lv_style_set_text_font(&instructionDefaultStyle, &lv_font_montserrat_24); - - //add the buttons to the layout - for (lv_obj_t* x : buttons) { - - break; - } } diff --git a/src/gui/screenWelcomme.hpp b/src/gui/screenWelcomme.hpp @@ -2,39 +2,36 @@ #define SCREEN_WELCOME_H #include "screen.hpp" #include <cstdint> +#include <src/core/lv_obj_event.h> +#include <src/core/lv_obj_style.h> #include <src/misc/lv_area.h> +#include <src/misc/lv_event.h> +#include <src/misc/lv_types.h> +#include <src/widgets/button/lv_button.h> +#include <src/widgets/label/lv_label.h> class ScreenWelcome : public Screen { private: - static void btn_event_cb(lv_event_t * e) - { - lv_event_code_t code = lv_event_get_code(e); - lv_obj_t * btn = (lv_obj_t*)lv_event_get_target(e); - if(code == LV_EVENT_CLICKED) { - static uint8_t cnt = 0; - cnt++; + lv_obj_t *instructionLabel; + lv_obj_t *startButton; + + - /*Get the first child of the button which is the label and change its text*/ - lv_obj_t * label = lv_obj_get_child(btn, 0); - lv_label_set_text_fmt(label, "Button: %d", cnt); - } - } + protected: public: - ScreenWelcome(uint16_t width, uint16_t height) : Screen(width, height){ - - /** - * Create a button with a label and react on click event. - */ + ScreenWelcome(uint16_t width, uint16_t height, void (*startCallback)(lv_event_t *e)) : Screen(width, height){ + //Set set the "instruction" + instructionLabel = lv_label_create(instructionsContainer); + lv_label_set_text(instructionLabel, "Press Start to begin..."); + lv_obj_add_style(instructionLabel, &instructionDefaultStyle, 0); - lv_obj_t * btn = lv_btn_create(screenPointer); /*Add a button the current screen*/ - lv_obj_set_pos(btn, 10, 10); /*Set its position*/ - lv_obj_set_size(btn, lv_pct(9), lv_pct(15)); /*Set its size*/ - lv_obj_add_event_cb(btn, this->btn_event_cb, LV_EVENT_ALL, NULL); /*Assign a callback to the button*/ - lv_obj_t * label = lv_label_create(btn); /*Add a label to the button*/ - lv_label_set_text(label, "Button"); /*Set the labels text*/ - lv_obj_center(label); + //Add button "Start" + startButton = lv_button_create(buttonsContainer); + lv_obj_t *label = lv_label_create(startButton); + lv_label_set_text(label, "Start"); + lv_obj_add_event_cb(startButton, startCallback, LV_EVENT_CLICKED, NULL); } };