Skip to content

Commit c7f9190

Browse files
authored
Merge pull request #214 from hpsaturn/fix_issue_212_cli_defaults
Fix issue 212 cli defaults
2 parents 63ac56d + 33ff434 commit c7f9190

File tree

6 files changed

+52
-8
lines changed

6 files changed

+52
-8
lines changed

lib/cli/cli.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,39 @@ void wcli_scshot(char *args, Stream *response)
101101
}
102102
}
103103

104+
/**
105+
* @brief list of user preference key. This depends of EasyPreferences manifest.
106+
* @author @Hpsaturn. Method migrated from CanAirIO project
107+
*/
108+
void wcli_klist(char *args, Stream *response) {
109+
Pair<String, String> operands = wcli.parseCommand(args);
110+
String opt = operands.first();
111+
response->printf("\n%11s \t%s \t%s \r\n", "KEYNAME", "DEFINED", "VALUE");
112+
response->printf("\n%11s \t%s \t%s \r\n", "=======", "=======", "=====");
113+
114+
for (int i = PKEYS::KUSER+1; i < PKEYS::KCOUNT; i++) {
115+
String key = cfg.getKey((CONFKEYS)i);
116+
bool isDefined = cfg.isKey(key);
117+
String defined = isDefined ? "custom " : "default";
118+
String value = "";
119+
if (isDefined) value = cfg.getValue(key);
120+
response->printf("%11s \t%s \t%s \r\n", key, defined.c_str(), value.c_str());
121+
}
122+
}
123+
124+
/**
125+
* @brief set an user preference key. This depends of EasyPreferences manifest.
126+
* @author @Hpsaturn. Method migrated from CanAirIO project
127+
*/
128+
void wcli_kset(char *args, Stream *response) {
129+
Pair<String, String> operands = wcli.parseCommand(args);
130+
String key = operands.first();
131+
String v = operands.second();
132+
if(cfg.saveAuto(key,v)){
133+
response->printf("saved key %s\t: %s\r\n", key, v);
134+
}
135+
}
136+
104137
void wcli_waypoint(char *args, Stream *response)
105138
{
106139
Pair<String, String> operands = wcli.parseCommand(args);
@@ -280,7 +313,6 @@ void wcli_settings(char *args, Stream *response)
280313
}
281314
}
282315

283-
284316
void wcli_webfile(char *args, Stream *response)
285317
{
286318
Pair<String, String> operands = wcli.parseCommand(args);
@@ -327,6 +359,8 @@ void initShell(){
327359
wcli.add("waypoint", &wcli_waypoint, "\twaypoint utilities");
328360
wcli.add("settings", &wcli_settings, "\tdevice settings");
329361
wcli.add("webfile", &wcli_webfile, "\tenable/disable Web file server");
362+
wcli.add("klist", &wcli_klist, "\t\tlist of user extra preferences");
363+
wcli.add("kset", &wcli_kset, "\t\tset an user extra preference");
330364
wcli.begin("IceNav");
331365
}
332366

lib/gps/gps.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ double getLat()
132132
{
133133
if (GPS.location.isValid())
134134
return GPS.location.lat();
135+
else if (cfg.getDouble(PKEYS::KLAT_DFL,0.0) != 0.0)
136+
{
137+
log_v("getLat: %02f\r\n",cfg.getDouble(PKEYS::KLAT_DFL,0.0));
138+
return cfg.getDouble(PKEYS::KLAT_DFL,0.0);
139+
}
135140
else
136141
{
137142
#ifdef DEFAULT_LAT
@@ -150,6 +155,11 @@ double getLon()
150155
{
151156
if (GPS.location.isValid())
152157
return GPS.location.lng();
158+
else if (cfg.getDouble(PKEYS::KLON_DFL,0.0) != 0.0)
159+
{
160+
log_v("getLon: %02f\r\n",cfg.getDouble(PKEYS::KLON_DFL,0.0));
161+
return cfg.getDouble(PKEYS::KLON_DFL,0.0);
162+
}
153163
else
154164
{
155165
#ifdef DEFAULT_LON

lib/preferences/preferences-keys.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
X(KCOMP_ROT, "Compass_rot", BOOL) \
1919
X(KGPS_SPEED, "GPS_speed", SHORT) \
2020
X(KGPS_RATE, "GPS_rate", SHORT) \
21+
X(KWEB_FILE, "Web_file", BOOL) \
22+
X(KUSER, "-----", UNKNOWN) \
2123
X(KDEF_ZOOM, "Def_zoom", UINT) \
2224
X(KGPS_TX, "GPS_tx", UINT) \
2325
X(KGPS_RX, "GPS_rx", UINT) \
24-
X(KWEB_FILE, "Web_file", BOOL) \
26+
X(KLAT_DFL, "defLAT", DOUBLE) \
27+
X(KLON_DFL, "defLON", DOUBLE) \
2528
X(KCOUNT, "KCOUNT", UNKNOWN)

lib/settings/settings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ void printSettings()
308308
log_v("%11s \t%s \t%s", "=======", "=======", "=====");
309309

310310
for (int i = 0; i < KCOUNT; i++) {
311+
if (i == PKEYS::KUSER) continue;
311312
String key = cfg.getKey((CONFKEYS)i);
312313
bool isDefined = cfg.isKey(key);
313314
String defined = isDefined ? "custom " : "default";

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ build_flags =
3333
-D SHELLMINATOR_BUFF_DIM=70
3434
-D SHELLMINATOR_LOGO_COLOR=BLUE
3535
-D COMMANDER_MAX_COMMAND_SIZE=70
36-
-D WCLI_MAX_CMDS=10 # set n+1 of defined commands for CLI
36+
-D WCLI_MAX_CMDS=12 # set n+1 of defined commands for CLI
3737
; -D DISABLE_CLI_TELNET=1 # disable remote access via telnet. It needs CLI
3838
; -D DISABLE_CLI=1 # removed CLI module. Config via Bluetooth only
3939

src/main.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,7 @@ void setup()
144144
splashScreen();
145145
initGpsTask();
146146

147-
#ifdef DEFAULT_LAT
148-
loadMainScreen();
149-
#else
150-
lv_screen_load(searchSatScreen);
151-
#endif
147+
lv_screen_load(searchSatScreen);
152148

153149
#ifndef DISABLE_CLI
154150
initCLI();

0 commit comments

Comments
 (0)