forked from hpsaturn/esp32-wifi-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
87 lines (75 loc) · 3.03 KB
/
main.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
/*********************************************************************
This sample file is part of the esp32-wifi-cli:
Copyright (c) 2022, @hpsaturn, Antonio Vanegas
https://hpsaturn.com, All rights reserved.
https://github.com/hpsaturn/esp32-wifi-cli
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include <Arduino.h>
#include <M5Atom.h>
#include <ESP32WifiCLI.hpp>
/*********************************************************************
* Optional callback.
********************************************************************/
class mESP32WifiCLICallbacks : public ESP32WifiCLICallbacks {
void onWifiStatus(bool isConnected) {
M5.dis.setBrightness(5); // set brightness to 50%
if (isConnected)
M5.dis.fillpix(0x00ff00); // set LED to green
else
M5.dis.fillpix(0xffff00); // set LED to yellow
}
// Callback for extend the help menu.
void onHelpShow() {
Serial.println("\r\nCustom commands:\r\n");
Serial.println("blink <times> <millis>\tLED blink x times each x millis");
Serial.println("echo \"message\"\t\tEcho the input message");
Serial.println("reboot\t\t\tperform a soft ESP32 reboot");
}
void onNewWifi(String ssid, String passw) {
}
};
/*********************************************************************
* User defined commands. Example: suspend, blink, reboot, etc.
********************************************************************/
void blink(String opts) {
maschinendeck::Pair<String, String> operands = maschinendeck::SerialTerminal::ParseCommand(opts);
int times = operands.first().toInt();
int miliseconds = operands.second().toInt();
for (int i = 0; i < times; i++) {
M5.dis.fillpix(0xaaff00); // set LED to green
delay(miliseconds);
M5.dis.fillpix(0xff0000); // set LED to green
delay(miliseconds);
}
}
void echo(String opts) {
String echo = maschinendeck::SerialTerminal::ParseArgument(opts);
Serial.println("\r\nmsg: "+echo);
}
void reboot(String opts){
ESP.restart();
}
void setup() {
M5.begin(true,false,true); //Init Atom(Initialize serial port, LED)
M5.dis.fillpix(0xffffff); //Light LED with the specified RGB color.
Serial.flush();
delay(1000);
wcli.setCallback(new mESP32WifiCLICallbacks());
wcli.begin();
// User custom commands:
wcli.term->add("blink", &blink, "\tLED blink x times each x millis");
wcli.term->add("echo", &echo, "\tEcho the input message");
wcli.term->add("reboot", &reboot, "\tperform a ESP32 reboot");
}
void loop() {
wcli.loop();
}