Skip to content

Commit

Permalink
fix(xod-arduino, xod-tabtest, stdlib): do not rely on NUM_ANALOG_INPU…
Browse files Browse the repository at this point in the history
…TS being defined
  • Loading branch information
evgenykochetkov committed Oct 18, 2018
1 parent 422b63c commit 645f32a
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 2 deletions.
8 changes: 8 additions & 0 deletions packages/xod-arduino/platform/runtime.cpp
Expand Up @@ -206,6 +206,14 @@ bool isValidDigitalPort(uint8_t port) {
#endif
}

bool isValidAnalogPort(uint8_t port) {
#ifdef NUM_ANALOG_INPUTS
return port >= A0 && port < A0 + NUM_ANALOG_INPUTS;
#else
return port >= A0;
#endif
}

} // namespace xod

//----------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions packages/xod-tabtest/cpp/Arduino.h
Expand Up @@ -11,6 +11,8 @@
void setup();
void loop();

#define A0 14

uint32_t millis();
void delay(uint32_t);

Expand Down
4 changes: 2 additions & 2 deletions workspace/__lib__/xod/gpio/analog-read/patch.cpp
Expand Up @@ -8,8 +8,8 @@ void evaluate(Context ctx) {
return;

const uint8_t port = getValue<input_PORT>(ctx);
bool err = (port < A0 || port > A0 + NUM_ANALOG_INPUTS - 1);
if (err) {

if (!isValidAnalogPort(port)) {
emitValue<output_ERR>(ctx, 1);
return;
}
Expand Down
8 changes: 8 additions & 0 deletions workspace/blink/__fixtures__/arduino.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions workspace/count-with-feedback-loops/__fixtures__/arduino.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions workspace/lcd-time/__fixtures__/arduino.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions workspace/two-button-switch/__fixtures__/arduino.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 645f32a

Please sign in to comment.