Skip to content

Commit c236b6b

Browse files
[Thread Tutorial] Formatting update
1 parent 75706b2 commit c236b6b

File tree

12 files changed

+121
-136
lines changed

12 files changed

+121
-136
lines changed

examples/tutorials/thread_network/01_sensor_temperature/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ int main(void) {
1212
libtocksync_temperature_read(&current_temperature);
1313

1414
// Convert temperature
15-
int whole_degree = current_temperature / 100;
15+
int whole_degree = current_temperature / 100;
1616
int decimal_degree = current_temperature % 100;
17-
17+
1818
printf("Hello World, the temperature is: %i.%i\r\n", whole_degree, decimal_degree);
19-
19+
2020
return 0;
2121
}

examples/tutorials/thread_network/02_sensor_final/main.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ static int current_temperature = 0;
1010
int main(void) {
1111

1212
// We measure the temperature in the main loop and
13-
//print this value to the console.
13+
// print this value to the console.
1414
while (1) {
1515
// Measure temperature -- returned in the form 2200 => 22C
1616
libtocksync_temperature_read(&current_temperature);
1717

1818
// Convert temperature
19-
int whole_degree = current_temperature / 100;
19+
int whole_degree = current_temperature / 100;
2020
int decimal_degree = current_temperature % 100;
21-
21+
2222
printf("Current temperature: %i.%i\r\n", whole_degree, decimal_degree);
23-
24-
// Delay 1000 ms (1 second).
23+
24+
// Delay 1000 ms (1 second).
2525
libtocksync_alarm_delay_ms(1000);
2626
}
2727
}

examples/tutorials/thread_network/03_openthread/main.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[])
3939

4040
// Set callback to be notified when thread state changes.
4141
otSetStateChangedCallback(instance, stateChangeCallback, instance);
42-
42+
4343
///////////////////////////////////////////////////
44-
// THREAD NETWORK SETUP HERE
44+
// THREAD NETWORK SETUP HERE
4545

4646
// TODO: Configure network.
4747

4848
// TODO: Enable network interface.
49-
49+
5050
// TODO: Start Thread network.
51-
51+
5252
//
5353
////////////////////////////////////////////////////
54-
54+
5555
// OpenThread main loop.
56-
for (;;) {
57-
// Execute any pending OpenThread related work.
56+
for ( ;;) {
57+
// Execute any pending OpenThread related work.
5858
otTaskletsProcess(instance);
5959

6060
// Execute any platform related work (e.g. check
@@ -64,9 +64,8 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[])
6464
// If there is not pending platform or OpenThread
6565
// related work -- yield.
6666
if (!otTaskletsArePending(instance) &&
67-
!openthread_platform_pending_work())
68-
{
69-
yield();
67+
!openthread_platform_pending_work()) {
68+
yield();
7069
}
7170

7271
}
@@ -77,9 +76,9 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[])
7776
// Helper method that configures the OpenThread network dataset
7877
// for the desired tutorial configuration.
7978
// We set the following dataset parameters:
80-
// -- Channel: 26
81-
// -- PanId: 0xabcd
82-
// -- Networkkey: 00112233445566778899aabbccddeeff
79+
// -- Channel: 26
80+
// -- PanId: 0xabcd
81+
// -- Networkkey: 00112233445566778899aabbccddeeff
8382
void setNetworkConfiguration(otInstance* aInstance) {
8483
otOperationalDataset aDataset;
8584

@@ -147,4 +146,3 @@ static void print_ip_addr(otInstance* instance) {
147146
printf("%s\n", addr_string);
148147
}
149148
}
150-

examples/tutorials/thread_network/04_openthread_attach/main.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[])
3939

4040
// Set callback to be notified when thread state changes.
4141
otSetStateChangedCallback(instance, stateChangeCallback, instance);
42-
42+
4343
///////////////////////////////////////////////////
44-
// THREAD NETWORK SETUP HERE
44+
// THREAD NETWORK SETUP HERE
4545

4646
// Configure network.
4747
setNetworkConfiguration(instance);
@@ -63,10 +63,10 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[])
6363

