@ -29,15 +29,12 @@ uint16_t EscapeOneShotConfig::settings_base_;
EventHandlerResult EscapeOneShotConfig : : onSetup ( ) {
EventHandlerResult EscapeOneShotConfig : : onSetup ( ) {
settings_base_ = : : EEPROMSettings . requestSlice ( sizeof ( EscapeOneShot : : settings_ ) ) ;
settings_base_ = : : EEPROMSettings . requestSlice ( sizeof ( EscapeOneShot : : settings_ ) ) ;
struct {
uint16_t checker ;
uint8_t b ;
uint16_t w ;
} checker ;
Runtime . storage ( ) . get ( settings_base_ , checker ) ;
Runtime . storage ( ) . get ( settings_base_ , checker ) ;
// Check if we have an empty eeprom...
// Check if we have an empty eeprom...
if ( checker . b = = 0xff & & checker . w = = 0xffff ) {
if ( checker = = 0xffff ) {
// ...if the eeprom was empty, store the default settings.
// ...if the eeprom was empty, store the default settings.
Runtime . storage ( ) . put ( settings_base_ , EscapeOneShot : : settings_ ) ;
Runtime . storage ( ) . put ( settings_base_ , EscapeOneShot : : settings_ ) ;
Runtime . storage ( ) . commit ( ) ;
Runtime . storage ( ) . commit ( ) ;
@ -52,48 +49,18 @@ EventHandlerResult EscapeOneShotConfig::onNameQuery() {
}
}
EventHandlerResult EscapeOneShotConfig : : onFocusEvent ( const char * command ) {
EventHandlerResult EscapeOneShotConfig : : onFocusEvent ( const char * command ) {
enum {
if ( : : Focus . handleHelp ( command , PSTR ( " escape_oneshot.cancel_key " ) ) )
ENABLED ,
CANCEL_KEY
} subCommand ;
if ( : : Focus . handleHelp ( command , PSTR ( " escape_oneshot.enabled \n "
" escape_oneshot.cancel_key " ) ) )
return EventHandlerResult : : OK ;
return EventHandlerResult : : OK ;
if ( strncmp_P ( command , PSTR ( " escape_oneshot. " ) , 15 ) ! = 0 )
if ( strcmp_P ( command , PSTR ( " escape_oneshot.cancel_key " ) ) ! = 0 )
return EventHandlerResult : : OK ;
if ( strcmp_P ( command + 15 , PSTR ( " enabled " ) ) = = 0 )
subCommand = ENABLED ;
else if ( strcmp_P ( command + 15 , PSTR ( " cancel_key " ) ) = = 0 )
subCommand = CANCEL_KEY ;
else
return EventHandlerResult : : OK ;
return EventHandlerResult : : OK ;
switch ( subCommand ) {
if ( : : Focus . isEOL ( ) ) {
case ENABLED :
: : Focus . send ( : : EscapeOneShot . getCancelKey ( ) ) ;
if ( : : Focus . isEOL ( ) ) {
} else {
: : Focus . send ( : : EscapeOneShot . isEnabled ( ) ) ;
Key k ;
} else {
: : Focus . read ( k ) ;
uint8_t v ;
: : EscapeOneShot . setCancelKey ( k ) ;
: : Focus . read ( v ) ;
if ( v ! = 0 ) {
: : EscapeOneShot . enable ( ) ;
} else {
: : EscapeOneShot . disable ( ) ;
}
}
break ;
case CANCEL_KEY :
if ( : : Focus . isEOL ( ) ) {
: : Focus . send ( : : EscapeOneShot . getCancelKey ( ) ) ;
} else {
Key k ;
: : Focus . read ( k ) ;
: : EscapeOneShot . setCancelKey ( k ) ;
}
break ;
}
}
Runtime . storage ( ) . put ( settings_base_ , EscapeOneShot : : settings_ ) ;
Runtime . storage ( ) . put ( settings_base_ , EscapeOneShot : : settings_ ) ;