EEPROM file storage, and argparsing that actually works

This commit is contained in:
John Stäck 2019-06-24 11:56:57 +02:00
parent 3b2f0fa4cf
commit 829c08c031
5 changed files with 4385 additions and 492 deletions

View file

@ -12,15 +12,16 @@
#include "GL/gl3w.h"
#include "examples/imgui_impl_sdl.h"
#include "examples/imgui_impl_opengl3.h"
#include "EEPROM.h"
#include <Arduino.h>
#include "argparse.hpp"
#include "args.hxx"
// Forward declarations
static void SimQuit(void);
static int SimInit(void);
static int SimRun(void);
static int SimRun(std::string eepromFile, bool eepromWrite, bool factoryReset);
static void SimLoop(std::function<bool()>, std::function<void()>);
@ -31,6 +32,8 @@ SimWire Wire;
SimSerial Serial;
SimSerial Serial3; //Midi
SimUsbMidi usbMIDI;
EEPROMClass EEPROM;
static const int scale = 3;
@ -510,12 +513,20 @@ static int SimRun(std::string eepromFile, bool eepromWrite, bool factoryReset)
{
if( 0 != SimInit() ) { return 1; }
// Dummy to always force full reset of EEPROM, to circumvent bug in NuEVI.ino
digitalInputs[mPin] = 0;
digitalInputs[ePin] = 0;
//Set up EEPROM file storage
if(eepromFile.length()>0) {
EEPROM.setStorage(eepromFile.c_str(), eepromWrite);
}
// Holding down buttons if doing a factory reset on startup
if(factoryReset) {
digitalInputs[mPin] = 0;
digitalInputs[ePin] = 0;
}
setup();
//Let it go, let it go, not resetting any more
digitalInputs[mPin] = 1;
digitalInputs[ePin] = 1;
@ -585,6 +596,8 @@ static void SimQuit()
{
printf("Leaving Sim, see you later!\n");
EEPROM.closeStorage();
if( window != NULL ) {
SDL_DestroyWindow( window );
// SDL_FreeSurface( surface );
@ -597,25 +610,15 @@ static void SimQuit()
int main(int argc, const char** argv)
{
ArgumentParser parser;
parser.addArgument("--eeprom-file", 1);
parser.addArgument("--eeprom-write");
parser.addArgument("--factory-reset");
parser.parse(argc, argv);
std::string eepromFile;
bool eepromWrite;
bool factoryReset;
args::ArgumentParser parser("This is a test program.", "This goes after the options.");
eepromFile = parser.retrieve<std::string>("eeprom-file");
eepromWrite = parser.exists("eeprom-write");
factoryReset = parser.exists("factory-reset");
args::ValueFlag<std::string> eepromFile(parser, "eeprom-write", "File to use for EEPROM data", {'e', "eeprom-file"});
args::Flag eepromWrite(parser, "eeprom-write", "Write EEPROM changes to file", {'w', "eeprom-write"});
args::Flag factoryReset(parser, "factory-reset", "Trigger factory reset", {'r', "factory-reset"});
printf("%d: %s\n",eepromWrite, eepromFile.c_str());
return 0;
parser.ParseCLI(argc, argv);
return SimRun(eepromFile, eepromWrite, factoryReset);
return SimRun(args::get(eepromFile), args::get(eepromWrite), args::get(factoryReset));
}