Skip to content

Commit

Permalink
store reactions in queues and lists according to their type
Browse files Browse the repository at this point in the history
  • Loading branch information
mairas committed Oct 14, 2018
1 parent a4502d5 commit 0c00638
Show file tree
Hide file tree
Showing 7 changed files with 313 additions and 195 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.pioenvs
.piolibdeps
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
67 changes: 67 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Continuous Integration (CI) is the practice, in software
# engineering, of merging all developer working copies with a shared mainline
# several times a day < https://docs.platformio.org/page/ci/index.html >
#
# Documentation:
#
# * Travis CI Embedded Builds with PlatformIO
# < https://docs.travis-ci.com/user/integration/platformio/ >
#
# * PlatformIO integration with Travis CI
# < https://docs.platformio.org/page/ci/travis.html >
#
# * User Guide for `platformio ci` command
# < https://docs.platformio.org/page/userguide/cmd_ci.html >
#
#
# Please choose one of the following templates (proposed below) and uncomment
# it (remove "# " before each line) or use own configuration according to the
# Travis CI documentation (see above).
#


#
# Template #1: General project. Test it using existing `platformio.ini`.
#

# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# install:
# - pip install -U platformio
# - platformio update
#
# script:
# - platformio run


#
# Template #2: The project is intended to be used as a library with examples.
#

# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# env:
# - PLATFORMIO_CI_SRC=path/to/test/file.c
# - PLATFORMIO_CI_SRC=examples/file.ino
# - PLATFORMIO_CI_SRC=path/to/test/directory
#
# install:
# - pip install -U platformio
# - platformio update
#
# script:
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N
33 changes: 21 additions & 12 deletions examples/torture_test/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ extern "C" {
int timer_ticks[NUM_TIMERS];
int tick_counter = 0;

int out_pin_state = 0;

void setup_timers(Reactduino &app) {
for (int i=0; i<NUM_TIMERS; i++) {
timer_ticks[i] = 0;
Expand All @@ -38,34 +40,41 @@ void setup_timers(Reactduino &app) {
});
}

int out_pin_state = 0;

void setup_io_pins(Reactduino &app) {
pinMode(OUT_PIN, OUTPUT);
app.onRepeat(500, [] () {
app.onRepeat(900, [] () {
out_pin_state = !out_pin_state;
digitalWrite(OUT_PIN, out_pin_state);
});
auto reporter = [] (int pin) {
Serial.printf("Pin %d changed state.\n", pin);
};
app.onPinChange(INPUT_PIN1, std::bind(reporter, INPUT_PIN1));
app.onPinChange(INPUT_PIN2, std::bind(reporter, INPUT_PIN2));
app.onInterrupt(INPUT_PIN1, RISING, std::bind(reporter, INPUT_PIN1));
app.onInterrupt(INPUT_PIN2, FALLING, std::bind(reporter, INPUT_PIN2));
}

void setup_serial(Reactduino &app) {
app.onAvailable(Serial, [&app] () {
static reaction_idx led_off = INVALID_REACTION;
static int reaction_counter = 0;
//static DelayReaction* led_off = nullptr;

Serial.write(Serial.read());
digitalWrite(LED_PIN, HIGH);

Reaction* re = app.free(led_off); // Cancel previous timer (if set)
if (re != nullptr) {
delete re;
}
reaction_counter++;

//if (led_off != nullptr) {
// led_off->free(app);
// led_off = nullptr;
//}

int current = reaction_counter;

led_off = app.onDelay(1000, [] () { digitalWrite(LED_PIN, LOW); });
app.onDelay(1000, [current] () {
if (reaction_counter==current) {
digitalWrite(LED_PIN, LOW);
}
});
});
}

Expand All @@ -78,7 +87,7 @@ void setup_tick(Reactduino &app) {
Reactduino app([] () {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);

setup_timers(app);
setup_io_pins(app);
setup_serial(app);
Expand Down
41 changes: 41 additions & 0 deletions lib/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link them to executable files.

The source code of each library should be placed in separate directories, like
"lib/private_lib/[here are source files]".

For example, see the structure of the following two libraries `Foo` and `Bar`:

|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- readme.txt --> THIS FILE
|
|- platformio.ini
|--src
|- main.c

Then in `src/main.c` you should use:

#include <Foo.h>
#include <Bar.h>

// rest H/C/CPP code

PlatformIO will find your libraries automatically, configure preprocessor's
include paths and build them.

More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html
14 changes: 14 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
Loading

0 comments on commit 0c00638

Please sign in to comment.