Skip to content

Commit 759fba5

Browse files
[Thread Tutorial] Update Screen application
- Remove IPC - Add more substeps
1 parent d03ed9b commit 759fba5

File tree

11 files changed

+156
-0
lines changed

11 files changed

+156
-0
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
198 KB
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Makefile for user application
2+
3+
# Specify this directory relative to the current application.
4+
TOCK_USERLAND_BASE_DIR = ../../../../
5+
6+
# Which files to compile.
7+
C_SRCS := $(wildcard *.c)
8+
9+
PACKAGE_NAME = screen
10+
11+
# Include userland master makefile. Contains rules and flags for actually
12+
# building the application.
13+
include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <stdbool.h>
2+
#include <stdint.h>
3+
#include <stdio.h>
4+
#include <string.h>
5+
6+
#include <libtock/interface/button.h>
7+
8+
uint8_t global_temperature_setpoint = 0;
9+
uint8_t local_temperature_setpoint = 22;
10+
uint8_t measured_temperature = 0;
11+
12+
13+
static void button_callback(returncode_t ret,
14+
int btn_num,
15+
bool pressed) {
16+
17+
if (pressed) {
18+
printf("Button %i pressed!\r\n", btn_num);
19+
}
20+
}
21+
22+
int main(void) {
23+
for (int i = 0; i < 4; i++){
24+
libtock_button_notify_on_press(i, button_callback);
25+
}
26+
27+
update_screen();
28+
29+
for(;;) {
30+
yield();
31+
}
32+
}
33+
34+
static void update_screen(void) {
35+
char temperature_set_point_str[35];
36+
char temperature_global_set_point_str[35];
37+
char temperature_current_measure_str[35];
38+
39+
// Format the buffers to be written.
40+
sprintf(temperature_set_point_str,
41+
"Set Point: %d",
42+
local_temperature_setpoint);
43+
44+
sprintf(temperature_global_set_point_str,
45+
"Global Set Point: %d",
46+
global_temperature_setpoint);
47+
48+
sprintf(temperature_current_measure_str,
49+
"Measured Temp: %d",
50+
measured_temperature);
51+
52+
// Use u8g2 library to draw each string.
53+
u8g2_ClearBuffer(&u8g2);
54+
u8g2_SetDrawColor(&u8g2, 1);
55+
u8g2_DrawStr(&u8g2, 0, 0, temperature_set_point_str);
56+
u8g2_DrawStr(&u8g2, 0, 25, temperature_global_set_point_str);
57+
u8g2_DrawStr(&u8g2, 0, 50, temperature_current_measure_str);
58+
u8g2_SendBuffer(&u8g2);
59+
}
60+
198 KB
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Makefile for user application
2+
3+
# Specify this directory relative to the current application.
4+
TOCK_USERLAND_BASE_DIR = ../../../../
5+
6+
# Which files to compile.
7+
C_SRCS := $(wildcard *.c)
8+
9+
PACKAGE_NAME = screen
10+
11+
# Include userland master makefile. Contains rules and flags for actually
12+
# building the application.
13+
include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk

0 commit comments

Comments
 (0)