Skip to content

Commit 33fb1ce

Browse files
authored
Cleaning up/adding missing comments within examples. (#58)
This is done in order to put clearer into context what actually is happening.
1 parent 7d503b2 commit 33fb1ce

File tree

19 files changed

+89
-18
lines changed

19 files changed

+89
-18
lines changed

Diff for: examples/Breaks_6/Breaks_6.ino

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/* This example is in fact expected to break, since we try
2+
* to access a thread-private variable.
3+
*/
4+
15
#include <Arduino_Threads.h>
26

37
void setup()

Diff for: examples/Threading_Basics/Shared_Counter/Consumer.inot

+6
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,11 @@ void setup()
66

77
void loop()
88
{
9+
/* If a value is available for reading within the internal
10+
* queue then the value is removed from the queue and made
11+
* available to the calling function. Should no data be
12+
* available, then this thread is suspended until new data
13+
* is available for reading.
14+
*/
915
Serial.println(counter);
1016
}

Diff for: examples/Threading_Basics/Shared_Counter/Producer.inot

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ void setup()
66
void loop()
77
{
88
static int i = 0;
9+
/* Every 100 ms a new value is inserted into the shared variable
10+
* 'counter'. Internally this is stored within a queue in a FIFO
11+
* (First-In/First-Out) manner.
12+
*/
913
counter = i;
1014
i++;
1115
delay(100);
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
/* Define a shared variable named 'counter' of type 'int'. */
12
SHARED(counter, int);

Diff for: examples/Threading_Basics/Shared_Counter/Shared_Counter.ino

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/* This example demonstrates data exchange between
2+
* threads using a shared counter variable defined
3+
* within 'SharedVariables.h'.
4+
*/
5+
16
void setup()
27
{
38
Producer.start();

Diff for: examples/Threading_Basics/Source_Sink_Counter/Consumer.inot

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* Define a data sink named 'counter' of type 'int' with a internal queue size of 10. */
12
SINK(counter, int, 10);
23

34
void setup()

Diff for: examples/Threading_Basics/Source_Sink_Counter/Producer.inot

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* Define a data source named 'counter' of type 'int'. */
12
SOURCE(counter, int);
23

34
void setup()

Diff for: examples/Threading_Basics/Source_Sink_Counter/Source_Sink_Counter.ino

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
/*
2-
* This examples demonstrates the SOURCE/SINK abstraction.
3-
* Each thread may have any number of SOURCES and SINKS that can be connected
4-
* together using the "connectTo" method.
1+
/* This examples demonstrates the SOURCE/SINK abstraction. Each thread
2+
* may have any number of SOURCES and SINKS that can be connected
3+
* together using the 'connectTo' method.
54
*/
65

76
void setup()
+4-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
2-
/*
3-
* An 'bool' SINK with a size of '0'. This kind of SINK has no buffer so the reading thread
4-
* will block until the writing thread has written something, or vice versa.
5-
*/
1+
/* Define a data sink named 'led' of type 'bool' with a internal queue size of 1. */
62
SINK(led, bool);
73

84
void setup()
@@ -12,9 +8,9 @@ void setup()
128

139
void loop()
1410
{
15-
/* Read a 'bool' from the SINK and discard it. Since there is basically no delay in the loop
16-
* this call will surely block until something comes from the connected SOURCE. In this case
17-
* the pace is dictated by the SOURCE that sends data every 100 ms.
11+
/* Read a 'bool' value from the SINK and discard it. Since there is no delay in the loop
12+
* this call will block until new data is inserted from the connected SOURCE. This means
13+
* that the pace is dictated by the SOURCE that sends data every 100 ms.
1814
*/
1915
digitalWrite(LED_BUILTIN, led);
2016
}

Diff for: examples/Threading_Basics/Source_Sink_LED/Source_Sink_LED.ino

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
/*
2-
* This examples demonstrates the SOURCE/SINK abstraction.
3-
* Each thread may have any number of SOURCES and SINKS that can be connected
4-
* together using the "connectTo" method.
1+
/* This examples demonstrates the SOURCE/SINK abstraction. Each thread
2+
* may have any number of SOURCES and SINKS that can be connected
3+
* together using the 'connectTo' method.
54
*/
65

76
void setup()

Diff for: examples/Threading_Basics/Source_Sink_LED/Source_Thread.inot

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* The output SOURCE, it sends 'bool' values. */
1+
/* Define a data source named 'led' of type 'bool'. */
22
SOURCE(led, bool);
33

44
void setup()

Diff for: examples/Threadsafe_IO/SPI/SPI.ino

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/* This example demonstrates how multiple threads can communicate
2+
* with a single SPI client device using the BusDevice abstraction
3+
* for SPI. In a similar way multiple threads can interface
4+
* with different client devices on the same SPI bus.
5+
*/
6+
17
/**************************************************************************************
28
* INCLUDE
39
**************************************************************************************/

Diff for: examples/Threadsafe_IO/SPI_BusIO/SPI_BusIO.ino

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/* This example demonstrates how multiple threads can communicate
2+
* with a single SPI client device using the BusDevice abstraction
3+
* for SPI. In a similar way multiple threads can interface
4+
* with different client devices on the same SPI bus.
5+
*
6+
* This example uses Adafruit_BusIO style read(), write(),
7+
* write_then_read() APIs.
8+
*/
9+
110
/**************************************************************************************
211
* INCLUDE
312
**************************************************************************************/

Diff for: examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Serial_GlobalPrefixSuffix.ino

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/* This example demonstrates how every Serial message can be prefixed
2+
* as well as suffixed by a user-configurable message. In this example
3+
* this functionality is used for appending the current timestamp and
4+
* prepending a line feed. Other uses might be to prepend the thread
5+
* from which a given serial message is originating.
6+
*/
7+
18
/**************************************************************************************
29
* INCLUDE
310
**************************************************************************************/

Diff for: examples/Threadsafe_IO/Serial_ProtocolWrapping/Serial_ProtocolWrapping.ino

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/* This example demonstrates how every Serial message can be prefixed
2+
* as well as suffixed by a user-configurable message. In this example
3+
* this functionality is used for prepending the right header for a
4+
* pseudo NMEA-encoded (think GPS) message as well as for calculating
5+
* and appending the checksum at the end.
6+
*/
7+
18
/**************************************************************************************
29
* INCLUDE
310
**************************************************************************************/

Diff for: examples/Threadsafe_IO/Serial_Reader/Serial_Reader.ino

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/* This example demonstrates how multiple threads can subscribe to
2+
* reading from the same physical Serial interface. Incoming data
3+
* is copied into per-thread receive buffers so that no thread
4+
* can "steal" data from another thread by reading it first.
5+
*/
6+
17
/**************************************************************************************
28
* INCLUDE
39
**************************************************************************************/

Diff for: examples/Threadsafe_IO/Serial_Writer/Serial_Writer.ino

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/* This example demonstrates how multiple threads can write to
2+
* the same physical Serial interface without interfering with
3+
* one another.
4+
*/
5+
16
/**************************************************************************************
27
* INCLUDE
38
**************************************************************************************/

Diff for: examples/Threadsafe_IO/Wire/Wire.ino

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/* This example demonstrates how multiple threads can communicate
2+
* with a single Wire client device using the BusDevice abstraction
3+
* for Wire. In a similar way multiple threads can interface
4+
* with different client devices on the same Wire bus.
5+
*/
6+
17
/**************************************************************************************
28
* INCLUDE
39
**************************************************************************************/

Diff for: examples/Threadsafe_IO/Wire_BusIO/Wire_BusIO.ino

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
/**************************************************************************************
1+
/* This example demonstrates how multiple threads can communicate
2+
* with a single Wire client device using the BusDevice abstraction
3+
* for Wire. In a similar way multiple threads can interface
4+
* with different client devices on the same Wire bus.
5+
*
6+
* This example uses Adafruit_BusIO style read(), write(),
7+
* write_then_read() APIs.
8+
*/
9+
10+
/**************************************************************************************
211
* INCLUDE
312
**************************************************************************************/
413

0 commit comments

Comments
 (0)