@ -20,41 +20,37 @@
# include <Kaleidoscope-EEPROM-Keymap.h>
# include <Kaleidoscope-EEPROM-Keymap.h>
# include <Kaleidoscope-Focus.h>
# include <Kaleidoscope-Focus.h>
namespace KaleidoscopePlugins {
namespace kaleidoscope {
uint16_t EEPROMKeymap : : keymap Base ;
uint16_t EEPROMKeymap : : keymap _base_ ;
uint8_t EEPROMKeymap : : max Layers ;
uint8_t EEPROMKeymap : : max _layers_ ;
EEPROMKeymap : : EEPROMKeymap ( void ) {
EEPROMKeymap : : EEPROMKeymap ( void ) {
}
}
void
void EEPROMKeymap : : begin ( void ) {
EEPROMKeymap : : begin ( void ) {
USE_PLUGINS ( & : : EEPROMSettings ) ;
USE_PLUGINS ( & : : EEPROMSettings ) ;
}
}
void
void EEPROMKeymap : : max_layers ( uint8_t max ) {
EEPROMKeymap : : reserveSpace ( uint8_t layers ) {
max_layers_ = max ;
maxLayers = layers ;
keymap_base_ = : : EEPROMSettings . requestSlice ( max_layers_ * ROWS * COLS * 2 ) ;
keymapBase = : : EEPROMSettings . requestSlice ( maxLayers * ROWS * COLS * 2 ) ;
}
}
Key
Key EEPROMKeymap : : getKey ( uint8_t layer , byte row , byte col ) {
EEPROMKeymap : : getKey ( uint8_t layer , byte row , byte col ) {
Key key ;
Key key ;
if ( layer > = max Layers )
if ( layer > = max _layers_ )
return Key_NoKey ;
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 . flags = EEPROM . read ( keymap_base_ + pos ) ;
key . keyCode = EEPROM . read ( keymapBase + pos + 1 ) ;
key . keyCode = EEPROM . read ( keymap_base_ + pos + 1 ) ;
return key ;
return key ;
}
}
Key
Key EEPROMKeymap : : getKeyOverride ( uint8_t layer , byte row , byte col ) {
EEPROMKeymap : : getKeyOverride ( uint8_t layer , byte row , byte col ) {
Key key ;
Key key ;
key = getKey ( layer , row , col ) ;
key = getKey ( layer , row , col ) ;
@ -63,19 +59,16 @@ EEPROMKeymap::getKeyOverride (uint8_t layer, byte row, byte col) {
return key ;
return key ;
}
}
uint16_t
uint16_t EEPROMKeymap : : keymap_base ( void ) {
EEPROMKeymap : : base ( void ) {
return keymap_base_ ;
return keymapBase ;
}
}
void
void EEPROMKeymap : : updateKey ( uint16_t base_pos , Key key ) {
EEPROMKeymap : : updateKey ( uint16_t basePos , Key key ) {
EEPROM . update ( keymap_base_ + base_pos * 2 , key . flags ) ;
EEPROM . update ( keymapBase + basePos * 2 , key . flags ) ;
EEPROM . update ( keymap_base_ + base_pos * 2 + 1 , key . keyCode ) ;
EEPROM . update ( keymapBase + basePos * 2 + 1 , key . keyCode ) ;
}
}
Key
Key EEPROMKeymap : : parseKey ( void ) {
EEPROMKeymap : : parseKey ( void ) {
Key key ;
Key key ;
key . raw = Serial . parseInt ( ) ;
key . raw = Serial . parseInt ( ) ;
@ -83,18 +76,16 @@ EEPROMKeymap::parseKey (void) {
return key ;
return key ;
}
}
void
void EEPROMKeymap : : printKey ( Key k ) {
EEPROMKeymap : : printKey ( Key k ) {
: : Focus . printNumber ( k . raw ) ;
: : Focus . printNumber ( k . raw ) ;
}
}
bool
bool EEPROMKeymap : : focusKeymap ( const char * command ) {
EEPROMKeymap : : focusKeymap ( const char * command ) {
if ( strcmp_P ( command , PSTR ( " keymap.map " ) ) ! = 0 )
if ( strcmp_P ( command , PSTR ( " keymap.map " ) ) ! = 0 )
return false ;
return false ;
if ( Serial . peek ( ) = = ' \n ' ) {
if ( Serial . peek ( ) = = ' \n ' ) {
for ( uint8_t layer = 0 ; layer < max Layers ; layer + + ) {
for ( uint8_t layer = 0 ; layer < max _layers_ ; layer + + ) {
for ( uint8_t row = 0 ; row < ROWS ; row + + ) {
for ( uint8_t row = 0 ; row < ROWS ; row + + ) {
for ( uint8_t col = 0 ; col < COLS ; col + + ) {
for ( uint8_t col = 0 ; col < COLS ; col + + ) {
Key k = getKey ( layer , row , col ) ;
Key k = getKey ( layer , row , col ) ;
@ -107,7 +98,7 @@ EEPROMKeymap::focusKeymap (const char *command) {
Serial . println ( ) ;
Serial . println ( ) ;
} else {
} else {
uint16_t i = 0 ;
uint16_t i = 0 ;
while ( ( Serial . peek ( ) ! = ' \n ' ) & & ( i < ROWS * COLS * max Layers ) ) {
while ( ( Serial . peek ( ) ! = ' \n ' ) & & ( i < ROWS * COLS * max _layers_ ) ) {
updateKey ( i , parseKey ( ) ) ;
updateKey ( i , parseKey ( ) ) ;
i + + ;
i + + ;
}
}
@ -116,8 +107,7 @@ EEPROMKeymap::focusKeymap (const char *command) {
return true ;
return true ;
}
}
bool
bool EEPROMKeymap : : focusKeymapTransfer ( const char * command ) {
EEPROMKeymap : : focusKeymapTransfer ( const char * command ) {
if ( strcmp_P ( command , PSTR ( " keymap.transfer " ) ) ! = 0 )
if ( strcmp_P ( command , PSTR ( " keymap.transfer " ) ) ! = 0 )
return false ;
return false ;
@ -135,6 +125,6 @@ EEPROMKeymap::focusKeymapTransfer (const char *command) {
return true ;
return true ;
}
}
} ;
}
KaleidoscopePlugins : : EEPROMKeymap EEPROMKeymap ;
kaleidoscope : : EEPROMKeymap EEPROMKeymap ;