Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update default template #106

Merged
merged 3 commits into from
Jul 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
436 changes: 82 additions & 354 deletions examples/ConfigurableFirmata/ConfigurableFirmata.ino

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/AccelStepperFirmata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ void AccelStepperFirmata::encode32BitSignedInteger(long value, byte pdata[])
/*==============================================================================
* LOOP()
*============================================================================*/
void AccelStepperFirmata::update()
void AccelStepperFirmata::report(bool elapsed)
{
bool stepsLeft;

Expand Down
2 changes: 1 addition & 1 deletion src/AccelStepperFirmata.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class AccelStepperFirmata: public FirmataFeature
long decode28BitUnsignedInteger(byte arg1, byte arg2, byte arg3, byte arg4);
long decode32BitSignedInteger(byte arg1, byte arg2, byte arg3, byte arg4, byte arg5);
void encode32BitSignedInteger(long value, byte pdata[]);
void update();
void report(bool elapsed) override;
void reset();
private:
AccelStepper *stepper[MAX_ACCELSTEPPERS];
Expand Down
7 changes: 6 additions & 1 deletion src/AnalogInputFirmata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,13 @@ void AnalogInputFirmata::reset()
analogInputsToReport = 0;
}

void AnalogInputFirmata::report()
void AnalogInputFirmata::report(bool elapsed)
{
if (!elapsed)
{
return;
}

byte pin, analogPin;
/* ANALOGREAD - do all analogReads() at the configured sampling interval */
for (pin = 0; pin < TOTAL_PINS; pin++) {
Expand Down
3 changes: 1 addition & 2 deletions src/AnalogInputFirmata.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class AnalogInputFirmata: public FirmataFeature
boolean handlePinMode(byte pin, int mode);
boolean handleSysex(byte command, byte argc, byte* argv);
void reset();
void report();

void report(bool elapsed) override;
private:
/* analog inputs */
int analogInputsToReport; // bitwise array to store pin reporting
Expand Down
2 changes: 1 addition & 1 deletion src/DigitalInputFirmata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void DigitalInputFirmata::outputPort(byte portNumber, byte portValue, byte force
/* -----------------------------------------------------------------------------
* check all the active digital inputs for change of state, then add any events
* to the Serial output queue using Serial.print() */
void DigitalInputFirmata::report(void)
void DigitalInputFirmata::report(bool elapsed)
{
/* Using non-looping code allows constants to be given to readPort().
* The compiler will apply substantial optimizations if the inputs
Expand Down
2 changes: 1 addition & 1 deletion src/DigitalInputFirmata.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DigitalInputFirmata: public FirmataFeature
public:
DigitalInputFirmata();
void reportDigital(byte port, int value);
void report(void);
void report(bool elapsed);
void handleCapability(byte pin);
boolean handleSysex(byte command, byte argc, byte* argv);
boolean handlePinMode(byte pin, int mode);
Expand Down
7 changes: 7 additions & 0 deletions src/FirmataExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,10 @@ void FirmataExt::reset()
features[i]->reset();
}
}

void FirmataExt::report(bool elapsed)
{
for (byte i = 0; i < numFeatures; i++) {
features[i]->report(elapsed);
}
}
2 changes: 1 addition & 1 deletion src/FirmataExt.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FirmataExt: public FirmataFeature
boolean handleSysex(byte command, byte argc, byte* argv);
void addFeature(FirmataFeature &capability);
void reset();

void report(bool elapsed) override;
private:
FirmataFeature *features[MAX_FEATURES];
byte numFeatures;
Expand Down
12 changes: 12 additions & 0 deletions src/FirmataFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ class FirmataFeature
virtual boolean handlePinMode(byte pin, int mode) = 0;
virtual boolean handleSysex(byte command, byte argc, byte* argv) = 0;
virtual void reset() = 0;

/// <summary>
/// Regularly called by main thread
/// </summary>
/// <param name="elapsed">True if the default reporting time has elapsed, false otherwise. Components wishing to report status in
/// a regular interval should not do anything if this is false.</param>
virtual void report(bool elapsed)
{
// Empty by default
}
virtual ~FirmataFeature()
= default;
};

#endif
6 changes: 5 additions & 1 deletion src/FirmataReporting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ boolean FirmataReporting::handleSysex(byte command, byte argc, byte* argv)
boolean FirmataReporting::elapsed()
{
currentMillis = millis();
if (currentMillis - previousMillis > samplingInterval) {
if (currentMillis - previousMillis > samplingInterval)
{
previousMillis += samplingInterval;
if (currentMillis - previousMillis > samplingInterval)
{
previousMillis = currentMillis - samplingInterval;
}
return true;
}
return false;
Expand All @@ -64,3 +67,4 @@ void FirmataReporting::reset()
previousMillis = millis();
samplingInterval = 19;
}

4 changes: 3 additions & 1 deletion src/FirmataReporting.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ class FirmataReporting: public FirmataFeature
void handleCapability(byte pin); //empty method
boolean handlePinMode(byte pin, int mode); //empty method
boolean handleSysex(byte command, byte argc, byte* argv);
boolean elapsed();
void reset();

boolean elapsed();
private:

/* timer variables */
unsigned long currentMillis; // store the current value from millis()
unsigned long previousMillis; // for comparison with currentMillis
Expand Down
2 changes: 1 addition & 1 deletion src/FirmataScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ void FirmataScheduler::reportTask(byte id, firmata_task *task, boolean error)
Firmata.write(END_SYSEX);
};

void FirmataScheduler::runTasks()
void FirmataScheduler::report(bool elapsed)
{
if (tasks) {
long now = millis();
Expand Down
2 changes: 1 addition & 1 deletion src/FirmataScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class FirmataScheduler: public FirmataFeature
void handleCapability(byte pin); //empty method
boolean handlePinMode(byte pin, int mode); //empty method
boolean handleSysex(byte command, byte argc, byte* argv);
void runTasks();
void report(bool elapsed);
void reset();
void createTask(byte id, int len);
void deleteTask(byte id);
Expand Down
4 changes: 2 additions & 2 deletions src/I2CFirmata.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class I2CFirmata: public FirmataFeature
void handleCapability(byte pin);
boolean handleSysex(byte command, byte argc, byte* argv);
void reset();
void report();
void report(bool elapsed) override;

private:
/* for i2c read continuous more */
Expand Down Expand Up @@ -321,7 +321,7 @@ void I2CFirmata::reset()
}
}

void I2CFirmata::report()
void I2CFirmata::report(bool elapsed)
{
// report i2c data for all device with read continuous mode enabled
if (queryIndex > -1) {
Expand Down
2 changes: 1 addition & 1 deletion src/SerialFirmata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ boolean SerialFirmata::handleSysex(byte command, byte argc, byte *argv)
return false;
}

void SerialFirmata::update()
void SerialFirmata::report(bool elapsed)
{
checkSerial();
}
Expand Down
2 changes: 1 addition & 1 deletion src/SerialFirmata.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class SerialFirmata: public FirmataFeature
boolean handlePinMode(byte pin, int mode);
void handleCapability(byte pin);
boolean handleSysex(byte command, byte argc, byte* argv);
void update();
void report(bool elapsed) override;
void reset();
void checkSerial();

Expand Down