diff --git a/examples/Breaks_1/Breaks_1.ino b/examples/Breaks_1/Breaks_1.ino new file mode 100644 index 0000000..fbb7922 --- /dev/null +++ b/examples/Breaks_1/Breaks_1.ino @@ -0,0 +1,11 @@ +#include <Arduino_Threads.h> + +void setup() +{ + Thread.start(); +} + +void loop() +{ + +} \ No newline at end of file diff --git a/examples/Breaks_1/SharedVariables.h b/examples/Breaks_1/SharedVariables.h new file mode 100644 index 0000000..e69de29 diff --git a/examples/Breaks_1/Thread.inot b/examples/Breaks_1/Thread.inot new file mode 100644 index 0000000..1f88db4 --- /dev/null +++ b/examples/Breaks_1/Thread.inot @@ -0,0 +1,23 @@ +/* This fails to compile because it doesn't look like a + * declaration and a definitio but rather like an attempt + * to overload myFunc with the same signature (again) + * resulting in a compile error. + */ + +int myFunc(int const a, int const b); + +void setup() +{ + +} + +void loop() +{ + static int c = 0; + c += myFunc(0,c); +} + +int myFunc(int const a, int const b) +{ + return (a + b); +} \ No newline at end of file diff --git a/examples/Breaks_2/Breaks_2.ino b/examples/Breaks_2/Breaks_2.ino new file mode 100644 index 0000000..fbb7922 --- /dev/null +++ b/examples/Breaks_2/Breaks_2.ino @@ -0,0 +1,11 @@ +#include <Arduino_Threads.h> + +void setup() +{ + Thread.start(); +} + +void loop() +{ + +} \ No newline at end of file diff --git a/examples/Breaks_2/SharedVariables.h b/examples/Breaks_2/SharedVariables.h new file mode 100644 index 0000000..e69de29 diff --git a/examples/Breaks_2/Thread.inot b/examples/Breaks_2/Thread.inot new file mode 100644 index 0000000..0eff097 --- /dev/null +++ b/examples/Breaks_2/Thread.inot @@ -0,0 +1,21 @@ +/* This fails to compile because myEventHandler has the + * function signature of 'void Thread::myEventHandler(void)' + * and is a member function of 'class Thread' while + * attachInterrupt expects a function with the signature + * 'void myEventHandler(void)' + */ + +void myEventHandler() +{ + /* Do something. */ +} + +void setup() +{ + attachInterrupt(digitalPinToInterrupt(2), myEventHandler, CHANGE); +} + +void loop() +{ + +} diff --git a/examples/Breaks_3/Breaks_3.ino b/examples/Breaks_3/Breaks_3.ino new file mode 100644 index 0000000..fbb7922 --- /dev/null +++ b/examples/Breaks_3/Breaks_3.ino @@ -0,0 +1,11 @@ +#include <Arduino_Threads.h> + +void setup() +{ + Thread.start(); +} + +void loop() +{ + +} \ No newline at end of file diff --git a/examples/Breaks_3/SharedVariables.h b/examples/Breaks_3/SharedVariables.h new file mode 100644 index 0000000..e69de29 diff --git a/examples/Breaks_3/Thread.inot b/examples/Breaks_3/Thread.inot new file mode 100644 index 0000000..6b2b2b4 --- /dev/null +++ b/examples/Breaks_3/Thread.inot @@ -0,0 +1,15 @@ +/* This fails to compile because in-class-initialisation of + * a static member variable is forbidden. + */ + +static int my_global_variable = 0; + +void setup() +{ + +} + +void loop() +{ + +} diff --git a/examples/Breaks_4/Breaks_4.ino b/examples/Breaks_4/Breaks_4.ino new file mode 100644 index 0000000..fbb7922 --- /dev/null +++ b/examples/Breaks_4/Breaks_4.ino @@ -0,0 +1,11 @@ +#include <Arduino_Threads.h> + +void setup() +{ + Thread.start(); +} + +void loop() +{ + +} \ No newline at end of file diff --git a/examples/Breaks_4/SharedVariables.h b/examples/Breaks_4/SharedVariables.h new file mode 100644 index 0000000..e69de29 diff --git a/examples/Breaks_4/Thread.inot b/examples/Breaks_4/Thread.inot new file mode 100644 index 0000000..4ba81e9 --- /dev/null +++ b/examples/Breaks_4/Thread.inot @@ -0,0 +1,47 @@ +/* Breaks for all kind of stuff ... + */ + +/************************************************************************************** + * CONSTANTS + **************************************************************************************/ + +static byte constexpr LSM6DSOX_ADDRESS = 0x6A; +static byte constexpr LSM6DSOX_WHO_AM_I_REG = 0x0F; + +/************************************************************************************** + * GLOBAL VARIABLES + **************************************************************************************/ + +BusDevice lsm6dsox(Wire, LSM6DSOX_ADDRESS); + +/************************************************************************************** + * FUNCTIONS + **************************************************************************************/ + +byte lsm6dsox_read_reg(byte reg_addr) +{ + byte read_buf = 0; + lsm6dsox.wire().write_then_read(®_addr, 1, &read_buf, 1); + return read_buf; +} + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() +{ + Serial.begin(9600); +} + +void loop() +{ + /* Sleep between 5 and 500 ms */ + rtos::ThisThread::sleep_for(rtos::Kernel::Clock::duration_u32(random(5,500))); + /* Try to read some data from the LSM6DSOX. */ + byte const who_am_i = lsm6dsox_read_reg(LSM6DSOX_WHO_AM_I_REG); + /* Print thread id and chip id value to serial. */ + char msg[64] = {0}; + snprintf(msg, sizeof(msg), "%s: LSM6DSOX[WHO_AM_I] = 0x%X", rtos::ThisThread::get_name(), who_am_i); + Serial.println(msg); +} diff --git a/examples/Breaks_5/Breaks_5.ino b/examples/Breaks_5/Breaks_5.ino new file mode 100644 index 0000000..fbb7922 --- /dev/null +++ b/examples/Breaks_5/Breaks_5.ino @@ -0,0 +1,11 @@ +#include <Arduino_Threads.h> + +void setup() +{ + Thread.start(); +} + +void loop() +{ + +} \ No newline at end of file diff --git a/examples/Breaks_5/SharedVariables.h b/examples/Breaks_5/SharedVariables.h new file mode 100644 index 0000000..e69de29 diff --git a/examples/Breaks_5/Thread.inot b/examples/Breaks_5/Thread.inot new file mode 100644 index 0000000..c430b03 --- /dev/null +++ b/examples/Breaks_5/Thread.inot @@ -0,0 +1,19 @@ +/* This fails to compile because myEventHandler is declared + * after setup/loop and currently there's not automatic prototype + * generation as done for the ino file. + */ + +void setup() +{ + attachInterrupt(digitalPinToInterrupt(2), myEventHandler, CHANGE); +} + +void loop() +{ + +} + +void myEventHandler() +{ + /* Do something. */ +}