// ----- Includes -----
-// Compiler Includes
-//#include <stdarg.h>
-
// Project Includes
#include <buildvars.h>
#include "cli.h"
#include <led.h>
#include <print.h>
+#include <kll_defs.h>
// Check for control characters
switch ( CLILineBuffer[prev_buf_pos] )
{
- case 0x0D: // Enter
+ // Enter
+ case 0x0A: // LF
+ case 0x0D: // CR
CLILineBuffer[CLILineBufferCurrent - 1] = ' '; // Replace Enter with a space (resolves a bug in args)
// Remove the space if there is no command
if ( CLILineBufferCurrent == 1 )
+ {
CLILineBufferCurrent--;
+ }
+ else
+ {
+ // Add the command to the history
+ CLI_saveHistory( CLILineBuffer );
- // Process the current line buffer
- CLI_commandLookup();
+ // Process the current line buffer
+ CLI_commandLookup();
- // Add the command to the history
- cli_saveHistory(CLILineBuffer);
+ // Keep the array circular, discarding the older entries
+ if ( CLIHistoryTail < CLIHistoryHead )
+ CLIHistoryHead = ( CLIHistoryHead + 1 ) % CLIMaxHistorySize;
+ CLIHistoryTail++;
+ if ( CLIHistoryTail == CLIMaxHistorySize )
+ {
+ CLIHistoryTail = 0;
+ CLIHistoryHead = 1;
+ }
- // Keep the array circular, discarding the older entries
- if (CLIHistoryTail < CLIHistoryHead)
- CLIHistoryHead = (CLIHistoryHead+1)%CLIMaxHistorySize;
- CLIHistoryTail++;
- if (CLIHistoryTail==CLIMaxHistorySize)
- {
- CLIHistoryTail = 0;
- CLIHistoryHead = 1;
- }
+ CLIHistoryCurrent = CLIHistoryTail; // 'Up' starts at the last item
+ CLI_saveHistory( NULL ); // delete the old temp buffer
- CLIHistoryCurrent = CLIHistoryTail; // 'Up' starts at the last item
- cli_saveHistory(NULL); // delete the old temp buffer
+ }
// Reset the buffer
CLILineBufferCurrent = 0;
case 0x1B: // Esc / Escape codes
// Check for other escape sequence
- // \e[ is an escape code in vt100 compatable terminals
- if (CLILineBufferCurrent>=prev_buf_pos+3
- && CLILineBuffer[prev_buf_pos]==0x1B
- && CLILineBuffer[prev_buf_pos+1]==0x5B)
+ // \e[ is an escape code in vt100 compatible terminals
+ if ( CLILineBufferCurrent >= prev_buf_pos + 3
+ && CLILineBuffer[ prev_buf_pos ] == 0x1B
+ && CLILineBuffer[ prev_buf_pos + 1] == 0x5B )
{
// Arrow Keys: A (0x41) = Up, B (0x42) = Down, C (0x43) = Right, D (0x44) = Left
- if (CLILineBuffer[prev_buf_pos+2]==0x41) // Hist prev
+ if ( CLILineBuffer[ prev_buf_pos + 2 ] == 0x41 ) // Hist prev
{
- if (CLIHistoryCurrent==CLIHistoryTail)
+ if ( CLIHistoryCurrent == CLIHistoryTail )
{
// Is first time pressing arrow. Save the current buffer
- CLILineBuffer[prev_buf_pos] = '\0';
- cli_saveHistory(CLILineBuffer);
+ CLILineBuffer[ prev_buf_pos ] = '\0';
+ CLI_saveHistory( CLILineBuffer );
}
// Grab the previus item from the history if there is one
- if (RING_PREV(CLIHistoryCurrent)!=RING_PREV(CLIHistoryHead))
- CLIHistoryCurrent = RING_PREV(CLIHistoryCurrent);
- cli_retreiveHistory(CLIHistoryCurrent);
+ if ( RING_PREV( CLIHistoryCurrent ) != RING_PREV( CLIHistoryHead ) )
+ CLIHistoryCurrent = RING_PREV( CLIHistoryCurrent );
+ CLI_retreiveHistory( CLIHistoryCurrent );
}
- if (CLILineBuffer[prev_buf_pos+2]==0x42) // Hist next
+ if ( CLILineBuffer[ prev_buf_pos + 2 ] == 0x42 ) // Hist next
{
// Grab the next item from the history if it exists
- if (RING_NEXT(CLIHistoryCurrent)!=RING_NEXT(CLIHistoryTail))
- CLIHistoryCurrent = RING_NEXT(CLIHistoryCurrent);
- cli_retreiveHistory(CLIHistoryCurrent);
+ if ( RING_NEXT( CLIHistoryCurrent ) != RING_NEXT( CLIHistoryTail ) )
+ CLIHistoryCurrent = RING_NEXT( CLIHistoryCurrent );
+ CLI_retreiveHistory( CLIHistoryCurrent );
}
}
return;
}
}
-inline int wrap(int kX, int const kLowerBound, int const kUpperBound)
+inline int CLI_wrap( int kX, int const kLowerBound, int const kUpperBound )
{
int range_size = kUpperBound - kLowerBound + 1;
- if (kX < kLowerBound)
+ if ( kX < kLowerBound )
kX += range_size * ((kLowerBound - kX) / range_size + 1);
return kLowerBound + (kX - kLowerBound) % range_size;
}
-inline void cli_saveHistory(char *buff) {
- if (buff==NULL) {
+inline void CLI_saveHistory( char *buff )
+{
+ if ( buff == NULL )
+ {
//clear the item
- CLIHistoryBuffer[CLIHistoryTail][0] = '\0';
+ CLIHistoryBuffer[ CLIHistoryTail ][ 0 ] = '\0';
return;
}
+ // Don't write empty lines to the history
+ const char *cursor = buff;
+ while (*cursor == ' ') { cursor++; } // advance past the leading whitespace
+ if (*cursor == '\0') { return ; }
+
// Copy the line to the history
int i;
- for (i=0; i<CLILineBufferCurrent; i++)
+ for (i = 0; i < CLILineBufferCurrent; i++)
{
- CLIHistoryBuffer[CLIHistoryTail][i] = CLILineBuffer[i];
+ CLIHistoryBuffer[ CLIHistoryTail ][ i ] = CLILineBuffer[ i ];
}
}
-void cli_retreiveHistory(int index) {
- char *histMatch = CLIHistoryBuffer[index];
+void CLI_retreiveHistory( int index )
+{
+ char *histMatch = CLIHistoryBuffer[ index ];
// Reset the buffer
CLILineBufferCurrent = 0;
CLILineBufferCurrent = 0;
while ( *histMatch != '\0' )
{
- CLILineBuffer[CLILineBufferCurrent++] = *histMatch++;
+ CLILineBuffer[ CLILineBufferCurrent++ ] = *histMatch++;
}
}
void cliFunc_reload( char* args )
{
+ if ( flashModeEnabled_define == 0 )
+ {
+ print( NL );
+ warn_print("flashModeEnabled not set, cancelling firmware reload...");
+ info_msg("Set flashModeEnabled to 1 in your kll configuration.");
+ return;
+ }
+
// Request to output module to be set into firmware reload mode
Output_firmwareReload();
}
print( " \033[1mCPU:\033[0m " CLI_CPU NL );
print( " \033[1mDevice:\033[0m " CLI_Device NL );
print( " \033[1mModules:\033[0m " CLI_Modules NL );
+#if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
+ print( " \033[1mUnique Id:\033[0m " );
+ printHex32_op( SIM_UIDH, 4 );
+ printHex32_op( SIM_UIDMH, 4 );
+ printHex32_op( SIM_UIDML, 4 );
+ printHex32_op( SIM_UIDL, 4 );
+#elif defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
+#else
+#error "No unique id defined."
+#endif
}