Added fake clock feature for DSTIKE wristband

This commit is contained in:
Stefan Kremser
2018-10-13 19:31:03 +02:00
parent bd332d533e
commit e466566f62
3 changed files with 2051 additions and 1943 deletions

View File

@@ -31,12 +31,11 @@ void DisplayUI::configOff() {
}
void DisplayUI::updatePrefix() {
display.clear(); // clear display
display.setTextAlignment(TEXT_ALIGN_LEFT); // reset text alignment just in case ;)
display.clear();
}
void DisplayUI::updateSuffix() {
display.display(); // draw changes
display.display();
}
void DisplayUI::drawString(int x, int y, String str) {
@@ -64,6 +63,11 @@ void DisplayUI::setup() {
setupButtons();
buttonTime = currentTime;
#ifdef FAKE_CLOCK
clockHour = random(12);
clockMinute = random(60);
#endif // ifdef FAKE_CLOCK
// ===== MENUS ===== //
// MAIN MENU
@@ -75,6 +79,15 @@ void DisplayUI::setup() {
scan.start(SCAN_MODE_SNIFFER, 0, SCAN_MODE_OFF, 0, false, wifi_channel);
mode = DISPLAY_MODE::PACKETMONITOR;
});
#ifdef FAKE_CLOCK
addMenuNode(&mainMenu, D_CLOCK, [this]() { // PACKET MONITOR
mode = DISPLAY_MODE::CLOCK;
display.setFont(ArialMT_Plain_24);
display.setTextAlignment(TEXT_ALIGN_CENTER);
});
#endif // ifdef FAKE_CLOCK
#ifdef HIGHLIGHT_LED
addMenuNode(&mainMenu, D_LED, [this]() { // LED
highlightLED = !highlightLED;
@@ -503,6 +516,8 @@ void DisplayUI::setupButtons() {
else currentMenu->selected = currentMenu->list->size() - 1;
} else if (mode == DISPLAY_MODE::PACKETMONITOR) { // when in packet monitor, change channel
scan.setChannel(wifi_channel + 1);
} else if (mode == DISPLAY_MODE::CLOCK) { // when in packet monitor, change channel
setTime(clockHour, clockMinute + 1, clockSecond);
}
}
});
@@ -516,6 +531,8 @@ void DisplayUI::setupButtons() {
else currentMenu->selected = currentMenu->list->size() - 1;
} else if (mode == DISPLAY_MODE::PACKETMONITOR) { // when in packet monitor, change channel
scan.setChannel(wifi_channel + 1);
} else if (mode == DISPLAY_MODE::CLOCK) { // when in packet monitor, change channel
setTime(clockHour, clockMinute + 10, clockSecond);
}
}
}, buttonDelay);
@@ -530,6 +547,8 @@ void DisplayUI::setupButtons() {
else currentMenu->selected = 0;
} else if (mode == DISPLAY_MODE::PACKETMONITOR) { // when in packet monitor, change channel
scan.setChannel(wifi_channel - 1);
} else if (mode == DISPLAY_MODE::CLOCK) { // when in packet monitor, change channel
setTime(clockHour, clockMinute - 1, clockSecond);
}
}
});
@@ -543,6 +562,8 @@ void DisplayUI::setupButtons() {
else currentMenu->selected = 0;
} else if (mode == DISPLAY_MODE::PACKETMONITOR) { // when in packet monitor, change channel
scan.setChannel(wifi_channel - 1);
} else if (mode == DISPLAY_MODE::CLOCK) { // when in packet monitor, change channel
setTime(clockHour, clockMinute - 10, clockSecond);
}
}
}, buttonDelay);
@@ -565,6 +586,12 @@ void DisplayUI::setupButtons() {
scan.stop();
mode = DISPLAY_MODE::MENU;
break;
case DISPLAY_MODE::CLOCK:
mode = DISPLAY_MODE::MENU;
display.setFont(DejaVu_Sans_Mono_12);
display.setTextAlignment(TEXT_ALIGN_LEFT);
break;
}
}
});
@@ -596,6 +623,10 @@ void DisplayUI::setupButtons() {
scan.stop();
mode = DISPLAY_MODE::MENU;
break;
case DISPLAY_MODE::CLOCK:
mode = DISPLAY_MODE::MENU;
break;
}
}
});
@@ -614,6 +645,13 @@ void DisplayUI::draw() {
updatePrefix();
#ifdef FAKE_CLOCK
if (clockTime < currentTime - 1000) {
setTime(clockHour, clockMinute++, clockSecond + 1);
clockTime += 1000;
}
#endif // ifdef FAKE_CLOCK
switch (mode) {
case DISPLAY_MODE::BUTTON_TEST:
drawButtonTest();
@@ -637,6 +675,12 @@ void DisplayUI::draw() {
}
drawIntro();
break;
#ifdef FAKE_CLOCK
case DISPLAY_MODE::CLOCK:
drawClock();
break;
#endif // ifdef FAKE_CLOCK
}
updateSuffix();
@@ -709,13 +753,26 @@ void DisplayUI::drawPacketMonitor() {
}
void DisplayUI::drawIntro() {
drawString(0, lineHeight * 0, center(String(F("")), maxLen));
drawString(0, lineHeight * 1, center(String(F("ESP8266 Deauther")), maxLen));
drawString(0, lineHeight * 2, center(String(F("by @Spacehuhn")), maxLen));
drawString(0, lineHeight * 3, center(String(F("")), maxLen));
drawString(0, lineHeight * 4, center(settings.getVersion(), maxLen));
drawString(0, center(String(D_INTRO_0), maxLen));
drawString(1, center(String(D_INTRO_1), maxLen));
drawString(2, center(String(D_INTRO_2), maxLen));
drawString(3, center(String(D_INTRO_3), maxLen));
drawString(4, center(settings.getVersion(), maxLen));
}
#ifdef FAKE_CLOCK
void DisplayUI::drawClock() {
String clockTime = String(clockHour);
clockTime += ':';
if (clockMinute < 10) clockTime += '0';
clockTime += String(clockMinute);
display.drawString(64, 20, clockTime);
}
#endif // ifdef FAKE_CLOCK
void DisplayUI::clearMenu(Menu* menu) {
while (menu->list->size() > 0) {
menu->list->remove(0);
@@ -784,3 +841,37 @@ void DisplayUI::addMenuNode(Menu* menu, const char* ptr, Menu* next) {
return str(ptr);
}, next);
}
void DisplayUI::setTime(int h, int m, int s) {
if (s >= 60) {
s = 0;
m++;
}
if (m >= 60) {
m = 0;
h++;
}
if (h >= 24) {
h = 0;
}
if (s < 0) {
s = 59;
m--;
}
if (m < 0) {
m = 59;
h--;
}
if (h < 0) {
h = 23;
}
clockHour = h;
clockMinute = m;
clockSecond = s;
}

View File

@@ -29,6 +29,11 @@ extern String right(String a, int len);
extern String leftRight(String a, String b, int len);
extern String replaceUtf8(String str, String r);
const char D_INTRO_0[] PROGMEM = "";
const char D_INTRO_1[] PROGMEM = "ESP8266 Deauther";
const char D_INTRO_2[] PROGMEM = "by @Spacehuhn";
const char D_INTRO_3[] PROGMEM = "";
// fallback for the buttons
#ifndef BUTTON_UP
#define BUTTON_UP 255
@@ -61,7 +66,7 @@ struct Menu {
class DisplayUI {
public:
enum DISPLAY_MODE { OFF = 0, BUTTON_TEST = 1, MENU = 2, LOADSCAN = 3, PACKETMONITOR = 4, INTRO = 5 };
enum DISPLAY_MODE { OFF = 0, BUTTON_TEST = 1, MENU = 2, LOADSCAN = 3, PACKETMONITOR = 4, INTRO = 5, CLOCK = 6 };
uint8_t mode = DISPLAY_MODE::MENU;
bool highlightLED = false;
@@ -160,6 +165,17 @@ class DisplayUI {
void addMenuNode(Menu* menu, std::function<String()>getStr, Menu* next);
void addMenuNode(Menu* menu, const char* ptr, std::function<void()>click);
void addMenuNode(Menu* menu, const char* ptr, Menu* next);
#ifdef FAKE_CLOCK
void drawClock();
void setTime(int h, int m, int s);
int clockHour = 6;
int clockMinute = 0;
int clockSecond = 0;
uint32_t clockTime = 0;
#endif // ifdef FAKE_CLOCK
};
// ===== FONT ===== //

View File

@@ -301,6 +301,7 @@ const char D_SCAN[] PROGMEM = "SCAN";
const char D_SHOW[] PROGMEM = "SELECT";
const char D_ATTACK[] PROGMEM = "ATTACK";
const char D_PACKET_MONITOR[] PROGMEM = "PACKET MONITOR";
const char D_CLOCK[] PROGMEM = "CLOCK";
// SCAN MENU
const char D_SCAN_APST[] PROGMEM = "SCAN AP + ST";