Talk is cheap, show me some code...
Here it is, the skeleton of the interpreter
// Ugly Token Player
while ( (EEprom_Addr < FLASH_SIZE) && !End_of_Script ) {
c = Ext_EEpromRead( EEprom_Addr);
switch (c) {
case 0xff:
!End_of_Script = TRUE ; break;
case 0x00: // end of command
Last_EEprom_Addr = EEprom_Addr; break; // save this address for
// eveventual return
case 0xA5: // Set Default Delay
Default_Delay = Ext_EEpromRead16 (EEprom_Addr +1); // read value
if (Default_Delay==0) // check range
Default_Delay = INIT_DEFAULT_DELAY; //
//Last_EEprom_Addr = EEprom_Addr; // advance address
EEprom_Addr +=2; //
case 0xA6: // Delay
Time_to_Delay = Ext_EEpromRead16 (EEprom_Addr +1);
if (Time_to_Delay==0) // check range
Time_to_Delay = INIT_DEFAULT_DELAY; //
//Last_EEprom_Addr = EEprom_Addr; // advance address
EEprom_Addr +=2; //
case 0xA7: // Replay last command
if (Replaying) {
EEprom_Addr = Last_EEprom_Addr;
Replay_Counter--;
if (Replay_Counter ==0) { // replay is over!
EEprom_Addr += 3 ; // skip to the next command
Replaying = RALSE;
}
} else {
Replaying = TRUE;
Replay_Counter = Ext_EEpromRead16 (EEprom_Addr +1);
if (Replay_Counter==0) // check range
Replay_Counter = 1; //
EEprom_Addr = Last_EEprom_Addr; // rewind address
}
case 0xA8: // Hold Shift
0xA9: // Hold ALT
0xAA: // Hold CONTROL
0xAB: // Hold GUI
Hold_Next_Key = 1; break ; // Just hold the next key
default: // Send the character
digiKeyboard.sendKeyPress(c);
if (Hold_Next_Key) // If next key should remain hold
Hold_Next_Key = 0; // then do nothing
else { //
digiKeyboard.sendKeyPress(0); // otherwise, send a release of
digiKeyboard.delay(Default_Delay); // all key presses
}
EEprom_Addr++; // advance to the next character
}
}
for (;;); // do nothing after playing the script
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.