summaryrefslogtreecommitdiff
path: root/src/main.cpp
blob: 0284ff7eb498e4f091f8c98dcc7de814df8b763b (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <GxEPD2_BW.h>
#include <U8g2_for_Adafruit_GFX.h>
#include <WiFi.h>

#include "calendar.h"
#include "draw_qrcode.h"
#include "weather.h"
#include "secrets.h"

#define USE_DHCP 0

#define EPULSE_BOARD

#if defined(WAVESHARE_BOARD)
  #define SCK  13
  #define MOSI 14
  #define CS   15
  #define RST  26
  #define DC   27
  #define BUSY 25
#elif defined(EPULSE_BOARD)
  #define SCK  18
  #define MISO 19
  #define MOSI 23
  #define CS   5
  #define RST  2
  #define DC   0
  #define BUSY 4
#endif

/*
  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


  thingpulse ePulse board:
  CLK = SCK = 18
  DIN = MOSI = 23
  CS = 5
  DC = 0
  RST = 2
  BUSY = 4
 */

GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(CS, DC, RST, BUSY));

U8G2_FOR_ADAFRUIT_GFX u8g2Fonts;

extern GxEPD2_GFX_BASE_CLASS &get_display() {
	return display;
}


void board_spi_setup() {
	/* board-specific setup */
	SPI.end();
	SPI.begin(SCK, MISO, MOSI, CS);
}

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

void draw() {
	display.setRotation(1);
	u8g2Fonts.setBackgroundColor(GxEPD_WHITE);
	u8g2Fonts.setForegroundColor(GxEPD_BLACK);
	display.firstPage();

	do {
		display.fillScreen(GxEPD_WHITE);
		draw_calendar(30, 10);
		draw_weather(10, 180);
		//draw_qrcode_wlan(30, 200, wifi_ssid, wifi_psk);
	} while(display.nextPage());
}

void wifi_connect() {
#if !USE_DHCP
	IPAddress ip{10, 0, 0, 8};
	//IPAddress dns{8, 8, 8, 8};
	IPAddress gateway{10, 0, 0, 1};
	IPAddress subnet{255, 255, 255, 0};
	WiFi.config(ip, gateway, subnet, gateway);
#endif
	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();
	fetch_weather();
	wifi_disconnect();

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

void loop() {
	delay(1000);
}