Skip to content

Refactor out breaking examples into main branch. #51

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

Merged
merged 3 commits into from
Nov 11, 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
11 changes: 11 additions & 0 deletions examples/Breaks_1/Breaks_1.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <Arduino_Threads.h>

void setup()
{
Thread.start();
}

void loop()
{

}
Empty file.
23 changes: 23 additions & 0 deletions examples/Breaks_1/Thread.inot
Original file line number Diff line number Diff line change
@@ -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);
}
11 changes: 11 additions & 0 deletions examples/Breaks_2/Breaks_2.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <Arduino_Threads.h>

void setup()
{
Thread.start();
}

void loop()
{

}
Empty file.
21 changes: 21 additions & 0 deletions examples/Breaks_2/Thread.inot
Original file line number Diff line number Diff line change
@@ -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()
{

}
11 changes: 11 additions & 0 deletions examples/Breaks_3/Breaks_3.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <Arduino_Threads.h>

void setup()
{
Thread.start();
}

void loop()
{

}
Empty file.
15 changes: 15 additions & 0 deletions examples/Breaks_3/Thread.inot
Original file line number Diff line number Diff line change
@@ -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()
{

}
11 changes: 11 additions & 0 deletions examples/Breaks_4/Breaks_4.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <Arduino_Threads.h>

void setup()
{
Thread.start();
}

void loop()
{

}
Empty file.
47 changes: 47 additions & 0 deletions examples/Breaks_4/Thread.inot
Original file line number Diff line number Diff line change
@@ -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(&reg_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);
}
11 changes: 11 additions & 0 deletions examples/Breaks_5/Breaks_5.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <Arduino_Threads.h>

void setup()
{
Thread.start();
}

void loop()
{

}
Empty file.
19 changes: 19 additions & 0 deletions examples/Breaks_5/Thread.inot
Original file line number Diff line number Diff line change
@@ -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. */
}