6464
//
6565
////////////////////////////////////////////////////
66-
66+
6767
// OpenThread main loop.
68-
for (;;) {
69-
// Execute any pending OpenThread related work.
68+
for ( ;;) {
69+
// Execute any pending OpenThread related work.
7070
otTaskletsProcess(instance);
7171

7272
// Execute any platform related work (e.g. check
@@ -76,9 +76,8 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[])
7676
// If there is not pending platform or OpenThread
7777
// related work -- yield.
7878
if (!otTaskletsArePending(instance) &&
79-
!openthread_platform_pending_work())
80-
{
81-
yield();
79+
!openthread_platform_pending_work()) {
80+
yield();
8281
}
8382

8483
}
@@ -89,9 +88,9 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[])
8988
// Helper method that configures the OpenThread network dataset
9089
// for the desired tutorial configuration.
9190
// We set the following dataset parameters:
92-
// -- Channel: 26
93-
// -- PanId: 0xabcd
94-
// -- Networkkey: 00112233445566778899aabbccddeeff
91+
// -- Channel: 26
92+
// -- PanId: 0xabcd
93+
// -- Networkkey: 00112233445566778899aabbccddeeff
9594
void setNetworkConfiguration(otInstance* aInstance) {
9695
otOperationalDataset aDataset;
9796

@@ -159,4 +158,3 @@ static void print_ip_addr(otInstance* instance) {
159158
printf("%s\n", addr_string);
160159
}
161160
}
162-

examples/tutorials/thread_network/05_openthread_final/main.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static otUdpSocket sUdpSocket;
2626
void initUdp(otInstance* aInstance);
2727

2828
void handleUdpRecvTemperature(void* aContext, otMessage* aMessage,
29-
const otMessageInfo* aMessageInfo);
29+
const otMessageInfo* aMessageInfo);
3030

3131
void sendUdpTemperature(otInstance* aInstance, uint8_t temperature);
3232

@@ -48,13 +48,13 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[])
4848

4949
// Set callback to be notified when thread state changes.
5050
otSetStateChangedCallback(instance, stateChangeCallback, instance);
51-
51+
5252
///////////////////////////////////////////////////
53-
// THREAD NETWORK SETUP HERE
53+
// THREAD NETWORK SETUP HERE
5454

5555
// Configure network.
5656
setNetworkConfiguration(instance);
57-
57+
5858
// Init UDP interface.
5959
initUdp(instance);
6060

@@ -75,10 +75,10 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[])
7575

