@ -17,20 +17,32 @@
*/
# include <Kaleidoscope-TypingBreaks.h>
# include <Kaleidoscope-EEPROM-Settings.h>
# include <Kaleidoscope-Focus.h>
namespace KaleidoscopePlugins {
#if 0
uint32_t TypingBreaks : : settings : : idleTimeLimit = 10000 ; // 10s
uint32_t TypingBreaks : : settings : : lockTimeOut = 2700000 ; // 45m
uint32_t TypingBreaks : : settings : : lockLength = 300000 ; // 5m
uint16_t TypingBreaks : : settings : : leftHandMaxKeys ;
uint16_t TypingBreaks : : settings : : rightHandMaxKeys ;
# else
TypingBreaks : : settings_t TypingBreaks : : settings = {
. idleTimeLimit = 10000 ,
. lockTimeOut = 2700000 ,
. lockLength = 300000 ,
. leftHandMaxKeys = 0 ,
. rightHandMaxKeys = 0
} ;
# endif
uint32_t TypingBreaks : : sessionStartTime ;
uint32_t TypingBreaks : : lastKeyTime ;
uint32_t TypingBreaks : : lockStartTime ;
uint16_t TypingBreaks : : leftHandKeys ;
uint16_t TypingBreaks : : rightHandKeys ;
uint16_t TypingBreaks : : settingsBase ;
TypingBreaks : : TypingBreaks ( void ) {
}
@ -102,6 +114,88 @@ namespace KaleidoscopePlugins {
return mappedKey ;
}
void
TypingBreaks : : enableEEPROM ( void ) {
settingsBase = : : EEPROMSettings . requestSlice ( sizeof ( settings ) ) ;
// If idleTime is max, assume that EEPROM is uninitialized, and store the
// defaults.
uint32_t idleTime ;
EEPROM . get ( settingsBase , idleTime ) ;
if ( idleTime = = 0xffffffff ) {
EEPROM . put ( settingsBase , settings ) ;
}
EEPROM . get ( settingsBase , settings ) ;
}
bool
TypingBreaks : : focusHook ( const char * command ) {
enum {
IDLE_TIME_LIMIT ,
LOCK_TIMEOUT ,
LOCK_LENGTH ,
LEFT_MAX ,
RIGHT_MAX ,
} subCommand ;
if ( strncmp_P ( command , PSTR ( " typingbreaks. " ) , 13 ) ! = 0 )
return false ;
if ( strcmp_P ( command + 13 , PSTR ( " idleTimeLimit " ) ) = = 0 )
subCommand = IDLE_TIME_LIMIT ;
else if ( strcmp_P ( command + 13 , PSTR ( " lockTimeOut " ) ) = = 0 )
subCommand = LOCK_TIMEOUT ;
else if ( strcmp_P ( command + 13 , PSTR ( " lockLength " ) ) = = 0 )
subCommand = LOCK_LENGTH ;
else if ( strcmp_P ( command + 13 , PSTR ( " leftMaxKeys " ) ) = = 0 )
subCommand = LEFT_MAX ;
else if ( strcmp_P ( command + 13 , PSTR ( " rightMaxKeys " ) ) = = 0 )
subCommand = RIGHT_MAX ;
else
return false ;
switch ( subCommand ) {
case IDLE_TIME_LIMIT :
if ( Serial . peek ( ) = = ' \n ' ) {
Serial . println ( settings . idleTimeLimit ) ;
} else {
settings . idleTimeLimit = Serial . parseInt ( ) ;
}
break ;
case LOCK_TIMEOUT :
if ( Serial . peek ( ) = = ' \n ' ) {
Serial . println ( settings . lockTimeOut ) ;
} else {
settings . lockTimeOut = Serial . parseInt ( ) ;
}
break ;
case LOCK_LENGTH :
if ( Serial . peek ( ) = = ' \n ' ) {
Serial . println ( settings . lockLength ) ;
} else {
settings . lockLength = Serial . parseInt ( ) ;
}
break ;
case LEFT_MAX :
if ( Serial . peek ( ) = = ' \n ' ) {
Serial . println ( settings . leftHandMaxKeys ) ;
} else {
settings . leftHandMaxKeys = Serial . parseInt ( ) ;
}
break ;
case RIGHT_MAX :
if ( Serial . peek ( ) = = ' \n ' ) {
Serial . println ( settings . rightHandMaxKeys ) ;
} else {
settings . rightHandMaxKeys = Serial . parseInt ( ) ;
}
break ;
}
EEPROM . put ( settingsBase , settings ) ;
return true ;
}
} ;
KaleidoscopePlugins : : TypingBreaks TypingBreaks ;