-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPicoCommandLine_Parser.ino
More file actions
308 lines (290 loc) · 8.71 KB
/
Copy pathPicoCommandLine_Parser.ino
File metadata and controls
308 lines (290 loc) · 8.71 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/**************************************************/
/*! \file PicoCommandLine_Parser.ino
\brief Raspberry pico command line interface (CLI)
\defgroup command line parser
\author Achim Jenne 18.10.2025
\sa ... */
/**************************************************/
/**************************************************/
/*! \brief Automatic generated enum- commands
\defgroup token_parser
\sa datetime_t */
/**************************************************/
enum eCmdSt {eNoToken=0,
eAUTO, eCD, eCLS, eCONFIG, eCOPY, eDATE, eDEL, eDIR,
eECHO, eFORMAT, eHELP, eMD, ePATH, eRD, eREN, eTEMP,
eTIME, eTYPE, eVER, eVOL};
/**************************************************/
#include "SD-OS_Pico.h"
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
//#include <arduino.h>
//#include <string.h>
//#include "pico/stdlib.h"
#include "I2C_RTC.h"
#include <SPI.h>
#include <SD.h>
#include <FatFS.h>
/**************************************************/
static DS3231 RTC;
File myFile;
char sLogFn[40]= "start.txt";
char sPath[ILINE]={"/"};
volatile bool bAuto = false;
bool bRTC = false;
time_t tiUx= 1760968836; // SW- Release;
struct timeval tiV;
/**************************************************/
/**************************************************/
void setup() {
// put your setup code here, to run once:
char sLine[ILINE];
Serial.begin(115200);
// wait on Serial to be available on Leonardo
while (!Serial){
delay(10);
}
delay(10);
pinMode(PIN_LED, OUTPUT);
analogReadResolution(12);
analogReadTemp(3.3f);
Serial.print(S_CLS);
Serial.println(BOARD_NAME);
Serial.print(F("CPU- Frequency: "));
Serial.print(F_CPU/1000000);
Serial.println(F(" MHz"));
Serial.print(F("Pico SDK Version: "));
Serial.println(PICO_SDK_VERSION_STRING);
Serial.print(F("Arduino Version: "));
Serial.println(ARDUINO_PICO_VERSION_STR);
#if defined MAKERSPI1
// check available SD_Card
gpio_init(PIN_SS);
gpio_set_dir(PIN_SS, false);
gpio_disable_pulls(PIN_SS);
gpio_put(PIN_SS, 0);
uint8_t bSD1= 0;
while ((bSD1= gpio_get(PIN_SS)) == 0) {
delay(100);
Serial.print(F("No Card ("));
Serial.print(PIN_SS);
Serial.print(F(":"));
Serial.print(bSD1, DEC);
Serial.print(F(")\e[14D"));
}
gpio_deinit(PIN_SS);
delay(10);
#endif
// if available, then init SPI-Interface
#if defined(MAKERSPI)
SDSPI.setMISO(PIN_MISO);
SDSPI.setMOSI(PIN_MOSI);
SDSPI.setSCK(PIN_SCK);
SDSPI.beginTransaction(SPISettings(SD_SCK_MHZ(SDSPD), MSBFIRST, SPI_MODE0));
#else
#endif
Serial.print(F("Init SD-Card ... "));
bool bInitSD = false;
// bInitSD = SD.begin( RP_CLK_GPIO, RP_CMD_GPIO, RP_DAT0_GPIO);
bInitSD = SD.begin( SDCRD);
// Serial.println(SDCRD);
// Serial.println(RP_CLK_GPIO);
// Serial.println(RP_CMD_GPIO);
// Serial.println(RP_DAT0_GPIO);
if (bInitSD) {
Serial.println(F("OK"));
} else {
Serial.println(F("failed"));
}
SD.end();
Serial.print(F("CPU- Temperature: "));
Serial.println(analogReadTemp(3.3f));
//*** external RTC Modul ***
if (RTC.begin()) {
bRTC = true;
if (!RTC.isRunning()) {
Serial.println(F("RTC starting"));
RTC.startClock();
}
if (RTC.getHourMode() != CLOCK_H24) {
Serial.println(F("RTC set to 24h Format"));
RTC.setHourMode(CLOCK_H24);
}
/* load internal RTC from external RTC */
tiV.tv_sec = dateTime2Unix(RTC.getYear(),RTC.getMonth(),RTC.getDay(),RTC.getHours(),RTC.getMinutes(),RTC.getSeconds()) ;
tiV.tv_usec = 0;
settimeofday(&tiV, nullptr);
Serial.print(F("RTC- Temperature: "));
Serial.println(RTC.getTemp());
Serial.print(F("RTC- Date&Time: "));
Serial.printf("%2.2d.%2.2d.%4.4d %2.2d:%2.2d:%2.2d\r\n",
RTC.getDay(), RTC.getMonth(), RTC.getYear(),
RTC.getHours(), RTC.getMinutes(), RTC.getSeconds());
} else {
tiV.tv_sec = tiUx;
tiV.tv_usec = 0;
settimeofday(&tiV, nullptr);
}
time(&tiUx);
Serial.print(F("Pico internal RTC: "));
strftime(sLine, sizeof(sLine), "%0d.%0m.20%0y %0H:%0M:%0S", localtime(&tiUx));
Serial.print(sLine);
strftime(sLine, sizeof(sLine), " %0d %B 20%0y (%A) %0H:%0M:%0S", localtime(&tiUx));
Serial.println(sLine);
Serial.print(sPath);
Serial.print(F(">"));
}
/**************************************************/
/**
@brief Interactive VT100- command input
@param [in, out] psLine Buffer to read and edit
@param [in] inChar serial input byte to interpret
*/
bool editLine(char *psLine, char inChar)
{
static char sBack[ILINE];
static char sTemp[ILINE];
static unsigned char iIndx=0;
static uint8_t iESC= 0;
static bool bEditMode= false;
if (inChar == '\r') // CR key
{
for (unsigned int i=1; i<=(strlen(psLine)-iIndx); i++) {
Serial.print(F("\e[C"));
}
iIndx= 0;
iESC= 0;
strcpy(&sBack[0], psLine);
bEditMode= true;
} else {
bEditMode= false;
if (inChar == '\n') // new line
{
Serial.write(inChar);
} else
if ((inChar == '[') && (iESC ==1)) {
iESC = 2;
} else
if (((inChar == 'A')||(inChar == 'B')) && (iESC ==2)) // cursor up-down
{
for (char i=0; i<iIndx; i++) {
Serial.print(F("\b \b"));
}
strcpy(&sTemp[0], psLine);
strcpy(psLine, &sBack[0]);
strcpy(&sBack[0], &sTemp[0]);
Serial.print(F("\e[0G"));
Serial.print(sPath);
Serial.print(F(">"));
Serial.print(psLine);
iIndx= strlen(psLine);
iESC= 0;
} else
if ((inChar == 'D') && (iESC ==2)) // key left
{
if (iIndx >=1) {
Serial.print(F("\e[D"));
iIndx--;
}
iESC= 0;
} else
if ((inChar == 'C') && (iESC ==2)) // key right
{
if (strlen(psLine) > iIndx) {
Serial.print(F("\e[C"));
iIndx++;
}
iESC= 0;
} else
if (inChar == C_BS) // backpace key
{
if (strlen(psLine) >= 1) {
Serial.print(F("\b"));
int iLen= strlen(psLine);
if (iLen> iIndx) {
for (int iLoop=iIndx; iLoop <= iLen; iLoop++) {
*(psLine+iLoop-1) = *(psLine+iLoop);
}
iIndx--;
Serial.print(psLine + iIndx);
Serial.print(F(" \e["));
Serial.print(iLen - iIndx);
Serial.print(F("D"));
} else {
Serial.print(F(" \b"));
iIndx--;
*(psLine+iIndx) = 0x00;
}
}
} else
if (inChar == C_ESC) // escape key
{
if (iESC >= 1) {
for (char i=0; i<iIndx; i++) {
Serial.print(F("\b \b"));
}
*psLine= 0;
iIndx= 0;
bEditMode = false;
iESC= 0;
} else {
iESC= 1;
}
} else
if (inChar == 0x7f) {
int iLen= strlen(psLine);
if (iLen> iIndx) {
for (int iLoop=iIndx+1; iLoop <= iLen; iLoop++){
*(psLine+iLoop-1) = *(psLine+iLoop);
}
Serial.print(psLine + iIndx);
Serial.print(F(" \e["));
Serial.print(iLen - iIndx);
Serial.print(F("D"));
}
} else {
if (iIndx < ILINE) {
Serial.write(inChar);
int iLen= strlen(psLine);
if (iLen> iIndx) {
for (int iLoop=iLen; iLoop >= iIndx; iLoop--){
*(psLine+iLoop+1) = *(psLine+iLoop);
}
*(psLine+iIndx) = inChar;
Serial.print(psLine + iIndx + 1);
Serial.print(F("\e["));
Serial.print(iIndx+3+strlen(sPath));
Serial.print(F("G"));
iIndx++;
} else {
*(psLine+iIndx) = inChar;
iIndx++;
*(psLine+iIndx) = 0x00;
}
}
}
}
return (bEditMode);
}
/**************************************************/
void loop() {
bool bEM;
char inChar;
static char sLine[ILINE];
char *psLine= &sLine[0];
// put your main code here, to run repeatedly:
if (Serial.available()) {
inChar = (char)Serial.read();
if (bEM= editLine(psLine, inChar)) {
/************************************************************/
// if command
psLine = strupr(psLine);
int iRet= fnSDOS_Parser(psLine);
*psLine= 0;
Serial.print(F("\r\n"));
Serial.print(sPath);
Serial.print(F(">"));
} /* end if */
} /* end if */
} /* end main loop */