summaryrefslogtreecommitdiff
path: root/src/main.cpp
blob: b8cb0c17b56c1cebe10f976c99be298e8cf79cbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <GxEPD2_BW.h>
#include <Fonts/FreeSansBold9pt7b.h>
#include <Fonts/FreeSans9pt7b.h>
#include <WiFi.h>

#include "calendar.h"
#include "secrets.h"

/*
  see GxEPD2_WS_ESP32_Driver.ino and esp32-waveshare-epd/src/DEV_Config.h

  #define EPD_SCK_PIN  13
  #define EPD_MOSI_PIN 14
  #define EPD_CS_PIN   15
  #define EPD_RST_PIN  26
  #define EPD_DC_PIN   27
  #define EPD_BUSY_PIN 25

  mapping of Waveshare ESP32 Driver Board
  BUSY -> 25, RST -> 26, DC -> 27, CS-> 15, CLK -> 13, DIN -> 14
 */
GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=*/ 15, /*DC=*/ 27, /*RST=*/ 26, /*BUSY=*/ 25));


void board_spi_setup() {
	/* board-specific setup */
	SPI.end();
	SPI.begin(13, 12, 14, 15);
}

void display_setup() {
	display.init();
	board_spi_setup();
}

void draw() {
	display.setRotation(1);
	display.setFont(&FreeSans9pt7b);
	display.setTextColor(GxEPD_BLACK);
	display.firstPage();

	do {
		display.fillScreen(GxEPD_WHITE);
		draw_calendar(display, 30, 30);
	} while(display.nextPage());
}

void wifi_connect() {
	WiFi.begin(wifi_ssid, wifi_psk);
	while (WiFi.status() != WL_CONNECTED) {
		delay(500);
	}
}

void wifi_disconnect() {
	WiFi.disconnect();
	WiFi.mode(WIFI_OFF);
}

void update_time() {
	struct tm timeinfo;
	configTime(0, 0, "de.pool.ntp.org");
	getLocalTime(&timeinfo, 5000);
}

void setup() {
	Serial.begin(115200);

	wifi_connect();
	update_time();
	wifi_disconnect();

	display_setup();
	draw();
	display.powerOff();
}

void loop() {
	delay(1000);
}