Skip to content

Commit

Permalink
Use minishell library instead of cmdproc/editline.
Browse files Browse the repository at this point in the history
  • Loading branch information
bertrik committed Dec 6, 2024
1 parent 8c4984c commit 001cd17
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 172 deletions.
47 changes: 0 additions & 47 deletions cmdproc.cpp

This file was deleted.

25 changes: 0 additions & 25 deletions cmdproc.h

This file was deleted.

58 changes: 0 additions & 58 deletions editline.cpp

This file was deleted.

6 changes: 0 additions & 6 deletions editline.h

This file was deleted.

1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ upload_speed = 1000000
lib_deps = fastled/[email protected]
tzapu/WifiManager@^0.16.0
bblanchon/ArduinoJson@^6.20.1
https://github.com/bertrik/minishell


48 changes: 12 additions & 36 deletions stofananas.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
#include <ESP8266HTTPClient.h>
#include <FastLED.h>
#include <ArduinoJson.h>

#include "cmdproc.h"
#include "editline.h"
#include <MiniShell.h>

#include <Arduino.h>

Expand Down Expand Up @@ -41,6 +39,7 @@ static savedata_t savedata;

static WiFiManager wifiManager;
static WiFiClient wifiClient;
static MiniShell shell(&Serial);
static char espid[64];

static CRGB leds1[1];
Expand Down Expand Up @@ -130,7 +129,7 @@ static int do_get(int argc, char *argv[])
printf("fetch_pm failed!\n");
return -1;
}
return CMD_OK;
return 0;
}

static int do_config(int argc, char *argv[])
Expand All @@ -154,7 +153,7 @@ static int do_config(int argc, char *argv[])

printf("config.rgb = %s\n", savedata.hasRgbLed ? "true" : "false");
printf("config.magic = %08X\n", savedata.magic);
return CMD_OK;
return 0;
}

static CRGB interpolate(float pm, const pmlevel_t table[])
Expand Down Expand Up @@ -182,7 +181,7 @@ static int do_pm(int argc, char *argv[])
float pm = atoi(argv[1]);
set_led(interpolate(pm, pmlevels));

return CMD_OK;
return 0;
}

static bool geolocate(float &latitude, float &longitude, float &accuracy)
Expand Down Expand Up @@ -253,13 +252,13 @@ static int do_geolocate(int argc, char *argv[])

printf("Latitude = %f, Longitude = %f, Accuracy = %f\n", latitude, longitude, accuracy);
printf("https://google.com/maps/place/%f,%f\n", latitude, longitude);
return CMD_OK;
return 0;
}

static int do_reboot(int argc, char *argv[])
{
ESP.restart();
return CMD_OK;
return 0;
}

static int do_error(int argc, char *argv[])
Expand All @@ -268,7 +267,7 @@ static int do_error(int argc, char *argv[])
num_fetch_failures = atoi(argv[1]);
}
printf("fetch failures:%d\n", num_fetch_failures);
return CMD_OK;
return 0;
}

static int do_led(int argc, char *argv[])
Expand All @@ -279,7 +278,7 @@ static int do_led(int argc, char *argv[])
int rgb = strtoul(argv[1], NULL, 16);
set_led(rgb);

return CMD_OK;
return 0;
}

const cmd_t commands[] = {
Expand All @@ -297,7 +296,7 @@ const cmd_t commands[] = {
static int do_help(int argc, char *argv[])
{
show_help(commands);
return CMD_OK;
return 0;
}

static void animate(void)
Expand Down Expand Up @@ -329,7 +328,6 @@ void setup(void)

Serial.begin(115200);
printf("\nESP-STOFANANAS\n");
EditInit(line, sizeof(line));

// init config
EEPROM.begin(sizeof(savedata));
Expand Down Expand Up @@ -392,29 +390,7 @@ void loop(void)
FastLED.showColor(color, flash ? 200 : 255);
}

// parse command line
while (Serial.available()) {
char c = Serial.read();
bool haveLine = EditLine(c, &c);
Serial.write(c);
if (haveLine) {
int result = cmd_process(commands, line);
switch (result) {
case CMD_OK:
printf("OK\n");
break;
case CMD_NO_CMD:
break;
case CMD_UNKNOWN:
printf("Unknown command, available commands:\n");
show_help(commands);
break;
default:
printf("%d\n", result);
break;
}
printf(">");
}
}
// command line processing
shell.process(">", commands);
}

0 comments on commit 001cd17

Please sign in to comment.