Added password hold option

This commit is contained in:
Ray Jones 2019-09-17 20:07:57 +10:00
parent 3a70970356
commit c51b18dd36
9 changed files with 137 additions and 38 deletions

BIN
icons/Password.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 B

View File

@ -36,6 +36,7 @@ CMenuSelScreen::onSelect()
CScreenHeader::onSelect(); CScreenHeader::onSelect();
_rowSel = 0; _rowSel = 0;
_menuMode = NVstore.getUserSettings().menuMode; _menuMode = NVstore.getUserSettings().menuMode;
_holdPW = NVstore.getUserSettings().holdPassword;
_scrollChar = 0; _scrollChar = 0;
_bReload = false; _bReload = false;
} }
@ -63,15 +64,23 @@ CMenuSelScreen::show()
_showConfirmMessage(); _showConfirmMessage();
} }
else { else {
_showTitle("Menu Mode"); _showTitle("Menu Options");
_drawBitmap(30, 16, MenuIconInfo); _drawBitmap(25, 16, MenuIconInfo);
switch(_menuMode) { switch(_menuMode) {
case 0: strcpy(msg, "Standard"); break; case 0: strcpy(msg, "Standard"); break;
case 1: strcpy(msg, "Basic"); break; case 1: strcpy(msg, "Basic"); break;
case 2: strcpy(msg, "No heater"); break; case 2: strcpy(msg, "No heater"); break;
} }
_printMenuText(50, 16, msg, _rowSel == 1); _printMenuText(45, 16, msg, _rowSel == 2);
_drawBitmap(25, 28, passwordIconInfo);
if(_holdPW)
strcpy(msg, "Retain 24hrs");
else
strcpy(msg, "Forget");
_printMenuText(45, 30, msg, _rowSel == 1);
} }
} }
return true; return true;
@ -87,20 +96,28 @@ CMenuSelScreen::animate()
} }
if(_rowSel != SaveConfirm) { if(_rowSel != SaveConfirm) {
const char* pMsg = NULL; const char* pMsg = NULL;
switch(_menuMode) { switch(_rowSel) {
case 0: case 0:
pMsg = " Standard, complete menu allows full access to features. "; _printMenuText(_display.xCentre(), 52, " \021 \030Edit Exit \020 ", true, eCentreJustify);
break;
case 1:
pMsg = " Basic simplified menu. ";
break; break;
case 2: case 2:
pMsg = " No heater mode. "; switch(_menuMode) {
case 0: pMsg = " Standard, complete menu allows full access to features. "; break;
case 1: pMsg = " Basic simplified menu. "; break;
case 2: pMsg = " No heater mode. "; break;
}
break;
case 1:
if(_holdPW)
pMsg = " Retain password for 24 hours after correct entry. ";
else
pMsg = " Forget password after each entry. ";
break; break;
} }
_display.drawFastHLine(0, 52, 128, WHITE); if(pMsg != NULL) {
if(pMsg != NULL) _display.drawFastHLine(0, 52, 128, WHITE);
_scrollMessage(56, pMsg, _scrollChar); _scrollMessage(56, pMsg, _scrollChar);
}
return true; return true;
} }
} }
@ -127,6 +144,7 @@ CMenuSelScreen::keyHandler(uint8_t event)
_enableStoringMessage(); _enableStoringMessage();
us = NVstore.getUserSettings(); us = NVstore.getUserSettings();
us.menuMode = _menuMode; us.menuMode = _menuMode;
us.holdPassword = _holdPW;
NVstore.setUserSettings(us); NVstore.setUserSettings(us);
NVstore.save(); NVstore.save();
switch(us.menuMode) { switch(us.menuMode) {
@ -134,11 +152,21 @@ CMenuSelScreen::keyHandler(uint8_t event)
case 1: DebugPort.println("Invoking Basic menu mode"); break; case 1: DebugPort.println("Invoking Basic menu mode"); break;
case 2: DebugPort.println("Invoking No Heater menu mode"); break; case 2: DebugPort.println("Invoking No Heater menu mode"); break;
} }
_holdPassword();
_bReload = true; _bReload = true;
_rowSel = 0; _rowSel = 0;
} }
else { else {
_getPassword(); if(_rowSel == 0) {
_getPassword();
if(_isPasswordOK()) {
_rowSel = 1;
}
}
else {
_rowSel++;
UPPERLIMIT(_rowSel, 2);
}
} }
} }
// DOWN press // DOWN press
@ -182,6 +210,9 @@ CMenuSelScreen::adjust(int dir)
{ {
switch(_rowSel) { switch(_rowSel) {
case 1: case 1:
_holdPW = _holdPW ? 0 : 1;
break;
case 2:
_menuMode += dir; _menuMode += dir;
WRAPLIMITS(_menuMode, 0, 2); WRAPLIMITS(_menuMode, 0, 2);
break; break;

View File

@ -34,6 +34,7 @@ class CMenuSelScreen : public CPasswordScreen
int _rowSel; int _rowSel;
int _scrollChar; int _scrollChar;
int _menuMode; int _menuMode;
uint8_t _holdPW;
bool _bReload; bool _bReload;
void _initUI(); void _initUI();
public: public:

View File

@ -31,8 +31,10 @@
#include "PasswordScreen.h" #include "PasswordScreen.h"
#include "KeyPad.h" #include "KeyPad.h"
#include "../Utility/macros.h" #include "../Utility/macros.h"
#include "../Utility/NVStorage.h"
#include "fonts/Arial.h" #include "fonts/Arial.h"
long CPasswordScreen::__Expiry = 0;
CPasswordScreen::CPasswordScreen(C128x64_OLED& display, CScreenManager& mgr) : CScreenHeader(display, mgr) CPasswordScreen::CPasswordScreen(C128x64_OLED& display, CScreenManager& mgr) : CScreenHeader(display, mgr)
{ {
@ -47,16 +49,33 @@ CPasswordScreen::onSelect()
} }
void void
CPasswordScreen::_initUI() CPasswordScreen::__initPassword(bool get)
{ {
_bGetPassword = false; _bGetPassword = get;
_bPasswordOK = false; _bPasswordOK = false;
_bPasswordOK |= __Expiry != 0;
_PWcol = 0; _PWcol = 0;
// reset PW digits
for(int i= 0; i < 4; i++) for(int i= 0; i < 4; i++)
_PWdig[i] = -1; _PWdig[i] = -1;
}
void
CPasswordScreen::_initUI()
{
__initPassword(false);
_SaveTime = 0; _SaveTime = 0;
} }
void
CPasswordScreen::_getPassword()
{
__initPassword(true);
_ScreenManager.reqUpdate();
}
bool bool
CPasswordScreen::show() CPasswordScreen::show()
{ {
@ -68,17 +87,13 @@ CPasswordScreen::show()
return true; return true;
} }
else if(_bGetPassword) { else if(_bGetPassword) {
_display.clearDisplay(); if(!_bPasswordOK) {
/* { _display.clearDisplay();
CTransientFont AF(_display, &arial_8ptBoldFontInfo); _showPassword();
_printMenuText(_display.xCentre(), 32, "Enter password...", false, eCentreJustify); return true;
}*/ }
_showPassword();
return true;
}
else {
return false;
} }
return false;
} }
bool bool
@ -100,10 +115,25 @@ CPasswordScreen::_busy()
return _SaveTime != 0; return _SaveTime != 0;
} }
void
CPasswordScreen::_holdPassword()
{
if(NVstore.getUserSettings().holdPassword)
__Expiry = millis() + 24 * 60 * 60 * 1000; // 24 hours
else
__Expiry = 0;
}
bool bool
CPasswordScreen::keyHandler(uint8_t event) CPasswordScreen::keyHandler(uint8_t event)
{ {
if(_bGetPassword) { if(_bGetPassword) {
if(_bPasswordOK) {
_bGetPassword = false;
return true;
}
if(event & keyPressed) { if(event & keyPressed) {
// press CENTRE // press CENTRE
@ -114,6 +144,7 @@ CPasswordScreen::keyHandler(uint8_t event)
(_PWdig[2] == 8) && (_PWdig[2] == 8) &&
(_PWdig[3] == 8)) { (_PWdig[3] == 8)) {
_bPasswordOK = true; _bPasswordOK = true;
_holdPassword();
} }
_bGetPassword = false; _bGetPassword = false;
@ -186,19 +217,6 @@ CPasswordScreen::_showPassword()
return _bGetPassword; return _bGetPassword;
} }
void
CPasswordScreen::_getPassword()
{
_bGetPassword = true;
_bPasswordOK = false;
_PWcol = 0;
// reset PW digits
for(int i= 0; i < 4; i++)
_PWdig[i] = -1;
_ScreenManager.reqUpdate();
}
void void
CPasswordScreen::_enableStoringMessage() CPasswordScreen::_enableStoringMessage()
{ {
@ -207,3 +225,14 @@ CPasswordScreen::_enableStoringMessage()
} }
bool CPasswordScreen::_isPasswordOK()
{
if(__Expiry) {
long tDelta = millis() - __Expiry;
if(tDelta > 0) {
__Expiry = 0;
_bPasswordOK = false;
}
}
return __Expiry != 0 || _bPasswordOK;
};

View File

@ -33,10 +33,13 @@ class CPasswordScreen : public CScreenHeader {
bool _bPasswordOK; bool _bPasswordOK;
int _PWcol; int _PWcol;
unsigned long _SaveTime; unsigned long _SaveTime;
static long __Expiry;
void __initPassword(bool get);
protected: protected:
bool _showPassword(); bool _showPassword();
void _holdPassword();
void _getPassword(); void _getPassword();
bool _isPasswordOK() { return _bPasswordOK; }; bool _isPasswordOK();
void _enableStoringMessage(); void _enableStoringMessage();
void _initUI(); void _initUI();
bool _busy(); bool _busy();

View File

@ -1345,3 +1345,31 @@ const uint8_t PROGMEM userBitmap[] =
const BITMAP_INFO UserIconInfo(8, 9, userBitmap); const BITMAP_INFO UserIconInfo(8, 9, userBitmap);
//
// Image data for password
//
const uint8_t PROGMEM passwordIcon[] =
{
0x0E, 0x00, // ###
0x1B, 0x00, // ## ##
0x11, 0x00, // # #
0x11, 0x00, // # #
0x7F, 0xC0, // #########
0x71, 0xC0, // ### ###
0x71, 0xC0, // ### ###
0x7B, 0xC0, // #### ####
0x7B, 0xC0, // #### ####
0x7F, 0xC0, // #########
0x00, 0x00, //
0xEE, 0xE0, // ### ### ###
0xAA, 0xA0, // # # # # # #
0x22, 0x20, // # # #
0x44, 0x40, // # # #
0x00, 0x00, //
0x44, 0x40, // # # #
};
const BITMAP_INFO passwordIconInfo(11, 17, passwordIcon);

View File

@ -156,3 +156,5 @@ extern const BITMAP_INFO OutputIconInfo;
extern const BITMAP_INFO _1IconInfo; extern const BITMAP_INFO _1IconInfo;
extern const BITMAP_INFO _2IconInfo; extern const BITMAP_INFO _2IconInfo;
extern const BITMAP_INFO algIconInfo; extern const BITMAP_INFO algIconInfo;
extern const BITMAP_INFO passwordIconInfo;

View File

@ -388,6 +388,7 @@ sUserSettings::load()
validatedLoad("JSONpad", JSON.padding, 0, u8inBounds, 0, 1); validatedLoad("JSONpad", JSON.padding, 0, u8inBounds, 0, 1);
validatedLoad("menuMode", menuMode, 0, u8inBounds, 0, 2); validatedLoad("menuMode", menuMode, 0, u8inBounds, 0, 2);
validatedLoad("Clock12hr", clock12hr, 0, u8inBounds, 0, 1); validatedLoad("Clock12hr", clock12hr, 0, u8inBounds, 0, 1);
validatedLoad("holdPassword", holdPassword, 0, u8inBounds, 0, 1);
preferences.end(); preferences.end();
} }
@ -421,6 +422,7 @@ sUserSettings::save()
preferences.putUChar("JSONpad", JSON.padding); preferences.putUChar("JSONpad", JSON.padding);
preferences.putUChar("menuMode", menuMode); preferences.putUChar("menuMode", menuMode);
preferences.putUChar("Clock12hr", clock12hr); preferences.putUChar("Clock12hr", clock12hr);
preferences.putUChar("holdPassword", holdPassword);
preferences.end(); preferences.end();
} }

View File

@ -266,6 +266,7 @@ struct sUserSettings : public CESP32_NVStorage {
sJSONoptions JSON; sJSONoptions JSON;
uint8_t menuMode; // 0 normal, 1, basic, 2 no heater uint8_t menuMode; // 0 normal, 1, basic, 2 no heater
uint8_t clock12hr; uint8_t clock12hr;
uint8_t holdPassword;
bool valid() { bool valid() {
bool retval = true; bool retval = true;
@ -309,6 +310,7 @@ struct sUserSettings : public CESP32_NVStorage {
JSON.init(); JSON.init();
menuMode = 0; menuMode = 0;
clock12hr = 0; clock12hr = 0;
holdPassword = 0;
}; };
void load(); void load();
void save(); void save();
@ -333,6 +335,7 @@ struct sUserSettings : public CESP32_NVStorage {
JSON = rhs.JSON; JSON = rhs.JSON;
menuMode = rhs.menuMode; menuMode = rhs.menuMode;
clock12hr = rhs.clock12hr; clock12hr = rhs.clock12hr;
holdPassword = rhs.holdPassword;
return *this; return *this;
} }
}; };