-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Makefile for user application | ||
|
||
# Specify this directory relative to the current application. | ||
TOCK_USERLAND_BASE_DIR = ../../../.. | ||
|
||
# Which files to compile. | ||
C_SRCS := $(wildcard *.c) | ||
|
||
APP_HEAP_SIZE := 20000 | ||
|
||
EXTERN_LIBS += $(TOCK_USERLAND_BASE_DIR)/u8g2 | ||
|
||
# Include userland master makefile. Contains rules and flags for actually | ||
# building the application. | ||
include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <screen.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include <timer.h> | ||
|
||
#include <u8g2-tock.h> | ||
#include <u8g2.h> | ||
|
||
#define max(a, b) ((a) > (b) ? (a) : (b)) | ||
|
||
u8g2_t u8g2; | ||
|
||
char buf[20]; | ||
|
||
int main(void) { | ||
|
||
u8g2_tock_init(&u8g2); | ||
|
||
int width = u8g2_GetDisplayWidth(&u8g2); | ||
int height = u8g2_GetDisplayHeight(&u8g2); | ||
|
||
u8g2_SetFont(&u8g2, u8g2_font_timB18_tn); | ||
u8g2_SetFontPosCenter(&u8g2); | ||
|
||
int count = 0; | ||
|
||
while (1) { | ||
u8g2_ClearBuffer(&u8g2); | ||
|
||
snprintf(buf, 20, "%i", count); | ||
|
||
int strwidth = u8g2_GetUTF8Width(&u8g2, buf); | ||
|
||
int y_center = height / 2; | ||
int x = max((width / 2) - (strwidth / 2), 0); | ||
|
||
u8g2_DrawStr(&u8g2, x, y_center, buf); | ||
u8g2_SendBuffer(&u8g2); | ||
|
||
count += 1; | ||
delay_ms(1000); | ||
} | ||
} |