-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdlgConfig.cpp
146 lines (113 loc) · 4.39 KB
/
dlgConfig.cpp
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
//-------------------------------------------------
// A dialog to select a config.yaml from the SPFFS
//-------------------------------------------------
#include "dlgConfig.h"
#include "dlgConfirm.h"
#include <gActions.h> // FluidNC_extensions
#include <SettingsDefinitions.h> // FluidNC
// #include <GCode.h> // a weird way to include the proper FluidNC Config.h
#include <SPIFFS.h>
#include <FS.h>
dlgConfig dlg_config;
//----------------------------------------------------------------------
// WINDOW DEFINITION
//----------------------------------------------------------------------
#define MAX_CONFIG 5
#define MAX_CONFIG_FILENAME 31
static char config_filenames[MAX_CONFIG][MAX_CONFIG_FILENAME+1];
#define ID_CONFIG_0 (0x0000 | ID_TYPE_TEXT | ID_TYPE_BUTTON | ID_TYPE_MUTABLE)
#define ID_CONFIG_1 (0x0001 | ID_TYPE_TEXT | ID_TYPE_BUTTON | ID_TYPE_MUTABLE)
#define ID_CONFIG_2 (0x0002 | ID_TYPE_TEXT | ID_TYPE_BUTTON | ID_TYPE_MUTABLE)
#define ID_CONFIG_3 (0x0003 | ID_TYPE_TEXT | ID_TYPE_BUTTON | ID_TYPE_MUTABLE)
#define ID_CONFIG_4 (0x0004 | ID_TYPE_TEXT | ID_TYPE_BUTTON | ID_TYPE_MUTABLE)
static uiMutable configs[MAX_CONFIG] =
{
{ config_filenames[0], COLOR_BUTTON_HIDDEN, COLOR_WHITE, FONT_SMALL },
{ config_filenames[1], COLOR_BUTTON_HIDDEN, COLOR_WHITE, FONT_SMALL },
{ config_filenames[2], COLOR_BUTTON_HIDDEN, COLOR_WHITE, FONT_SMALL },
{ config_filenames[3], COLOR_BUTTON_HIDDEN, COLOR_WHITE, FONT_SMALL },
{ config_filenames[4], COLOR_BUTTON_HIDDEN, COLOR_WHITE, FONT_SMALL },
};
static const uiElement config_elements[] =
{
{ ID_CONFIG_0, 20, 35, 280, 33, V(&configs[0]) },
{ ID_CONFIG_1, 20, 69, 280, 33, V(&configs[1]) },
{ ID_CONFIG_2, 20, 103, 280, 33, V(&configs[2]) },
{ ID_CONFIG_3, 20, 137, 280, 33, V(&configs[3]) },
{ ID_CONFIG_4, 20, 171, 280, 33, V(&configs[4]) },
};
//-----------------------
// implementation
//-----------------------
dlgConfig::dlgConfig() :
uiWindow(config_elements,sizeof(config_elements)/sizeof(uiElement))
{
}
void dlgConfig::begin()
// set the app title to the current name and
// populate the list of existing config filenames
{
the_app.setTitle(config_filename->getStringValue());
// get the current config_filename from FluidNC::SettingsDefinitions.h extern'd "config_filename"
for (int i=0; i<MAX_CONFIG; i++)
{
configs[i].bg = COLOR_BUTTON_HIDDEN;
}
int num_config = 0;
File root = SPIFFS.open("/");
File file = root.openNextFile();
while (num_config < MAX_CONFIG && file)
{
const char* name = file.name();
if (!file.isDirectory())
{
int len = strlen(name);
int pos = len-1;
if (*name == '/') name++;
while (pos && name[pos] != '.') pos--;
// g_debug("filename=%s ext=%s",name,&name[pos]);
if (pos && !strcmp(&name[pos],".yaml"))
{
if (len > MAX_CONFIG_FILENAME)
{
g_error("Config filename %s is longer than MAX_CONFIG_FILENAME=%d",name,MAX_CONFIG_FILENAME);
}
else
{
configs[num_config].bg = COLOR_BLUE;
strcpy(config_filenames[num_config++],name);
}
}
}
file = root.openNextFile();
}
root.close();
uiWindow::begin();
}
const char *dlgConfig::getConfigFilename(int config_num)
{
return config_filenames[config_num];
}
void dlgConfig::setConfigFilename(int config_num)
{
g_info("CHANGING CONFIG to %s",config_filenames[config_num]);
#define CMD_BASE "$config/filename="
char buf[strlen(CMD_BASE) + MAX_CONFIG_FILENAME + 4];
strcpy(buf,CMD_BASE);
strcat(buf,config_filenames[config_num]);
strcat(buf,"\r\n");
gActions::pushGrblText(buf);
delay(1000);
gActions::g_reset();
ESP.restart();
while (1) {}
}
void dlgConfig::onButton(const uiElement *ele, bool pressed)
{
if (!pressed) // normal buttons happen when released
{
int config_num = ele->id_type & 0x0f; // could be upto 0xff
dlg_confirm.setConfirm(CONFIRM_COMMAND_SET_CONFIG + config_num);
the_app.openWindow(&dlg_confirm);
}
}