Skip to content

Commit e4b1be0

Browse files
committed
temp save.
1 parent 8bcacfd commit e4b1be0

File tree

3 files changed

+86
-88
lines changed

3 files changed

+86
-88
lines changed

examples/Braccio_Learn_and_Repeat/AppState.cpp

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,30 @@
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

1121
static int const SAMPLE_BUF_SIZE = 6*100*2; /* 20 seconds. */
1222
static 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

2332
static float sample_buf[SAMPLE_BUF_SIZE];
2433
static int sample_cnt;
@@ -28,6 +37,71 @@ RecordState LearnAndRepeatApp::_record_state;
2837
ReplayState LearnAndRepeatApp::_replay_state;
2938
ZeroState 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
**************************************************************************************/

examples/Braccio_Learn_and_Repeat/AppState.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ enum class StateName
2121
Record, Replay, Idle, Zero
2222
};
2323

24+
/**************************************************************************************
25+
* FUNCTION DECLARATION
26+
**************************************************************************************/
27+
28+
void custom_main_menu();
29+
2430
/**************************************************************************************
2531
* CLASS DECLARATION
2632
**************************************************************************************/

examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino

Lines changed: 2 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -6,94 +6,12 @@
66

77
#include "AppState.h"
88

9-
/**************************************************************************************
10-
* DEFINE
11-
**************************************************************************************/
12-
13-
#define COLOR_TEAL 0x00878F
14-
#define COLOR_LIGHT_TEAL 0x62AEB2
15-
#define COLOR_ORANGE 0xE47128
16-
17-
#define BUTTON_ENTER 6
18-
19-
/**************************************************************************************
20-
* GLOBAL CONST
21-
**************************************************************************************/
22-
23-
static float const homePos[6] = {157.5, 157.5, 157.5, 157.5, 157.5, 90.0};
24-
259
/**************************************************************************************
2610
* GLOBAL VARIABLES
2711
**************************************************************************************/
2812

29-
lv_obj_t * counter;
30-
lv_obj_t * btnm;
31-
32-
const char * btnm_map[] = { "RECORD", "\n", "REPLAY", "\n", "ZERO_POSITION", "\n", "\0" };
33-
34-
static LearnAndRepeatApp app;
35-
36-
/**************************************************************************************
37-
* FUNCTIONS
38-
**************************************************************************************/
39-
40-
static void eventHandlerMenu(lv_event_t * e)
41-
{
42-
lv_event_code_t code = lv_event_get_code(e);
43-
44-
//if (code == LV_EVENT_CLICKED || (code == LV_EVENT_KEY && Braccio.getKey() == BUTTON_ENTER))
45-
if (code == LV_EVENT_KEY && Braccio.getKey() == BUTTON_ENTER)
46-
{
47-
lv_obj_t * obj = lv_event_get_target(e);
48-
uint32_t const id = lv_btnmatrix_get_selected_btn(obj);
49-
50-
switch (id)
51-
{
52-
case 0: app.update(EventSource::Button_Record); break;
53-
case 1: app.update(EventSource::Button_Replay); break;
54-
case 2: app.update(EventSource::Button_ZeroPosition); break;
55-
}
56-
}
57-
}
58-
59-
void custom_main_menu()
60-
{
61-
Braccio.lvgl_lock();
62-
static lv_style_t style_focus;
63-
lv_style_init(&style_focus);
64-
lv_style_set_outline_color(&style_focus, lv_color_hex(COLOR_ORANGE));
65-
lv_style_set_outline_width(&style_focus, 4);
66-
67-
static lv_style_t style_btn;
68-
lv_style_init(&style_btn);
69-
lv_style_set_bg_color(&style_btn, lv_color_hex(COLOR_LIGHT_TEAL));
70-
lv_style_set_text_color(&style_btn, lv_color_white());
71-
72-
btnm = lv_btnmatrix_create(lv_scr_act());
73-
lv_obj_set_size(btnm, 240, 240);
74-
lv_btnmatrix_set_map(btnm, btnm_map);
75-
lv_obj_align(btnm, LV_ALIGN_CENTER, 0, 0);
76-
77-
lv_obj_add_style(btnm, &style_btn, LV_PART_ITEMS);
78-
lv_obj_add_style(btnm, &style_focus, LV_PART_ITEMS | LV_STATE_FOCUS_KEY);
79-
80-
lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_DISABLED);
81-
lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_DISABLED);
82-
lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_DISABLED);
83-
84-
lv_btnmatrix_set_one_checked(btnm, true);
85-
lv_btnmatrix_set_selected_btn(btnm, 0);
86-
lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED);
87-
88-
counter = lv_label_create(btnm);
89-
lv_label_set_text_fmt(counter, "Counter: %d" , 0);
90-
lv_obj_align(counter, LV_ALIGN_CENTER, 0, 80);
91-
92-
lv_obj_add_event_cb(btnm, eventHandlerMenu, LV_EVENT_ALL, NULL);
93-
Braccio.lvgl_unlock();
94-
95-
Braccio.connectJoystickTo(btnm);
96-
}
13+
extern lv_obj_t * btnm;
14+
LearnAndRepeatApp app;
9715

9816
/**************************************************************************************
9917
* SETUP/LOOP

0 commit comments

Comments
 (0)