Skip to content

Commit

Permalink
add count demo
Browse files Browse the repository at this point in the history
  • Loading branch information
bradjc committed Feb 8, 2024
1 parent 85c2bb2 commit 6c16272
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
15 changes: 15 additions & 0 deletions examples/tests/u8g2-demos/count/Makefile
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
45 changes: 45 additions & 0 deletions examples/tests/u8g2-demos/count/main.c
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);
}
}

0 comments on commit 6c16272

Please sign in to comment.