summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/calendar.cpp53
-rw-r--r--src/draw_qrcode.cpp42
-rw-r--r--src/main.cpp18
3 files changed, 60 insertions, 53 deletions
diff --git a/src/calendar.cpp b/src/calendar.cpp
index d743718..04325b0 100644
--- a/src/calendar.cpp
+++ b/src/calendar.cpp
@@ -1,17 +1,18 @@
#include <GxEPD2_BW.h>
-#include <Fonts/FreeSansBold12pt7b.h>
-#include <Fonts/FreeSansBold9pt7b.h>
-#include <Fonts/FreeSans9pt7b.h>
+#include <U8g2_for_Adafruit_GFX.h>
#include <ctime>
-#define CELL_SPACING 10
+#define CELL_SPACING 8
+
+extern GxEPD2_GFX_BASE_CLASS &get_display();
+extern U8G2_FOR_ADAFRUIT_GFX u8g2Fonts;
static const char *week_days[] {
"Mo", "Di", "Mi", "Do", "Fr", "Sa", "So",
};
static const char *months[] {
- "Januar", "Februar", "Maerz", "April", "Mai", "Juni", "Juli",
+ "Januar", "Februar", "März", "April", "Mai", "Juni", "Juli",
"August", "September", "Oktober", "November", "Dezember",
};
@@ -55,7 +56,6 @@ static int days_in_month(int month, int year) {
}
/*
- * @display where to draw on
* @x0 absolute initial X coord
* @y0 absolute initial Y coord
* @w0 width of a cell
@@ -65,24 +65,22 @@ static int days_in_month(int month, int year) {
* @text text to draw
* @highlight whether text should be highlighted
*/
-static void draw_cell_content(GxEPD2_GFX_BASE_CLASS &display, int16_t x0, int16_t y0, uint16_t w0, uint16_t h0, uint8_t xoff, uint8_t yoff, String &text, bool highlight = false) {
- int16_t x, y;
- uint16_t w, h;
-
- display.getTextBounds(text, 0, 0, &x, &y, &w, &h);
+static void draw_cell_content(int16_t x0, int16_t y0, uint16_t w0, uint16_t h0, uint8_t xoff, uint8_t yoff, String &text, bool highlight = false) {
+ uint16_t w = u8g2Fonts.getUTF8Width(text.c_str());
+ uint16_t h = 10; /* assume 10px high font */
int16_t w_diff = w0 - w;
- int x2 = x0 + xoff * w0 + w_diff/2 - x;
- int y2 = y0 + yoff * h0 - y;
+ int x2 = x0 + xoff * w0 + w_diff/2;
+ int y2 = y0 + yoff * h0;
- display.setCursor(x2, y2);
- display.print(text);
+ u8g2Fonts.setCursor(x2, y2);
+ u8g2Fonts.print(text);
if (highlight) {
- display.drawCircle(x2 + x + w/2, y2 - h/2, (w0 - CELL_SPACING) / 2, GxEPD_BLACK);
+ get_display().drawCircle(x2 + w/2, y2 - h/2 - 1, w0/2 - 3, GxEPD_BLACK);
}
}
-void draw_calendar(GxEPD2_GFX_BASE_CLASS &display, int16_t x0, int16_t y0) {
+void draw_calendar(int16_t x0, int16_t y0) {
struct tm now;
if (!getLocalTime(&now)) {
return;
@@ -97,32 +95,33 @@ void draw_calendar(GxEPD2_GFX_BASE_CLASS &display, int16_t x0, int16_t y0) {
day_of_1st = (day_of_1st - 1 + 7) % 7;
/* determine sizes */
- int16_t x, y;
- uint16_t w, h, cell_width, cell_height;
- display.getTextBounds(week_days[0], 0, 0, &x, &y, &w, &h);
+ u8g2Fonts.setFont(u8g2_font_helvB10_tf);
+ uint16_t cell_width, cell_height;
+ int w = u8g2Fonts.getUTF8Width(week_days[0]);
+ int h = 10; /* assume 10px high font */
cell_width = w + CELL_SPACING;
- cell_height = h + CELL_SPACING;
+ cell_height = h + CELL_SPACING + 5;
/* draw title with month and year */
- display.setFont(&FreeSansBold12pt7b);
+ u8g2Fonts.setFont(u8g2_font_helvB14_tf);
String title_text = String(months[now.tm_mon]) + " " + String(1900 + now.tm_year);
- draw_cell_content(display, x0, y0, cell_width * 7, h, 0, 0, title_text);
+ draw_cell_content(x0, y0, cell_width * 7, h, 0, 0, title_text);
y0 += h + 2 * CELL_SPACING;
/* draw table header with week days */
- display.setFont(&FreeSansBold9pt7b);
+ u8g2Fonts.setFont(u8g2_font_helvB10_tf);
for (int i=0; i<7; i++) {
String week_day = String(week_days[i]);
- draw_cell_content(display, x0, y0, cell_width, cell_height, i, 0, week_day);
+ draw_cell_content(x0, y0, cell_width, cell_height, i, 0, week_day);
}
/* draw days */
- display.setFont(&FreeSans9pt7b);
+ u8g2Fonts.setFont(u8g2_font_helvR10_tf);
int8_t wday = day_of_1st;
uint8_t row = 1;
for (uint8_t day = 1; day <= n_days; day++) {
String day_str = String(day);
- draw_cell_content(display, x0, y0, cell_width, cell_height, wday, row, day_str, day == now.tm_mday);
+ draw_cell_content(x0, y0, cell_width, cell_height, wday, row, day_str, day == now.tm_mday);
wday++;
if (wday > 6) {
diff --git a/src/draw_qrcode.cpp b/src/draw_qrcode.cpp
index 594e47c..1d2edc8 100644
--- a/src/draw_qrcode.cpp
+++ b/src/draw_qrcode.cpp
@@ -1,10 +1,12 @@
#include <GxEPD2_BW.h>
-#include <Fonts/FreeSansBold9pt7b.h>
-#include <Fonts/FreeSans9pt7b.h>
+#include <U8g2_for_Adafruit_GFX.h>
#include <qrcode.h>
#define BLOCK_WIDTH 4
+extern GxEPD2_GFX_BASE_CLASS &get_display();
+extern U8G2_FOR_ADAFRUIT_GFX u8g2Fonts;
+
static uint16_t sizes[] = {
17, 32, 53, 78, 106, 134, 154, 192, 230,
};
@@ -28,7 +30,7 @@ static int version_for_len(int length) {
return -1;
}
-int draw_qrcode(GxEPD2_GFX_BASE_CLASS &display, int16_t x, int16_t y, String &text) {
+int draw_qrcode(int16_t x, int16_t y, String &text) {
QRCode qrcode;
int version = version_for_len(text.length());
if (version <= 0)
@@ -46,13 +48,13 @@ int draw_qrcode(GxEPD2_GFX_BASE_CLASS &display, int16_t x, int16_t y, String &te
if (!qrcode_getModule(&qrcode, row, col)) {
continue;
}
- display.fillRect(x + BLOCK_WIDTH * row, y + BLOCK_WIDTH * col, BLOCK_WIDTH, BLOCK_WIDTH, GxEPD_BLACK);
+ get_display().fillRect(x + BLOCK_WIDTH * row, y + BLOCK_WIDTH * col, BLOCK_WIDTH, BLOCK_WIDTH, GxEPD_BLACK);
}
}
return qrcode.size * BLOCK_WIDTH + 8 * BLOCK_WIDTH;
}
-void draw_qrcode_wlan(GxEPD2_GFX_BASE_CLASS &display, int16_t x, int16_t y, const char *ssid, const char *psk) {
+void draw_qrcode_wlan(int16_t x, int16_t y, const char *ssid, const char *psk) {
String ssid_str = String(ssid);
String psk_str = String(psk);
escape_strings(ssid_str);
@@ -67,28 +69,28 @@ void draw_qrcode_wlan(GxEPD2_GFX_BASE_CLASS &display, int16_t x, int16_t y, cons
wifi_str += ";P:" + psk_str + ";T:WPA;;";
}
- int size = draw_qrcode(display, x, y, wifi_str);
+ int size = draw_qrcode(x, y, wifi_str);
/* draw text */
- int16_t x2, y2;
uint16_t w, h;
+ h = 10; /* assume 10px height */
String text_ssid = String("SSID:");
String text_psk = String("PSK:");
- display.setFont(&FreeSansBold9pt7b);
- display.getTextBounds(text_ssid, 0, 0, &x2, &y2, &w, &h);
- display.setCursor(x, y + size + h);
- display.print(text_ssid);
- display.setFont(&FreeSans9pt7b);
- display.setCursor(x + w, y + size + h);
- display.print(" " + ssid_str);
+ u8g2Fonts.setFont(u8g2_font_helvB10_tf);
+ w = u8g2Fonts.getUTF8Width(text_ssid.c_str());
+ u8g2Fonts.setCursor(x, y + size + h);
+ u8g2Fonts.print(text_ssid);
+ u8g2Fonts.setFont(u8g2_font_helvR10_tf);
+ u8g2Fonts.setCursor(x + w, y + size + h);
+ u8g2Fonts.print(" " + ssid_str);
if (psk_str.length() > 0) {
- display.setFont(&FreeSansBold9pt7b);
- display.setCursor(x, y + size + 2 * h + 10);
- display.print(text_psk);
- display.setFont(&FreeSans9pt7b);
- display.setCursor(x + w, y + size + 2 * h + 10);
- display.print(" " + psk_str);
+ u8g2Fonts.setFont(u8g2_font_helvB10_tf);
+ u8g2Fonts.setCursor(x, y + size + 2 * h + 10);
+ u8g2Fonts.print(text_psk);
+ u8g2Fonts.setFont(u8g2_font_helvR10_tf);
+ u8g2Fonts.setCursor(x + w, y + size + 2 * h + 10);
+ u8g2Fonts.print(" " + psk_str);
}
}
diff --git a/src/main.cpp b/src/main.cpp
index 70f2559..ee7435a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,6 +1,5 @@
#include <GxEPD2_BW.h>
-#include <Fonts/FreeSansBold9pt7b.h>
-#include <Fonts/FreeSans9pt7b.h>
+#include <U8g2_for_Adafruit_GFX.h>
#include <WiFi.h>
#include "calendar.h"
@@ -22,6 +21,12 @@
*/
GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=*/ 15, /*DC=*/ 27, /*RST=*/ 26, /*BUSY=*/ 25));
+U8G2_FOR_ADAFRUIT_GFX u8g2Fonts;
+
+extern GxEPD2_GFX_BASE_CLASS &get_display() {
+ return display;
+}
+
void board_spi_setup() {
/* board-specific setup */
@@ -32,18 +37,19 @@ void board_spi_setup() {
void display_setup() {
display.init();
board_spi_setup();
+ u8g2Fonts.begin(display);
}
void draw() {
display.setRotation(1);
- display.setFont(&FreeSans9pt7b);
- display.setTextColor(GxEPD_BLACK);
+ u8g2Fonts.setBackgroundColor(GxEPD_WHITE);
+ u8g2Fonts.setForegroundColor(GxEPD_BLACK);
display.firstPage();
do {
display.fillScreen(GxEPD_WHITE);
- draw_calendar(display, 30, 30);
- draw_qrcode_wlan(display, 30, 200, wifi_ssid, wifi_psk);
+ draw_calendar(30, 30);
+ draw_qrcode_wlan(30, 200, wifi_ssid, wifi_psk);
} while(display.nextPage());
}