This repository has been archived by the owner on Mar 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOCHKI.ino
204 lines (179 loc) · 5.23 KB
/
OCHKI.ino
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include <OLED_I2C.h>
#include <ArduinoJson.h>
#include <MsTimer2.h>
#include <TimeLib.h>
#include <avr/delay.h>
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(8, 9);
long Millis_updated = 0;
String bt_msg = "";
OLED display(SDA, SCL, 4);
extern uint8_t SmallFont[];
extern uint8_t BigNumbers[];
static const uint8_t PROGMEM bat_0 [] = {
0xE0, 0xF0, 0xF8, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xF0, 0xE0, 0x80,
0x07, 0x0F, 0x1F, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x0F, 0x07, 0x01
};
static const uint8_t PROGMEM bat_1 [] = {
0xE0, 0xF0, 0xF8, 0x38, 0xF8, 0xF8, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xF0, 0xE0, 0x80,
0x07, 0x0F, 0x1F, 0x1C, 0x1F, 0x1F, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x0F, 0x07, 0x01
};
static const uint8_t PROGMEM bat_2 [] = {
0xE0, 0xF0, 0xF8, 0x38, 0xF8, 0xF8, 0x38, 0xF8, 0xF8, 0x38, 0x38, 0x38, 0x38, 0xF0, 0xE0, 0x80,
0x07, 0x0F, 0x1F, 0x1C, 0x1F, 0x1F, 0x1C, 0x1F, 0x1F, 0x1C, 0x1C, 0x1C, 0x1C, 0x0F, 0x07, 0x01
};
static const uint8_t PROGMEM bat_3 [] = {
0xE0, 0xF0, 0xF8, 0x38, 0xF8, 0xF8, 0x38, 0xF8, 0xF8, 0x38, 0xF8, 0xF8, 0x38, 0xF0, 0xE0, 0x80,
0x07, 0x0F, 0x1F, 0x1C, 0x1F, 0x1F, 0x1C, 0x1F, 0x1F, 0x1C, 0x1F, 0x1F, 0x1C, 0x0F, 0x07, 0x01
};
static const uint8_t PROGMEM bat_4 [] = {
0xE0, 0xF0, 0xF8, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xB8, 0xB8, 0x38, 0x38, 0xF0, 0xE0, 0x80,
0x07, 0x0F, 0x1F, 0x1C, 0x1C, 0x1D, 0x1F, 0x1F, 0x1D, 0x1D, 0x1D, 0x1D, 0x1C, 0x0F, 0x07, 0x01
};
static const uint8_t PROGMEM talk [] = {
0xFC, 0xFE, 0xFF, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x0F, 0xFF, 0xFE, 0xFC,
0x0F, 0x1F, 0x3F, 0x7C, 0xF0, 0xE0, 0x70, 0x38, 0x38, 0x38, 0x38, 0x38, 0x3C, 0x1F, 0x0F, 0x07
};
static const uint8_t PROGMEM bluetooth [] = {
0x00, 0x00, 0x00, 0x00, 0x30, 0x60, 0xC0, 0xFE, 0x86, 0xCC, 0x78, 0x30, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0x0C, 0x06, 0xFF, 0xC3, 0x66, 0x3C, 0x18, 0x00, 0x00, 0x00, 0x00
};
void setup() {
Serial.begin(115200);
BT_init("SeeEYE", 9600);
display_int();
MsTimer2::set(1000, clock);
MsTimer2::start();
}
/*/
Пример отправки данных:
{
1: "10-21",
2: 60,
3: 3,
4: 1,
5: "Aleksandr Ruban"
6: "Privet, urod"
}
/*/
void loop() {
if (BT_check_data()) {
BT_readData();
DynamicJsonBuffer jsonBuffer;
Serial.println(bt_msg);
JsonObject& data = jsonBuffer.parseObject(bt_msg);
if (!data.success()) {
display_error(1);
return;
}
setTime(data["1"]);
display.clrScr();
//Батарея
if (data["2"] < 25) display.drawBitmap(112, 0, bat_0, 16, 16);
else if (data["2"] >= 25 && data["2"] < 50) display.drawBitmap(112, 0, bat_1, 16, 16);
else if (data["2"] >= 50 && data["2"] < 75) display.drawBitmap(112, 0, bat_2, 16, 16);
else if (data["2"] >= 75 && data["2"] < 100) display.drawBitmap(112, 0, bat_3, 16, 16);
else display.drawBitmap(112, 0, bat_4, 16, 16);
//Что-то другое
}
if (millis() - Millis_updated > 1000) {
Millis_updated = millis();
display.update();
}
}
void msg(byte type, char* from_msg, char* msg) {
switch (type) {
}
}
void display_error(byte type) {
display.clrScr();
display.setFont(SmallFont);
switch (type) {
case 1: display.print("parseObject failed", CENTER, 10);
display.update();
display.invert(true);
delay(500);
display.invert(false);
delay(500);
display.invert(true);
delay(500);
display.invert(false);
break;
case 2: display.print("SeeEYE v.2", CENTER, 10);
display.print("Connect", CENTER, 19);
display.print("Waiting for data", CENTER, 28);
display.update();
break;
case 3: display.print("SeeEYE v.2", CENTER, 10);
display.print("Connection...", CENTER, 19);
display.update();
break;
default: display.print("Unknown error", CENTER, 10);
display.update();
}
}
void check_bet() {
uint8_t check = analogRead(A0);
//Тута батарея
}
void clock() {
display.setFont(BigNumbers);
display.print(String(hour()) + "-" + String(minute()), CENTER, 0);
display.update();
}
void display_int() {
display.begin();
display.setFont(SmallFont);
display.setBrightness(150);
//open test
display.drawBitmap(112, 0, bat_4, 16, 16);
display.drawBitmap(112, 16, bluetooth, 16, 16);
display.drawBitmap(112, 32, talk, 16, 16);
//close test
}
void BT_init(const char *_name, int _rate) {
BTSerial.begin(_rate);
return;
/*if(BT_check_bt_connect()){
BTSerial.print("AT+NAME");
BTSerial.print(_name);
return;
}*/
}
bool BT_readData() {
_delay_ms(50);
bt_msg = "";
char last_read;
bool record = false;
while (last_read != '}') {
if (BT_check_data()) {
last_read = (char)BTSerial.read();
if (last_read == '{') record = true;
if (record) bt_msg += last_read;
Serial.println(bt_msg);
}
}
return 1;
}
bool BT_sendData(const char *_data) {
BTSerial.print(_data);
return 1;
}
bool BT_check_bt_connect() {
BT_sendData("AT");
_delay_ms(800);
if (BT_readData() && bt_msg == "OK") {
return 1;
}
else {
return 0;
}
}
bool BT_check_data() {
if (BTSerial.available()) {
return 1;
}
else {
return 0;
}
}