Skip to content
Snippets Groups Projects
Commit 6d36deaf authored by David Gauchard's avatar David Gauchard
Browse files

CLI interface: preliminary API and integration are added

parent 13d2b543
No related branches found
No related tags found
1 merge request!17Malaurie's work on UI + CLI interface + AccelStepper interface
cli.cpp 0 → 100644
#include "cli.h"
void Cli::resetNextWord ()
{
_currentWordIndex = -1;
_previousWordLength = 0;
}
const char* Cli::findNextWord ()
{
if (_currentWordIndex >= 0)
// skip current word
while (_currentWordIndex < (int)_currentInput.length())
{
if (_currentInput[_currentWordIndex] == 32)
break;
_currentWordIndex++;
}
else
_currentWordIndex = 0;
size_t _previousWordLength = 0;
// skip spaces
while (_currentWordIndex < (int)_currentInput.length())
{
if (_currentInput[_currentWordIndex] != 32)
break;
_currentWordIndex++;
_previousWordLength++;
}
const char* ret = _currentWordIndex < (int)_currentInput.length()? _currentInput.c_str() + _currentWordIndex: nullptr;
//if (ret)
// Serial.printf("# found new start of word '%s'\n", ret);
return ret;
}
void Cli::copyNextToTemp ()
{
findNextWord();
int start = _currentWordIndex;
findNextWord();
if (start < _currentWordIndex)
_temp = _currentInput.substring(start, _currentWordIndex);
else
_temp.clear();
}
bool Cli::kw (const __FlashStringHelper* keyWord, const char* input)
{
// return true if input matches keyWord
auto len = strlen_P((PGM_P)keyWord);
return len && strncasecmp_P((PGM_P)keyWord, input, len) == 0;
}
bool Cli::kw (const __FlashStringHelper* keyWord)
{
return kw(keyWord, _currentInput.c_str() + _currentWordIndex);
}
void Cli::syntax ()
{
syntax(_currentInput.c_str() + _currentWordIndex);
}
void Cli::syntaxFull ()
{
syntax((const char*)nullptr);
}
void Cli::syntax (const __FlashStringHelper* cmd)
{
syntax((PGM_P)cmd);
}
void Cli::syntax (const char* cmd)
{
if (!cmd || kw(F("AT"), cmd)) Serial.printf("# CLI: AT -> OK\n");
if (!cmd || kw(F("HELP"), cmd)) Serial.printf("# CLI: HELP [CMD]\n");
if (!cmd || kw(F("RAT"), cmd)) Serial.printf("# CLI: RAT [ C | I ] [ <rate> [ <unit>(UM/MM/UH/MH) ] ]\n");
if (!cmd || kw(F("VOL"), cmd)) Serial.printf("# CLI: VOL [ <vol> | <unit>(UL/ML) ]\n");
}
void Cli::loop (Stream& input)
{
while (true)
{
if (!input.available())
return;
int c = input.read();
if (c == 13)
break;
if (c >= 32 && c <= 127)
_currentInput += (char)c;
}
resetNextWord();
if (findNextWord())
{
if (kw(F("AT")))
{
Serial.printf("OK\n");
}
else if (kw(F("HELP")))
{
copyNextToTemp();
if (_temp.length())
syntax(_temp.c_str());
else
syntaxFull();
}
else if (kw(F("RAT")))
{
copyNextToTemp();
}
else if (kw(F("VOL")))
{
}
else
{
Serial.printf("# CLI: invalid command '%s'\n", _currentInput.c_str() + _currentWordIndex);
}
}
if (findNextWord())
Serial.printf("# CLI: garbage at end of line: '%s'\n", _currentInput.c_str() + _currentWordIndex);
resetNextWord();
_currentInput.clear();
}
cli.h 0 → 100644
#pragma once
#include <Arduino.h>
#include "syringe.h"
class Cli
{
private:
Syringe& syringe;
String _currentInput;
String _temp;
int _currentWordIndex;
int _previousWordLength;
void resetNextWord ();
const char* findNextWord ();
void copyNextToTemp ();
bool kw (const __FlashStringHelper* keyWord, const char* input);
bool kw (const __FlashStringHelper* keyWord);
void syntax ();
void syntaxFull ();
void syntax (const __FlashStringHelper* cmd);
void syntax (const char* cmd);
public:
Cli (Syringe& syringe, int bufferLen = 32): syringe(syringe)
{
_currentInput.reserve(bufferLen);
_temp.reserve(bufferLen);
resetNextWord();
}
void loop (Stream& input);
};
......@@ -3,19 +3,16 @@
pwd=$(pwd)
cd ${ESP8266ARDUINO}/tests/host
make FORCE32=0 ssl
make -j 10 FORCE32=0 D=1 USERCFLAGS="-I ${ARDUINOLIB}/emuAsync/replacement" ULIBDIRS=${ARDUINOLIB}/emuAsync:${ARDUINOLIB}/ESPUI:${ARDUINOLIB}/ArduinoJson:${ARDUINOLIB}/arduinoWebSockets ${pwd}/../pousseseringue-arduino
make -j 10 FORCE32=0 USERCFLAGS="-I ${ARDUINOLIB}/emuAsync/replacement" ULIBDIRS=${ARDUINOLIB}/emuAsync:${ARDUINOLIB}/ESPUI:${ARDUINOLIB}/ArduinoJson:${ARDUINOLIB}/arduinoWebSockets ${pwd}/../pousseseringue-arduino
(./bin/pousseseringue-arduino/pousseseringue-arduino -b "$@" 2>&1 | grep -v '^http-server loop: conn=') & pid=$!
trap "kill ${pid}" EXIT INT
(
true '----------------------------------------'
true '----------- starting firefox -----------'
true '----------------------------------------'
sleep 5
firefox -new-window http://localhost:9080
) &
sleep 1
true '----------------------------------------'
true '----------- starting firefox -----------'
true '----------------------------------------'
sleep 4
firefox -new-window http://localhost:9080
./bin/pousseseringue-arduino/pousseseringue-arduino "$@"
while true; do
true '^C to quit'
read junk
done
stty sane
......@@ -56,6 +56,7 @@
#endif // !CORE_MOCK
#include "Debouncer.h" // local, debouncer, short counter, long detector
#include "syringe.h"
#include "cli.h"
#include "common.h"
......@@ -93,6 +94,7 @@ int rpming = 0; // -1, 0 or +1
// single syringe global instance
Syringe syringe;
Cli console(syringe);
const char* oledMode ()
{
......@@ -320,7 +322,9 @@ void loop()
}
stepper.run();
#endif // !CORE_MOCK
console.loop(Serial);
webLoop();
dnsServer.processNextRequest(); // AP redirection
dnsServer.processNextRequest(); // access-point redirection
}
......@@ -7,4 +7,5 @@
#include "web.cpp"
#include "syringe.cpp"
#include "motor.cpp"
#include "cli.cpp"
#endif // !CORE_MOCK
......@@ -13,7 +13,7 @@ float Syringe::volumeToDistance(float volume)
return distance;
}
void Syringe::configureSyringe(Syringe_configuration_t config)
void Syringe::configureSyringe(const Syringe_configuration_t& config)
{
this->current_configuration = config;
this->piston_surface = M_PI * pow(config.diameter,2) / 4.;
......
......@@ -22,7 +22,7 @@ private:
public:
// Configuration
void configureSyringe(Syringe_configuration_t config);
void configureSyringe(const Syringe_configuration_t& config);
void setInitialContent(float initial_volume);
// Actions
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment