-
Notifications
You must be signed in to change notification settings - Fork 2
/
WatchFace.cpp
75 lines (61 loc) · 2.32 KB
/
WatchFace.cpp
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
#include "WatchFace.h"
#include "Menu.h"
#include "util/util.h"
#include <fonts/Dustfine72pt7b.h>
#include <fonts/FreeMonoBold12pt7b.h>
#include <string>
#include <system/system.h>
#include <utility>
#include <vector>
void WatchFace::draw() {
Graphics *gfx = _sys->getGraphics();
RTC *rtc = _sys->getRTC();
Battery *battery = _sys->getBattery();
gfx->clearBuffer();
RTCDateTime now = rtc->now();
gfx->setTextColor(0);
gfx->setFont(&Dustfine72pt7b);
gfx->setCursor(45, 120);
//char txt[64] = {'\0'};
gfx->setTextColor(0);
//gfx->printf("%02d%c", now.hour, ((now.second % 2) ? '.' : ' '));
gfx->printf("%02d", now.hour);
//gfx->print(txt);
gfx->setFont(&Dustfine72pt7b);
gfx->setCursor(45, 220);
gfx->printf("%02d", now.minute);
gfx->setFont(&FreeMonoBold12pt7b);
gfx->printf("%02d", now.second);
gfx->setFont(&FreeMonoBold12pt7b);
gfx->setCursor(30, 250);
gfx->printf("%04d-%02d-%02d", now.year, now.month, now.day);
gfx->setCursor(15, 270);
gfx->print("batt: ");
gfx->print(battery->get_percent());
gfx->print("%/");
gfx->printf("%.1fV", (float)(battery->get_voltage_mV())/1000);
gfx->setCursor(25, 290);
//gfx->printf("%d uA", (battery->get_current_uA()));
//
//drawTopBar(_sys);
}
void WatchFace::handleEvent(EVENT_T e) {
// flashlight
if (e.type == BUTTON_CHANGE && e.button == BUTTON_MIDDLE) {
if (_sys->getButtonPressed(PIN_BUTTON5)) {
_sys->getFlashlight()->on();
} else {
_sys->getFlashlight()->off();
}
}
if (e.type == BUTTON_PRESS && e.button == BUTTON_BOTTOM) {
Menu* menu = new Menu(_sys);
menu->addItem([&]() { return std::string((_sys->getBacklight()->isOn()) ? "disable" : "enable") + " backlight";}, [&]() { _sys->getBacklight()->toggle(); return false; });
menu->addItem([&]() { return std::string((_sys->get5Vreg()->isOn()) ? "disable" : "enable") + " 5v reg";}, [&]() { _sys->get5Vreg()->toggle(); return false; });
menu->addItem([&]() { return std::string((_sys->getFlashlight()->isOn()) ? "disable" : "enable") + " flashlight";}, [&]() { _sys->getFlashlight()->toggle(); return false; });
menu->addItem("", []() { return false; }); // spacer
menu->addItem("Update Mode", [&]() { _sys->getFlashlight()->off(); enter_dfu(); return false; });
menu->addItem("back", []() { return true; });
_sys->switchToNewView(menu);
}
}