7676
//
7777
////////////////////////////////////////////////////
78-
78+
7979
// OpenThread main loop.
80-
for (;;) {
81-
// Execute any pending OpenThread related work.
80+
for ( ;;) {
81+
// Execute any pending OpenThread related work.
8282
otTaskletsProcess(instance);
8383

8484
// Execute any platform related work (e.g. check
@@ -88,9 +88,8 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[])
8888
// If there is not pending platform or OpenThread
8989
// related work -- yield.
9090
if (!otTaskletsArePending(instance) &&
91-
!openthread_platform_pending_work())
92-
{
93-
yield();
91+
!openthread_platform_pending_work()) {
92+
yield();
9493
}
9594

9695
}
@@ -101,9 +100,9 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[])
101100
// Helper method that configures the OpenThread network dataset
102101
// for the desired tutorial configuration.
103102
// We set the following dataset parameters:
104-
// -- Channel: 26
105-
// -- PanId: 0xabcd
106-
// -- Networkkey: 00112233445566778899aabbccddeeff
103+
// -- Channel: 26
104+
// -- PanId: 0xabcd
105+
// -- Networkkey: 00112233445566778899aabbccddeeff
107106
void setNetworkConfiguration(otInstance* aInstance) {
108107
otOperationalDataset aDataset;
109108

@@ -175,7 +174,7 @@ static void print_ip_addr(otInstance* instance) {
175174

176175

177176
void handleUdpRecvTemperature(void* aContext, otMessage* aMessage,
178-
const otMessageInfo* aMessageInfo) {
177+
const otMessageInfo* aMessageInfo) {
179178
OT_UNUSED_VARIABLE(aContext);
180179
OT_UNUSED_VARIABLE(aMessageInfo);
181180
char buf[2];
@@ -231,4 +230,3 @@ void sendUdpTemperature(otInstance* aInstance, uint8_t temperature) {
231230
otMessageFree(message);
232231
}
233232
}
234-

examples/tutorials/thread_network/06_screen/main.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@
33
#include <stdio.h>
44
#include <string.h>
55

6-
int main(void) {
7-
8-
}
6+
int main(void) {}

examples/tutorials/thread_network/07_screen_button/main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
static void button_callback(returncode_t ret,
99
int btn_num,
1010
bool pressed) {
11-
if (ret != RETURNCODE_SUCCESS) return;
11+
if (ret != RETURNCODE_SUCCESS) return;
1212

1313
if (pressed) {
1414
printf("Button %i pressed!\r\n", btn_num);
1515
}
1616
}
1717

1818
int main(void) {
19-
for (int i = 0; i < 4; i++){
19+
for (int i = 0; i < 4; i++) {
2020
libtock_button_notify_on_press(i, button_callback);
2121
}
2222

23-
for(;;) {
23+
for ( ;;) {
2424
yield();
25-
}
25+
}
2626
}

examples/tutorials/thread_network/08_screen_u8g2/main.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
#include <libtock/interface/button.h>
77

8-
#include <u8g2.h>
98
#include <u8g2-tock.h>
9+
#include <u8g2.h>
1010

1111
// Global reference to the u8g2 context:
1212
u8g2_t u8g2;
@@ -21,7 +21,7 @@ uint8_t measured_temperature = 0;
2121
static void button_callback(returncode_t ret,
2222
int btn_num,
2323
bool pressed) {
24-
if (ret != RETURNCODE_SUCCESS) return;
24+
if (ret != RETURNCODE_SUCCESS) return;
2525

2626
if (pressed) {
2727
printf("Button %i pressed!\r\n", btn_num);
@@ -34,38 +34,38 @@ int main(void) {
3434
u8g2_SetFont(&u8g2, u8g2_font_profont12_tr);
3535
u8g2_SetFontPosTop(&u8g2);
3636

37-
for (int i = 0; i < 4; i++){
37+
for (int i = 0; i < 4; i++) {
3838
libtock_button_notify_on_press(i, button_callback);
3939
}
4040

4141
update_screen();
4242

43-
for(;;) {
43+
for ( ;;) {
4444
yield();
45-
}
45+
}
4646
}
4747

4848
static void update_screen(void) {
4949
char temperature_set_point_str[35];
5050
char temperature_global_set_point_str[35];
5151
char temperature_current_measure_str[35];
52-
52+
5353
// Format the buffers to be written.
5454
sprintf(temperature_set_point_str,
55-
"Set Point: %d",
56-
local_temperature_setpoint);
55+
"Set Point: %d",
56+
local_temperature_setpoint);
5757

58-
sprintf(temperature_global_set_point_str,
58+
sprintf(temperature_global_set_point_str,
5959
"Global Set Point: %d",
60-
global_temperature_setpoint);
60+
global_temperature_setpoint);
61+
62+
uint8_t whole_temp = measured_temperature / 100;
63+
uint8_t decimal_temp = measured_temperature % 100;
6164

62-
uint8_t whole_temp = measured_temperature / 100;
63-
uint8_t decimal_temp = measured_temperature % 100;
64-
65-
sprintf(temperature_current_measure_str,
66-
"Measured Temp: %d.%d",
67-
whole_temp,
68-
decimal_temp );
65+
sprintf(temperature_current_measure_str,
66+
"Measured Temp: %d.%d",
67+
whole_temp,
68+
decimal_temp);
6969

7070
// Use u8g2 library to draw each string.
7171
u8g2_ClearBuffer(&u8g2);
@@ -75,4 +75,3 @@ static void update_screen(void) {
7575
u8g2_DrawStr(&u8g2, 0, 50, temperature_current_measure_str);
7676
u8g2_SendBuffer(&u8g2);
7777
}
78-

0 commit comments

Comments
 (0)