-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaocmd_boot.ino
174 lines (136 loc) · 4.77 KB
/
aocmd_boot.ino
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
162
163
164
165
166
167
168
169
170
171
172
173
// aocmd_boot.ino - testing boot.cmd, stored persistently on the ESP
/*****************************************************************************
* Copyright 2024 by ams OSRAM AG *
* All rights are reserved. *
* *
* IMPORTANT - PLEASE READ CAREFULLY BEFORE COPYING, INSTALLING OR USING *
* THE SOFTWARE. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
*****************************************************************************/
#include <aospi.h> // aospi_init()
#include <aoosp.h> // aoosp_init()
#include <aocmd.h> // generic include for whole aocmd lib
/*
DESCRIPTION
This demo implements an application that prints a message every x ms.
It adds a command ("wait") to set and get x. This command can then be
stored in boot.cmd, to configure this app persistently. The default
value of x is 30000 (30 seconds).
HARDWARE
The demo runs on the OSP32 board, no demo board needs to be attached.
In Arduino select board "ESP32S3 Dev Module".
BEHAVIOR
No commands are given to change the LEDs (in the below example).
OUTPUT
Welcome to aocmd_boot.ino
spi: init
osp: init
cmd: init
No 'boot.cmd' file available to execute
Type 'help' for help
Try 'wait 5000'
>>
message (wait=30000 ms)
message (wait=30000 ms)
message (wait=30000 ms)
>> file record
001>> echo New wait
002>> wait 10000
003>>
file: 25 bytes written
>>
>> board reboot
... software triggered reboot ...
Welcome to aocmd_boot.ino
spi: init
osp: init
cmd: init
only power-on runs 'boot.cmd'
Type 'help' for help
Try 'wait 5000'
>>
... pressed RST button ...
Welcome to aocmd_boot.ino
spi: init
osp: init
cmd: init
Running 'boot.cmd'
>> echo New wait
New wait
>> wait 10000
>>
Type 'help' for help
Try 'wait 5000'
>>
message (wait=10000 ms)
message (wait=10000 ms)
message (wait=10000 ms)
*/
// --- command "wait" --------------------------------------------------------
// This command allow setting and getting a delay.
// The statistics variables for the "stat" command
static uint32_t cmdwait_ms = 30*1000;
// The command handler for the "wait" command
static void cmdwait_main(int argc, char * argv[]) {
if( argc==1 ) {
Serial.printf("wait: %lu ms\n", cmdwait_ms);
return;
}
if( argc==2 ) {
int val;
bool ok= aocmd_cint_parse_dec(argv[1],&val) ;
if( !ok || val<0) { Serial.printf("ERROR: wait: value must be non-negative decimal '%s'\n",argv[1]); return; }
cmdwait_ms= val;
return;
}
Serial.printf("ERROR: wait: unknown argument\n");
}
// The long help for the "wait" command
static const char cmdwait_longhelp[] =
"SYNTAX: wait\n"
"- shows the wait time (ms)\n"
"SYNTAX: wait <time>\n"
"- sets the wait time (ms)\n"
;
// Registers "wait" command
static void cmdwait_register() {
aocmd_cint_register(cmdwait_main, "wait", "controls the wait time between a periodic message", cmdwait_longhelp);
}
// ---------------------------------------------------------------------------
static uint32_t last;
void setup() {
Serial.begin(115200);
Serial.printf("\n\nWelcome to aocmd_boot.ino\n");
aospi_init(); // used by command "osp" in aocmd
aoosp_init(); // used by command "osp" in aocmd
aocmd_init();
aocmd_register(); // register all commands in aocmd lib
cmdwait_register(); // register extra command 'wait'
Serial.printf("\n");
// Exec file boot.cmd on POR
aocmd_file_bootcmd_exec_on_por();
Serial.print( "Type 'help' for help\n" );
Serial.print( "Try 'wait 5000'\n" );
aocmd_cint_prompt();
last = millis();
}
void loop() {
// Processing of incoming commands
aocmd_cint_pollserial();
// Main application
if( millis()-last > cmdwait_ms ) {
Serial.printf("message (wait=%lu ms)\n",cmdwait_ms );
last = millis();
}
}