forked from bigtreetech/BIGTREETECH-TouchScreenFirmware
-
Notifications
You must be signed in to change notification settings - Fork 15
/
SettingsMenu.c
161 lines (132 loc) · 5.26 KB
/
SettingsMenu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "SettingsMenu.h"
#include "includes.h"
// Version infomation
void menuInfo(void)
{
char buf[128];
const GUI_POINT clocks[] = {{0 * LCD_WIDTH / 3, 0 * BYTE_HEIGHT},
{1 * LCD_WIDTH / 3, 0 * BYTE_HEIGHT},
{2 * LCD_WIDTH / 3, 0 * BYTE_HEIGHT},
{0 * LCD_WIDTH / 3, 1 * BYTE_HEIGHT},
{1 * LCD_WIDTH / 3, 1 * BYTE_HEIGHT},
{2 * LCD_WIDTH / 3, 1 * BYTE_HEIGHT},};
const char* hardware = "Board : BIGTREETECH_" HARDWARE_VERSION;
const char* firmware = "Firmware: "HARDWARE_VERSION"." STRINGIFY(SOFTWARE_VERSION) " " __DATE__;
u16 HW_X = (LCD_WIDTH - GUI_StrPixelWidth((u8 *)hardware))/2;
u16 FW_X = (LCD_WIDTH - GUI_StrPixelWidth((u8 *)firmware))/2;
u16 centerY = LCD_HEIGHT/2;
u16 startX = MIN(HW_X, FW_X);
GUI_Clear(infoSettings.bg_color);
my_sprintf(buf, "SYS:%dMhz", mcuClocks.rccClocks.SYSCLK_Frequency / 1000000);
GUI_DispString(clocks[0].x, clocks[0].y, (uint8_t *)buf);
my_sprintf(buf, "APB1:%dMhz", mcuClocks.rccClocks.PCLK1_Frequency / 1000000);
GUI_DispString(clocks[1].x, clocks[1].y, (uint8_t *)buf);
my_sprintf(buf, "P1Tim:%dMhz", mcuClocks.PCLK1_Timer_Frequency / 1000000);
GUI_DispString(clocks[2].x, clocks[2].y, (uint8_t *)buf);
my_sprintf(buf, "AHB:%dMhz", mcuClocks.rccClocks.HCLK_Frequency / 1000000);
GUI_DispString(clocks[3].x, clocks[3].y, (uint8_t *)buf);
my_sprintf(buf, "APB2:%dMhz", mcuClocks.rccClocks.PCLK2_Frequency / 1000000);
GUI_DispString(clocks[4].x, clocks[4].y, (uint8_t *)buf);
my_sprintf(buf, "P2Tim:%dMhz", mcuClocks.PCLK2_Timer_Frequency / 1000000);
GUI_DispString(clocks[5].x, clocks[5].y, (uint8_t *)buf);
GUI_DispString(startX, centerY - BYTE_HEIGHT, (u8 *)hardware);
GUI_DispString(startX, centerY, (u8 *)firmware);
GUI_DispStringInRect(20, LCD_HEIGHT - (BYTE_HEIGHT*2), LCD_WIDTH-20, LCD_HEIGHT, textSelect(LABEL_TOUCH_TO_EXIT));
while(!isPress()) loopProcess();
while(isPress()) loopProcess();
infoMenu.cur--;
}
// Set uart pins to input, free uart
void menuDisconnect(void)
{
GUI_Clear(infoSettings.bg_color);
GUI_DispStringInRect(20, 0, LCD_WIDTH-20, LCD_HEIGHT, textSelect(LABEL_DISCONNECT_INFO));
GUI_DispStringInRect(20, LCD_HEIGHT - (BYTE_HEIGHT*2), LCD_WIDTH-20, LCD_HEIGHT, textSelect(LABEL_TOUCH_TO_EXIT));
Serial_ReSourceDeInit();
while(!isPress());
while(isPress());
Serial_ReSourceInit();
infoMenu.cur--;
}
MENUITEMS settingsItems = {
// title
LABEL_SETTINGS,
// icon label
{{ICON_SCREEN_SETTINGS, LABEL_SCREEN_SETTINGS},
{ICON_MACHINE_SETTINGS, LABEL_MACHINE_SETTINGS},
{ICON_FEATURE_SETTINGS, LABEL_FEATURE_SETTINGS},
{ICON_SCREEN_INFO, LABEL_SCREEN_INFO},
{ICON_DISCONNECT, LABEL_DISCONNECT},
{ICON_BAUD_RATE, LABEL_BACKGROUND},
{ICON_BACKGROUND, LABEL_BACKGROUND},
{ICON_BACK, LABEL_BACK},}
};
const ITEM itemBaudrate[ITEM_BAUDRATE_NUM] = {
// icon label
{ICON_BAUD_RATE, {.address = "2400"}},
{ICON_BAUD_RATE, {.address = "9600"}},
{ICON_BAUD_RATE, {.address = "19200"}},
{ICON_BAUD_RATE, {.address = "38400"}},
{ICON_BAUD_RATE, {.address = "57600"}},
{ICON_BAUD_RATE, {.address = "115200"}},
{ICON_BAUD_RATE, {.address = "250000"}},
{ICON_BAUD_RATE, {.address = "500000"}},
{ICON_BAUD_RATE, {.address = "1000000"}},
};
const u32 item_baudrate[ITEM_BAUDRATE_NUM] = {2400, 9600, 19200, 38400, 57600, 115200, 250000, 500000, 1000000};
static u8 item_baudrate_i = 0;
void menuSettings(void)
{
KEY_VALUES key_num = KEY_IDLE;
SETTINGS now = infoSettings;
for(u8 i=0; i<ITEM_BAUDRATE_NUM; i++)
{
if(infoSettings.baudrate == item_baudrate[i])
{
item_baudrate_i = i;
settingsItems.items[KEY_ICON_5] = itemBaudrate[item_baudrate_i];
}
}
menuDrawPage(&settingsItems);
while(infoMenu.menu[infoMenu.cur] == menuSettings)
{
key_num = menuKeyGetValue();
switch(key_num)
{
case KEY_ICON_0:
infoMenu.menu[++infoMenu.cur] = menuScreenSettings;
break;
case KEY_ICON_1:
infoMenu.menu[++infoMenu.cur] = menuMachineSettings;
break;
case KEY_ICON_2:
infoMenu.menu[++infoMenu.cur] = menuFeatureSettings;
break;
case KEY_ICON_3:
infoMenu.menu[++infoMenu.cur] = menuInfo;
break;
case KEY_ICON_4:
infoMenu.menu[++infoMenu.cur] = menuDisconnect;
break;
case KEY_ICON_5:
item_baudrate_i = (item_baudrate_i + 1) % ITEM_BAUDRATE_NUM;
settingsItems.items[key_num] = itemBaudrate[item_baudrate_i];
menuDrawItem(&settingsItems.items[key_num], key_num);
infoSettings.baudrate = item_baudrate[item_baudrate_i];
Serial_ReSourceDeInit(); // Serial_Init() will malloc a dynamic memory, so Serial_DeInit() first to free, then malloc again.
Serial_ReSourceInit();
reminderMessage(LABEL_UNCONNECTED, STATUS_UNCONNECT);
break;
case KEY_ICON_7:
infoMenu.cur--;
break;
default:
break;
}
loopProcess();
}
if(memcmp(&now, &infoSettings, sizeof(SETTINGS)))
{
storePara();
}
}