@ -20,121 +20,111 @@
# include <Kaleidoscope-EEPROM-Keymap.h>
# include <Kaleidoscope-Focus.h>
namespace KaleidoscopePlugins {
uint16_t EEPROMKeymap : : keymap Base ;
uint8_t EEPROMKeymap : : max Layers ;
namespace kaleidoscope {
uint16_t EEPROMKeymap : : keymap _base_ ;
uint8_t EEPROMKeymap : : max _layers_ ;
EEPROMKeymap : : EEPROMKeymap ( void ) {
EEPROMKeymap : : EEPROMKeymap ( void ) {
}
void
EEPROMKeymap : : begin ( void ) {
USE_PLUGINS ( & : : EEPROMSettings ) ;
void EEPROMKeymap : : begin ( void ) {
USE_PLUGINS ( & : : EEPROMSettings ) ;
}
void
EEPROMKeymap : : reserveSpace ( uint8_t layers ) {
maxLayers = layers ;
keymapBase = : : EEPROMSettings . requestSlice ( maxLayers * ROWS * COLS * 2 ) ;
void EEPROMKeymap : : max_layers ( uint8_t max ) {
max_layers_ = max ;
keymap_base_ = : : EEPROMSettings . requestSlice ( max_layers_ * ROWS * COLS * 2 ) ;
}
Key
EEPROMKeymap : : getKey ( uint8_t layer , byte row , byte col ) {
Key key ;
Key EEPROMKeymap : : getKey ( uint8_t layer , byte row , byte col ) {
Key key ;
if ( layer > = max Layers )
return Key_NoKey ;
if ( layer > = max _layers_ )
return Key_NoKey ;
uint16_t pos = ( ( layer * ROWS * COLS ) + ( row * COLS ) + col ) * 2 ;
uint16_t pos = ( ( layer * ROWS * COLS ) + ( row * COLS ) + col ) * 2 ;
key . flags = EEPROM . read ( keymapBase + pos ) ;
key . keyCode = EEPROM . read ( keymapBase + pos + 1 ) ;
key . flags = EEPROM . read ( keymap_base_ + pos ) ;
key . keyCode = EEPROM . read ( keymap_base_ + pos + 1 ) ;
return key ;
return key ;
}
Key
EEPROMKeymap : : getKeyOverride ( uint8_t layer , byte row , byte col ) {
Key key ;
Key EEPROMKeymap : : getKeyOverride ( uint8_t layer , byte row , byte col ) {
Key key ;
key = getKey ( layer , row , col ) ;
if ( key = = Key_Transparent )
key = Layer . getKeyFromPROGMEM ( layer , row , col ) ;
return key ;
key = getKey ( layer , row , col ) ;
if ( key = = Key_Transparent )
key = Layer . getKeyFromPROGMEM ( layer , row , col ) ;
return key ;
}
uint16_t
EEPROMKeymap : : base ( void ) {
return keymapBase ;
uint16_t EEPROMKeymap : : keymap_base ( void ) {
return keymap_base_ ;
}
void
EEPROMKeymap : : updateKey ( uint16_t basePos , Key key ) {
EEPROM . update ( keymapBase + basePos * 2 , key . flags ) ;
EEPROM . update ( keymapBase + basePos * 2 + 1 , key . keyCode ) ;
void EEPROMKeymap : : updateKey ( uint16_t base_pos , Key key ) {
EEPROM . update ( keymap_base_ + base_pos * 2 , key . flags ) ;
EEPROM . update ( keymap_base_ + base_pos * 2 + 1 , key . keyCode ) ;
}
Key
EEPROMKeymap : : parseKey ( void ) {
Key key ;
Key EEPROMKeymap : : parseKey ( void ) {
Key key ;
key . raw = Serial . parseInt ( ) ;
key . raw = Serial . parseInt ( ) ;
return key ;
return key ;
}
void
EEPROMKeymap : : printKey ( Key k ) {
: : Focus . printNumber ( k . raw ) ;
void EEPROMKeymap : : printKey ( Key k ) {
: : Focus . printNumber ( k . raw ) ;
}
bool
EEPROMKeymap : : focusKeymap ( const char * command ) {
if ( strcmp_P ( command , PSTR ( " keymap.map " ) ) ! = 0 )
return false ;
if ( Serial . peek ( ) = = ' \n ' ) {
for ( uint8_t layer = 0 ; layer < maxLayers ; layer + + ) {
for ( uint8_t row = 0 ; row < ROWS ; row + + ) {
for ( uint8_t col = 0 ; col < COLS ; col + + ) {
Key k = getKey ( layer , row , col ) ;
printKey ( k ) ;
: : Focus . printSpace ( ) ;
}
}
}
Serial . println ( ) ;
} else {
uint16_t i = 0 ;
while ( ( Serial . peek ( ) ! = ' \n ' ) & & ( i < ROWS * COLS * maxLayers ) ) {
updateKey ( i , parseKey ( ) ) ;
i + + ;
bool EEPROMKeymap : : focusKeymap ( const char * command ) {
if ( strcmp_P ( command , PSTR ( " keymap.map " ) ) ! = 0 )
return false ;
if ( Serial . peek ( ) = = ' \n ' ) {
for ( uint8_t layer = 0 ; layer < max_layers_ ; layer + + ) {
for ( uint8_t row = 0 ; row < ROWS ; row + + ) {
for ( uint8_t col = 0 ; col < COLS ; col + + ) {
Key k = getKey ( layer , row , col ) ;
printKey ( k ) ;
: : Focus . printSpace ( ) ;
}
}
}
Serial . println ( ) ;
} else {
uint16_t i = 0 ;
while ( ( Serial . peek ( ) ! = ' \n ' ) & & ( i < ROWS * COLS * max_layers_ ) ) {
updateKey ( i , parseKey ( ) ) ;
i + + ;
}
}
return true ;
return true ;
}
bool
EEPROMKeymap : : focusKeymapTransfer ( const char * command ) {
if ( strcmp_P ( command , PSTR ( " keymap.transfer " ) ) ! = 0 )
return false ;
bool EEPROMKeymap : : focusKeymapTransfer ( const char * command ) {
if ( strcmp_P ( command , PSTR ( " keymap.transfer " ) ) ! = 0 )
return false ;
uint8_t layer = Serial . parseInt ( ) ;
uint8_t layer = Serial . parseInt ( ) ;
for ( uint8_t row = 0 ; row < ROWS ; row + + ) {
for ( uint8_t col = 0 ; col < COLS ; col + + ) {
Key k = Layer . getKeyFromPROGMEM ( layer , row , col ) ;
uint16_t pos = ( ( layer * ROWS * COLS ) + ( row * COLS ) + col ) ;
for ( uint8_t row = 0 ; row < ROWS ; row + + ) {
for ( uint8_t col = 0 ; col < COLS ; col + + ) {
Key k = Layer . getKeyFromPROGMEM ( layer , row , col ) ;
uint16_t pos = ( ( layer * ROWS * COLS ) + ( row * COLS ) + col ) ;
updateKey ( pos , k ) ;
}
updateKey ( pos , k ) ;
}
}
return true ;
return true ;
}
} ;
}
KaleidoscopePlugins : : EEPROMKeymap EEPROMKeymap ;
kaleidoscope : : EEPROMKeymap EEPROMKeymap ;