Skip to content

Commit 33579e7

Browse files
committedMay 21, 2024
Hack can now control the door effectively
1 parent 9dd7666 commit 33579e7

File tree

4 files changed

+85
-4
lines changed

4 files changed

+85
-4
lines changed
 

‎examples/PINAndRFID/PINAndRFID.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
*/
55

6-
#define DEBUG_ENABLED
6+
//#define DEBUG_ENABLED
77

88
#include <LarpHackableRfidLock.h>
99
#ifdef DEBUG_ENABLED

‎src/LarpHackableRfidLock.cpp

+73-2
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,8 @@ bool ICACHE_FLASH_ATTR LarpHackableRfidLock::loadConfiguration(const char* filen
496496
//Hacking game
497497
game_enabled_ = doc[game_enabled_key_] | game_enabled_default_;
498498
game_type_ = doc[game_type_key_] | game_type_default_;
499-
game_length_ = doc[game_length_key_] = game_length_default_;
500-
game_retries_ = doc[game_retries_key_] = game_retries_default_;
499+
game_length_ = doc[game_length_key_] | game_length_default_;
500+
game_retries_ = doc[game_retries_key_] | game_retries_default_;
501501
//Multi-factor authentication
502502
multi_factor_enabled_ = doc[multi_factor_enabled_key_] | multi_factor_enabled_default_;
503503
uint8_t multifactortype = doc[multi_factor_type_key_] | 0;
@@ -1412,6 +1412,29 @@ void ICACHE_FLASH_ATTR LarpHackableRfidLock::housekeeping(){
14121412
#endif
14131413
if(game_enabled_) {
14141414
game.runFsm(); //Run the game finite state machine
1415+
if(game.won()) {
1416+
if(game_lock_controls_visible_ == false) {
1417+
hack_complete_ = true;
1418+
game_lock_controls_visible_ = true;
1419+
ESPUI.updateVisibility(game_lock_controls_tab_id_, true);
1420+
}
1421+
}
1422+
else if(hack_complete_ == true) {
1423+
hack_complete_ = false;
1424+
turn_off_wifi_soon_ = millis();
1425+
if(debugStream_ != nullptr) {
1426+
debugStream_->println(F("Hack complete, hiding lock controls again"));
1427+
}
1428+
ESPUI.updateVisibility(game_lock_controls_tab_id_, false);
1429+
}
1430+
if(turn_off_wifi_soon_ !=0 && millis() - turn_off_wifi_soon_ > 3e3)
1431+
{
1432+
turn_off_wifi_soon_ = 0;
1433+
if(debugStream_ != nullptr) {
1434+
debugStream_->println(F("Wifi Off"));
1435+
}
1436+
WiFi.mode(WIFI_OFF);
1437+
}
14151438
}
14161439
#ifdef HOUSEKEEPING_DEBUG
14171440
Serial.println(housekeepingdebug++);
@@ -2090,6 +2113,13 @@ void LarpHackableRfidLock::setupGame()
20902113
game.addPlayButton(PSTR("Delta"), PSTR("Hack"), ControlColor::Carrot);
20912114
}
20922115
game.addGameTab(); //Builds all the game controls
2116+
//Lock controls
2117+
game_lock_controls_tab_id_ = ESPUI.addControl(ControlType::Tab, PSTR("Entry control"), PSTR("Entry control")); //Create the tab
2118+
game_lock_controls_button0_id_ = ESPUI.addControl(ControlType::Button, PSTR("Open once"), PSTR("Open"), ControlColor::Peterriver, game_lock_controls_tab_id_, &gameButtonCallback);
2119+
game_lock_controls_button1_id_ = ESPUI.addControl(ControlType::Button, PSTR("Open permanently"), PSTR("Unseal"), ControlColor::Peterriver, game_lock_controls_tab_id_, &gameButtonCallback);
2120+
game_lock_controls_button2_id_ = ESPUI.addControl(ControlType::Button, PSTR("Require Code/Card"), PSTR("Normal behaviour"), ControlColor::Peterriver, game_lock_controls_tab_id_, &gameButtonCallback);
2121+
game_lock_controls_button3_id_ = ESPUI.addControl(ControlType::Button, PSTR("Permanently Lock"), PSTR("Seal"), ControlColor::Peterriver, game_lock_controls_tab_id_, &gameButtonCallback);
2122+
ESPUI.updateVisibility(game_lock_controls_tab_id_, false); //Hide the tabe
20932123
game.setHelpTabTitle(PSTR("OC: How to hack"));
20942124
if(game_type_ == 0) {
20952125
game.setHelpContent(
@@ -2105,6 +2135,47 @@ void LarpHackableRfidLock::setupGame()
21052135
game.addHelpTab(); //Builds all the help controls
21062136
ESPUI.begin(game.title()); //ESPUI is started from the sketch in case you want to add your own controls and pages as well before starting ESPUI
21072137
}
2138+
void LarpHackableRfidLock::gameButtonCallback(Control* sender, int type)
2139+
{
2140+
if(Lock.debugStream_ != nullptr) {
2141+
//Lock.debugStream_->printf_P(PSTR("Game callback: %u %s\r\n"), sender->id, (type==B_DOWN ? PSTR("Down") : PSTR("Up"))); //Debug feedback in callback
2142+
if(type==B_UP)
2143+
{
2144+
if(sender->id == Lock.game_lock_controls_button0_id_)
2145+
{
2146+
Lock.debugStream_->println(PSTR("Hack: Open"));
2147+
}
2148+
else if(sender->id == Lock.game_lock_controls_button1_id_)
2149+
{
2150+
Lock.debugStream_->println(PSTR("Hack: Unseal"));
2151+
}
2152+
else if(sender->id == Lock.game_lock_controls_button2_id_)
2153+
{
2154+
Lock.debugStream_->println(PSTR("Hack: Normal"));
2155+
}
2156+
else if(sender->id == Lock.game_lock_controls_button3_id_)
2157+
{
2158+
Lock.debugStream_->println(PSTR("Hack: Seal"));
2159+
}
2160+
}
2161+
}
2162+
if(sender->id == Lock.game_lock_controls_button0_id_)
2163+
{
2164+
Lock.allow();
2165+
}
2166+
else if(sender->id == Lock.game_lock_controls_button1_id_)
2167+
{
2168+
Lock.unseal();
2169+
}
2170+
else if(sender->id == Lock.game_lock_controls_button2_id_)
2171+
{
2172+
Lock.normal();
2173+
}
2174+
else if(sender->id == Lock.game_lock_controls_button3_id_)
2175+
{
2176+
Lock.seal();
2177+
}
2178+
}
21082179
#ifdef DRD
21092180
bool ICACHE_FLASH_ATTR LarpHackableRfidLock::doubleReset() {
21102181
if(this->reset_detector_.detectDoubleReset() == true) {

‎src/LarpHackableRfidLock.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
//#include <Servo.h> //Support servo based locks
6565
#include <ESP32Servo.h>
6666

67-
#include <ESPUI.h>
67+
#include <ESPUI.h> //Hacking game support
6868
#include <ESPUIgames.h>
6969

7070
const char web_admin_header_includes_[348] PROGMEM = "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><link href=\"//fonts.googleapis.com/css?family=Raleway:400,300,600\" rel=\"stylesheet\" type=\"text/css\"><link rel=\"stylesheet\" href=\"css/normalize.css\"><link rel=\"stylesheet\" href=\"css/skeleton.css\"><link rel=\"icon\" type=\"image/png\" href=\"images/favicon.png\">";
@@ -793,6 +793,7 @@ class LarpHackableRfidLock {
793793
String mqtt_topic_key_ = PSTR("mqttTopic");
794794
//Hacking game
795795
void setupGame(); //Set up the game
796+
static void gameButtonCallback(Control* sender, int type); // Lock control callbacks for the game
796797
bool game_enabled_ = false;
797798
bool game_enabled_default_ = false;
798799
String game_enabled_key_ = PSTR("gameEnabled");
@@ -805,6 +806,14 @@ class LarpHackableRfidLock {
805806
uint8_t game_retries_ = 0;
806807
uint8_t game_retries_default_ = 0;
807808
String game_retries_key_ = PSTR("gameRetries");
809+
uint16_t game_lock_controls_tab_id_ = 0; //ESPUI tab ID
810+
uint16_t game_lock_controls_button0_id_ = 0; //ESPUI button IDs
811+
uint16_t game_lock_controls_button1_id_ = 0;
812+
uint16_t game_lock_controls_button2_id_ = 0;
813+
uint16_t game_lock_controls_button3_id_ = 0;
814+
bool hack_complete_ = false;
815+
bool game_lock_controls_visible_ = false;
816+
uint32_t turn_off_wifi_soon_ = 0;
808817
//Multi-factor authentication
809818
bool multi_factor_enabled_ = false;
810819
bool multi_factor_enabled_default_ = false;

‎src/webAdminInterface.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ void ICACHE_FLASH_ATTR LarpHackableRfidLock::web_admin_control_page_button3_pres
311311
if(Lock.debugStream_ != nullptr) {
312312
Lock.debugStream_->println(F("web_admin_control_page_button3_pressed Seal"));
313313
}
314+
Lock.seal();
314315
}
315316
void ICACHE_FLASH_ATTR LarpHackableRfidLock::webAdminControlPageCallback() {
316317
if(Lock.debugStream_ != nullptr) {

0 commit comments

Comments
 (0)
Please sign in to comment.