@@ -496,8 +496,8 @@ bool ICACHE_FLASH_ATTR LarpHackableRfidLock::loadConfiguration(const char* filen
496
496
// Hacking game
497
497
game_enabled_ = doc[game_enabled_key_] | game_enabled_default_;
498
498
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_;
501
501
// Multi-factor authentication
502
502
multi_factor_enabled_ = doc[multi_factor_enabled_key_] | multi_factor_enabled_default_;
503
503
uint8_t multifactortype = doc[multi_factor_type_key_] | 0 ;
@@ -1412,6 +1412,29 @@ void ICACHE_FLASH_ATTR LarpHackableRfidLock::housekeeping(){
1412
1412
#endif
1413
1413
if (game_enabled_) {
1414
1414
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
+ }
1415
1438
}
1416
1439
#ifdef HOUSEKEEPING_DEBUG
1417
1440
Serial.println (housekeepingdebug++);
@@ -2090,6 +2113,13 @@ void LarpHackableRfidLock::setupGame()
2090
2113
game.addPlayButton (PSTR (" Delta" ), PSTR (" Hack" ), ControlColor::Carrot);
2091
2114
}
2092
2115
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
2093
2123
game.setHelpTabTitle (PSTR (" OC: How to hack" ));
2094
2124
if (game_type_ == 0 ) {
2095
2125
game.setHelpContent (
@@ -2105,6 +2135,47 @@ void LarpHackableRfidLock::setupGame()
2105
2135
game.addHelpTab (); // Builds all the help controls
2106
2136
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
2107
2137
}
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
+ }
2108
2179
#ifdef DRD
2109
2180
bool ICACHE_FLASH_ATTR LarpHackableRfidLock::doubleReset () {
2110
2181
if (this ->reset_detector_ .detectDoubleReset () == true ) {
0 commit comments