Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
Latest commit
145 lines (124 loc) · 3.38 KB
/
Copy pathmain.cpp
File metadata and controls
145 lines (124 loc) · 3.38 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Modbus bridge device V3
// Copyright 2020 by miq1@gmx.de
#include<Arduino.h>
#include"Blinker.h"
#include"Buttoner.h"
#include<Wire.h>
#include"SSD1306Ascii.h"
#include"SSD1306AsciiWire.h"
#include"TelnetLogAsync.h"
#include"Logging.h"
// 0X3C+SA0 - 0x3C or 0x3D
#defineI2C_ADDRESS0x3C
// Define proper RST_PIN if required.
#defineRST_PIN -1
#defineLED_RGPIO_NUM_4
#defineLED_BGPIO_NUM_25
#defineBUTTON_AGPIO_NUM_27
#defineBUTTON_BGPIO_NUM_26
Blinker rot(LED_R);
Blinker gruen(LED_B);
Buttoner ButtonA(BUTTON_A, HIGH, false, 2);
Buttoner ButtonB(BUTTON_B);
constuint16_tBL_QUICKLY(0x2);
constuint16_tBL_SLOW(0x3000);
constuint16_tBL_FLICK(0xFFFC);
SSD1306AsciiWire oled;
TelnetLog tl(23, 4);
voidsetup() {
Serial.begin(115200);
Serial.println("\n");
delay(5000);
Serial.println("_OK_\n");
WiFi.begin("FritzGandhi", "MahatmaNetzwerk");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(100);
}
rot.start(BL_FLICK);
gruen.start(BL_SLOW);
Wire.begin();
Wire.setClock(400000L);
oled.begin(&Adafruit128x32, I2C_ADDRESS);
oled.setFont(System5x7);
oled.setScrollMode(SCROLL_MODE_AUTO);
oled.clear();
oled.printf("012345678901234567890123456789");
delay(3000);
oled.clear();
oled.setFont(fixed_bold10x15);
oled.printf("012345678901234567890123456789");
delay(3000);
oled.clear();
oled.setFont(Callibri10);
oled.printf("012345678901234567890123456789");
delay(3000);
oled.clear();
oled.setFont(System5x7);
tl.begin("Bridge-Test");
// LOGDEVICE = &tl;
MBUlogLvl = LOG_LEVEL_VERBOSE;
}
voidloop() {
staticuint32_t dTimer = millis();
staticbool dOn = false;
staticunsignedint oldClientNum = 999;
char buffer[64];
rot.update();
gruen.update();
if (oldClientNum != tl.getActiveClients()) {
oldClientNum = tl.getActiveClients();
Serial.printf("%d clients.\n", oldClientNum);
}
if (ButtonA.update() > 0) {
if (!dOn) oled.ssd1306WriteCmd(SSD1306_DISPLAYON);
dOn = true;
dTimer = millis();
switch (ButtonA.getEvent()) {
caseBE_CLICK:
snprintf(buffer, 64, "A clicked.(%d)", ButtonA.qSize());
break;
caseBE_DOUBLECLICK:
snprintf(buffer, 64, "A doubly clicked.(%d)", ButtonA.qSize());
break;
caseBE_PRESS:
snprintf(buffer, 64, "A held down.(%d)", ButtonA.qSize());
oled.setContrast(0);
break;
default:
snprintf(buffer, 64, "Huh? A?(%d)", ButtonA.qSize());
break;
}
oled.println();
oled.print(buffer);
LOG_D("Button %s\n", buffer);
HEXDUMP_V("Buffer", (uint8_t *)buffer, strlen(buffer));
}
if (ButtonB.update() > 0) {
if (!dOn) oled.ssd1306WriteCmd(SSD1306_DISPLAYON);
dOn = true;
dTimer = millis();
switch (ButtonB.getEvent()) {
caseBE_CLICK:
snprintf(buffer, 64, "B clicked.(%d)", ButtonB.qSize());
break;
caseBE_DOUBLECLICK:
snprintf(buffer, 64, "B doubly clicked.(%d)", ButtonB.qSize());
break;
caseBE_PRESS:
snprintf(buffer, 64, "B held down.(%d)", ButtonB.qSize());
oled.setContrast(255);
break;
default:
snprintf(buffer, 64, "Huh? B?(%d)", ButtonB.qSize());
break;
}
oled.println();
oled.print(buffer);
tl.println(buffer);
}
if (dOn && millis() - dTimer > 5000) {
oled.ssd1306WriteCmd(SSD1306_DISPLAYOFF);
dOn = false;
}
}