44
55#include " AppState.h"
66
7+ /* *************************************************************************************
8+ * DEFINE
9+ **************************************************************************************/
10+
11+ #define COLOR_TEAL 0x00878F
12+ #define COLOR_LIGHT_TEAL 0x62AEB2
13+ #define COLOR_ORANGE 0xE47128
14+
15+ #define BUTTON_ENTER 6
16+
717/* *************************************************************************************
818 * CONSTANT
919 **************************************************************************************/
1020
1121static int const SAMPLE_BUF_SIZE = 6 *100 *2 ; /* 20 seconds. */
1222static float const HOME_POS[6 ] = {157.5 , 157.5 , 157.5 , 157.5 , 157.5 , 90.0 };
1323
14-
1524/* *************************************************************************************
1625 * GLOBAL VARIABLES
1726 **************************************************************************************/
1827
19- extern const char * btnm_map[] ;
20- extern lv_obj_t * counter ;
21- extern lv_obj_t * btnm ;
28+ lv_obj_t * counter ;
29+ lv_obj_t * btnm ;
30+ const char * btnm_map[] = { " RECORD " , " \n " , " REPLAY " , " \n " , " ZERO_POSITION " , " \n " , " \0 " } ;
2231
2332static float sample_buf[SAMPLE_BUF_SIZE];
2433static int sample_cnt;
@@ -28,6 +37,71 @@ RecordState LearnAndRepeatApp::_record_state;
2837ReplayState LearnAndRepeatApp::_replay_state;
2938ZeroState LearnAndRepeatApp::_zero_state;
3039
40+ extern LearnAndRepeatApp app;
41+
42+ /* *************************************************************************************
43+ * FUNCTION DEFINITION
44+ **************************************************************************************/
45+
46+ static void event_handler_menu (lv_event_t * e)
47+ {
48+ lv_event_code_t code = lv_event_get_code (e);
49+
50+ // if (code == LV_EVENT_CLICKED || (code == LV_EVENT_KEY && Braccio.getKey() == BUTTON_ENTER))
51+ if (code == LV_EVENT_KEY && Braccio.getKey () == BUTTON_ENTER)
52+ {
53+ lv_obj_t * obj = lv_event_get_target (e);
54+ uint32_t const id = lv_btnmatrix_get_selected_btn (obj);
55+
56+ switch (id)
57+ {
58+ case 0 : app.update (EventSource::Button_Record); break ;
59+ case 1 : app.update (EventSource::Button_Replay); break ;
60+ case 2 : app.update (EventSource::Button_ZeroPosition); break ;
61+ }
62+ }
63+ }
64+
65+
66+ void custom_main_menu ()
67+ {
68+ Braccio.lvgl_lock ();
69+ static lv_style_t style_focus;
70+ lv_style_init (&style_focus);
71+ lv_style_set_outline_color (&style_focus, lv_color_hex (COLOR_ORANGE));
72+ lv_style_set_outline_width (&style_focus, 4 );
73+
74+ static lv_style_t style_btn;
75+ lv_style_init (&style_btn);
76+ lv_style_set_bg_color (&style_btn, lv_color_hex (COLOR_LIGHT_TEAL));
77+ lv_style_set_text_color (&style_btn, lv_color_white ());
78+
79+ btnm = lv_btnmatrix_create (lv_scr_act ());
80+ lv_obj_set_size (btnm, 240 , 240 );
81+ lv_btnmatrix_set_map (btnm, btnm_map);
82+ lv_obj_align (btnm, LV_ALIGN_CENTER, 0 , 0 );
83+
84+ lv_obj_add_style (btnm, &style_btn, LV_PART_ITEMS);
85+ lv_obj_add_style (btnm, &style_focus, LV_PART_ITEMS | LV_STATE_FOCUS_KEY);
86+
87+ lv_btnmatrix_set_btn_ctrl (btnm, 0 , LV_BTNMATRIX_CTRL_DISABLED);
88+ lv_btnmatrix_set_btn_ctrl (btnm, 1 , LV_BTNMATRIX_CTRL_DISABLED);
89+ lv_btnmatrix_set_btn_ctrl (btnm, 2 , LV_BTNMATRIX_CTRL_DISABLED);
90+
91+ lv_btnmatrix_set_one_checked (btnm, true );
92+ lv_btnmatrix_set_selected_btn (btnm, 0 );
93+ lv_btnmatrix_set_btn_ctrl (btnm, 2 , LV_BTNMATRIX_CTRL_CHECKED);
94+
95+ counter = lv_label_create (btnm);
96+ lv_label_set_text_fmt (counter, " Counter: %d" , 0 );
97+ lv_obj_align (counter, LV_ALIGN_CENTER, 0 , 80 );
98+
99+ lv_obj_add_event_cb (btnm, event_handler_menu, LV_EVENT_ALL, NULL );
100+ Braccio.lvgl_unlock ();
101+
102+ Braccio.connectJoystickTo (btnm);
103+ }
104+
31105/* *************************************************************************************
32106 * State
33107 **************************************************************************************/
0 commit comments