Skip to content

Commit 1e5a95a

Browse files
committed
Simplify example.
1 parent 8564a6b commit 1e5a95a

File tree

4 files changed

+10
-22
lines changed

4 files changed

+10
-22
lines changed

examples/Threading_Basics/Thermostat/TemperatureControl_SleepingRoom.inot renamed to examples/Threading_Basics/Thermostat/AirConditionerControl.inot

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
/* Define a data sink named 'temperature' of type 'float'. */
22
SINK(temperature, float, 10);
33

4-
static String sleeping_room_message_prefix(String const & /* msg */)
5-
{
6-
return String("[Sleeping Room] ");
7-
}
8-
94
void setup()
105
{
116
Serial.begin(9600);
12-
Serial.prefix(sleeping_room_message_prefix);
137
while (!Serial) { }
148
}
159

@@ -20,13 +14,13 @@ void loop()
2014
float current_temperature_deg = temperature.pop();
2115

2216
/* Check if the temperature reported by the thermostat is above
23-
* or below 20.0 °C. If the temperature is above 20.0 °C, turn
17+
* or below 26.0 °C. If the temperature is above 26.0 °C, turn
2418
* on the AC.
2519
*/
2620
bool turn_ac_on = false,
2721
turn_ac_off = false;
2822

29-
if (current_temperature_deg > 20.0f)
23+
if (current_temperature_deg > 26.0f)
3024
turn_ac_on = true;
3125
else
3226
turn_ac_off = true;

examples/Threading_Basics/Thermostat/TemperatureControl_LivingRoom.inot renamed to examples/Threading_Basics/Thermostat/HeatingControl.inot

-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
/* Define a data sink named 'temperature' of type 'float'. */
22
SINK(temperature, float, 10);
33

4-
static String living_room_message_prefix(String const & /* msg */)
5-
{
6-
return String("[Living Room] ");
7-
}
8-
94
void setup()
105
{
116
Serial.begin(9600);
12-
Serial.prefix(living_room_message_prefix);
137
while (!Serial) { }
148
}
159

examples/Threading_Basics/Thermostat/TemperatureSensor.inot

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ void setup()
99
void loop()
1010
{
1111
/* Read temperature - since this is just a simulation
12-
* so we take a random value between 15 and 25 °C.
12+
* so we take a random value between 15 and 30 °C.
1313
*/
14-
float const temperature_deg = (rand() % 16) + 10;
14+
float const temperature_deg = (rand() % 16) + 15;
1515
/* Store in temperature source variable. */
1616
temperature.push(temperature_deg);
1717
/* Do only one temperature sensore measurement per second. */

examples/Threading_Basics/Thermostat/Thermostat.ino

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@
1414

1515
void setup()
1616
{
17-
/* Connect the TemperatureSensor thread providing temperature readings
18-
* with the various TemperatureControl_* threads.
17+
/* Connect the temperature sensor thread providing temperature readings
18+
* with the various temperature control unit threads.
1919
*/
20-
TemperatureSensor.temperature.connectTo(TemperatureControl_LivingRoom.temperature);
21-
TemperatureSensor.temperature.connectTo(TemperatureControl_SleepingRoom.temperature);
20+
TemperatureSensor.temperature.connectTo(HeatingControl.temperature);
21+
TemperatureSensor.temperature.connectTo(AirConditionerControl.temperature);
2222
TemperatureSensor.temperature.connectTo(TemperatureSensorReporter.temperature);
2323

2424
/* Start the individual threads for sensing the temperature
2525
* and controlling heating/air-conditioning based on the sensed
2626
* temperature on a per-room basis.
2727
*/
2828
TemperatureSensor.start();
29-
TemperatureControl_LivingRoom.start();
30-
TemperatureControl_SleepingRoom.start();
29+
HeatingControl.start();
30+
AirConditionerControl.start();
3131
TemperatureSensorReporter.start();
3232
}
3333

0 commit comments

Comments
 (0)