-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBLEWatchNotifier.ino
More file actions
136 lines (105 loc) · 3.39 KB
/
BLEWatchNotifier.ino
File metadata and controls
136 lines (105 loc) · 3.39 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
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
#include "config.h"
BLEServer* pServer = NULL;
BLECharacteristic* pCharacteristic = NULL;
uint32_t value = 0;
TTGOClass *ttgo;
TFT_eSPI *tft = nullptr;
bool irq = false;
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
uint32_t targetTime = 0;
boolean initial = 1;
byte xcolon = 0;
static uint8_t conv2d(const char *p)
{
uint8_t v = 0;
if ('0' <= *p && *p <= '9')
v = *p - '0';
return 10 * v + *++p - '0';
}
uint8_t hh = conv2d(__TIME__), mm = conv2d(__TIME__ + 3), ss = conv2d(__TIME__ + 6); // Get H, M, S from compile time
void display_show()
{
ttgo->openBL();
tft->fillScreen(TFT_BLACK);
tft->drawString(String(ttgo->power->getBattPercentage()) + " %", 25, 100);
byte xpos = 6;
byte ypos = 0;
ttgo->tft->setTextColor(0x39C4, TFT_BLACK);
//ttgo->tft->drawString("88:88", xpos, ypos, 7);
ttgo->tft->setTextColor(0xFBE0, TFT_BLACK);
if (hh < 10) xpos += ttgo->tft->drawChar('0', xpos, ypos, 7);
xpos += ttgo->tft->drawNumber(hh, xpos, ypos, 7);
xcolon = xpos;
xpos += ttgo->tft->drawChar(':', xpos, ypos, 7);
if (mm < 10) xpos += ttgo->tft->drawChar('0', xpos, ypos, 7);
ttgo->tft->drawNumber(mm, xpos, ypos, 7);
}
void setup() {
ttgo = TTGOClass::getWatch();
ttgo->begin();
tft = ttgo->tft;
tft->setTextFont(2);
tft->setTextColor(TFT_GREEN, TFT_BLACK);
pinMode(AXP202_INT, INPUT_PULLUP);
attachInterrupt(AXP202_INT, [] {
irq = true;
}, FALLING);
ttgo->power->enableIRQ(AXP202_PEK_SHORTPRESS_IRQ | AXP202_VBUS_REMOVED_IRQ | AXP202_VBUS_CONNECT_IRQ | AXP202_CHARGING_IRQ, true);
ttgo->power->clearIRQ();
BLEDevice::init("ESP32");
// Create the BLE Server
pServer = BLEDevice::createServer();
BLEService *pService = pServer->createService(SERVICE_UUID);
pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE |
BLECharacteristic::PROPERTY_NOTIFY |
BLECharacteristic::PROPERTY_INDICATE
);
pCharacteristic->addDescriptor(new BLE2902());
pService->start();
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
pAdvertising->addServiceUUID(SERVICE_UUID);
pAdvertising->setScanResponse(false);
pAdvertising->setMinPreferred(0x0); // set value to 0x00 to not advertise this parameter
//pAdvertising->setMinPreferred(0x0);
//pAdvertising->setMaxPreferred(0x0);
//pAdvertising->setMaxInterval(0x460);
//pAdvertising->setMinInterval(0x460);
BLEDevice::startAdvertising();
}
void loop() {
if (targetTime < millis()) {
targetTime = millis() + 1000;
ss++; // Advance second
if (ss == 60) {
ss = 0;
mm++; // Advance minute
if (mm > 59) {
mm = 0;
hh++; // Advance hour
if (hh > 23) {
hh = 0;
}
}
}
}
if (irq) {
irq = false;
ttgo->power->readIRQ();
if (ttgo->power->isPEKShortPressIRQ()) {
display_show();
delay(2000);
ttgo->closeBL();
}
ttgo->power->clearIRQ();
}
//lv_task_handler();
delay(5);
}