Skip to content

Commit

Permalink
First unfinished draft of PrefabFileExplorerFS - demonstrating new pr…
Browse files Browse the repository at this point in the history
…efab/streaming features of Commander

- generic FS support (tested on Teensy SD library only)
- XYmodem receive
  • Loading branch information
Louis Beaudoin committed Jul 14, 2021
1 parent 87e499e commit 80c50eb
Show file tree
Hide file tree
Showing 3 changed files with 479 additions and 0 deletions.
59 changes: 59 additions & 0 deletions examples/PrefabFileExplorerFS/Commands.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//All commands for 'master'


/*
* This needs to be passed to the commander object so it knows how big the array of commands is, but this happens earlier in setup().
* This has already been forward declared before setup() so the compiler knows it exists
*/
/* Command handler template
bool myFunc(Commander &Cmdr){
//put your command handler code here
return 0;
}
*/


//These are the command handlers, there needs to be one for each command in the command array myCommands[]
//The command array can have multiple commands strings that all call the same function
bool sdStatusHandler(Commander &Cmdr){
if(!myNavigator.isFilesystemOk()){
Cmdr.println("No SD Card");
}else{
Cmdr.println("SD Card detected");
//Cmdr.println(Cmdr.getPayloadString());
}
return 0;
}

CommandCollection masterCollection;

bool sdFileHandler(Commander &Cmdr){
if(!myNavigator.isFilesystemOk()){
Cmdr.println("No SD Card");
return 0;
}
//For the moment - block commands if they are chained
if(Cmdr.hasPayload()){
Cmdr.println("Chained commands are disabled");
//This is blocking when using coolterm ...?
return 0;
}
Cmdr.println("Opening SD Navigator");
//Cmdr.attachCommands(getCommands, numOfGetCmds);
//cmdName = "SD:";
//if(Cmdr.transferTo(fileCommands, numOfFileCommands, cmdName)){
if(Cmdr.transferTo(myNavigator)){
//commander returns true if it is passing back control;
Cmdr.transferBack(masterCollection);
}
return 0;
}

//COMMAND ARRAY ------------------------------------------------------------------------------

const commandList_t masterCommands[] = {
{"status", sdStatusHandler, "Check SD Card status"},
{"SD", sdFileHandler, "Open SD explorer"},
};


69 changes: 69 additions & 0 deletions examples/PrefabFileExplorerFS/PrefabFileExplorerFS.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* Prefab command example
* Prefabs are command sets and command handlers that have been pre defined for specific scenarios
* This demonstrates the FileNavigator prefab that impliments an SDFat file navigation system.
* The prefab is implimented as a sub command and can be invoked with the SD command.
*
* IMPORTANT:
* The prefab includes a file write command that lets you stream text files to a file on the SD card or open a file and sent typed text to the file.
* When this command is activated the command processor will stop working until the ASCII value 4 is received.
* This can be sent from a terminal application such as coolTerm by pressing CONTROL+D
* The Arduino Serial terminal does NOT allow you to send this character and so you cannot terminate the file download when using the Arduino Serial terminal.
*/
#include <Commander.h>

#include <SD.h>
Commander cmd;

#include "PrefabFileNavigatorFS.h"

//FileNavigator myNavigator(SD, "SD:", SerialUSB1);
FileNavigator myNavigator(SD, "SD:");

//String for the top level commander prompt
String prompt = "CMD";

#include "Commands.h"

//SPI Chip select pin
const int cardSelect = BUILTIN_SDCARD;

void setup() {
Serial.begin(115200);
while(!Serial){yield();} //Wait for the serial port to open before running the example
Serial.println("Commander prefab File navigator Example");

SerialUSB1.begin(115200);
SerialUSB1.println("(Debug) FatFs Command Line Interpreter");

myNavigator.setup();

//See if an SD card is inserted
if(!SD.begin(cardSelect)) {
Serial.println("SDCard Init Error");
}else{
myNavigator.setFilesystemOk(true);
Serial.println("SDCard Started");
}

Serial.println("Starting Commander ... type help to see a command list");

//tell the SD prefab what the top layer command list is called and how large it is, prompt);
masterCollection.setList(masterCommands, sizeof(masterCommands), prompt);
myNavigator.setTopLayer(masterCollection);

cmd.endOfLineChar('\r');
cmd.delimiters("= :,\t\\|"); // use defaults except for '/' which interferes with pathnames including root directory
cmd.stripCR(OFF);
cmd.setStreamingMode(1);
cmd.setStreamingMethod(1);
cmd.echo(true);
cmd.begin(&Serial, &Serial, masterCollection.listPtr, masterCollection.numCmds);

cmd.commandPrompt(ON);
cmd.commanderName = prompt;
cmd.printCommandPrompt();
}

void loop() {
cmd.update();
}
Loading

0 comments on commit 80c50eb

Please sign in to comment.