Kiibohd Controller
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

cli.h 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* Copyright (C) 2014-2015 by Jacob Alexander
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. */
  21. #ifndef cli_h__
  22. #define cli_h__
  23. // ----- Includes -----
  24. // Compiler Includes
  25. #include <Lib/MainLib.h>
  26. // Project Includes
  27. #include <output_com.h>
  28. // ----- Defines -----
  29. #define CLILineBufferMaxSize 100
  30. #define CLIMaxDictionaries 10
  31. #define CLIEntryTabAlign 13
  32. #define CLIMaxHistorySize 10
  33. // ----- Macros -----
  34. // AVR CLI Dictionary definitions (has to deal with the annoying PROGMEM
  35. // Only using PROGMEM with descriptions (all the string comparison tools need to be re-written otherwise)
  36. #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
  37. #define CLIDict_Def(name,description) \
  38. const PROGMEM char name##Name[] = description; \
  39. const CLIDictItem name[]
  40. #define CLIDict_Item(name) \
  41. { #name, name##CLIDict_DescEntry, (const void (*)(char*))cliFunc_##name }
  42. #define CLIDict_Entry(name,description) \
  43. const PROGMEM char name##CLIDict_DescEntry[] = description;
  44. // ARM is easy :P
  45. #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_) // ARM
  46. #define CLIDict_Def(name,description) \
  47. const char name##Name[] = description; \
  48. const CLIDictItem name[]
  49. #define CLIDict_Item(name) \
  50. { #name, name##CLIDict_DescEntry, (const void (*)(char*))cliFunc_##name }
  51. #define CLIDict_Entry(name,description) \
  52. const char name##CLIDict_DescEntry[] = description;
  53. #endif
  54. #define RING_PREV(i) CLI_wrap(i - 1, 0, CLIMaxHistorySize - 1)
  55. #define RING_NEXT(i) CLI_wrap(i + 1, 0, CLIMaxHistorySize - 1)
  56. // ----- Structs -----
  57. // Each item has a name, description, and function pointer with an argument for arguments
  58. typedef struct CLIDictItem {
  59. const char* name;
  60. const char* description;
  61. const void (*function)(char*);
  62. } CLIDictItem;
  63. // ----- Variables -----
  64. char CLILineBuffer[CLILineBufferMaxSize+1]; // +1 for an additional NULL
  65. uint8_t CLILineBufferCurrent;
  66. // Main command dictionary
  67. CLIDictItem *CLIDict [CLIMaxDictionaries];
  68. char* CLIDictNames[CLIMaxDictionaries];
  69. uint8_t CLIDictionariesUsed;
  70. // History
  71. char CLIHistoryBuffer[CLIMaxHistorySize][CLILineBufferMaxSize];
  72. uint8_t CLIHistoryHead;
  73. uint8_t CLIHistoryTail;
  74. int8_t CLIHistoryCurrent;
  75. // Debug
  76. uint8_t CLILEDState;
  77. uint8_t CLIHexDebugMode;
  78. // ----- Functions and Corresponding Function Aliases -----
  79. void CLI_init();
  80. void CLI_process();
  81. void CLI_registerDictionary( const CLIDictItem *cmdDict, const char* dictName );
  82. void CLI_argumentIsolation( char* string, char** first, char** second );
  83. int CLI_wrap( int x, int low, int high );
  84. void CLI_commandLookup();
  85. void CLI_tabCompletion();
  86. void CLI_saveHistory( char *buff );
  87. void CLI_retreiveHistory( int index );
  88. // CLI Command Functions
  89. void cliFunc_arch ( char* args );
  90. void cliFunc_chip ( char* args );
  91. void cliFunc_clear ( char* args );
  92. void cliFunc_cliDebug( char* args );
  93. void cliFunc_device ( char* args );
  94. void cliFunc_help ( char* args );
  95. void cliFunc_led ( char* args );
  96. void cliFunc_reload ( char* args );
  97. void cliFunc_reset ( char* args );
  98. void cliFunc_restart ( char* args );
  99. void cliFunc_version ( char* args );
  100. #endif