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.

scan_loop.c 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* Copyright (C) 2014 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. // ----- Includes -----
  22. // Compiler Includes
  23. #include <Lib/ScanLib.h>
  24. // Project Includes
  25. #include <cli.h>
  26. #include <led.h>
  27. #include <print.h>
  28. #include <matrix_scan.h>
  29. // Local Includes
  30. #include "scan_loop.h"
  31. #include "macro.h"
  32. // ----- Function Declarations -----
  33. // CLI Functions
  34. void cliFunc_echo( char* args );
  35. // ----- Variables -----
  36. // Scan Module command dictionary
  37. const char scanCLIDictName[] = "Scan Module Commands";
  38. const CLIDictItem scanCLIDict[] = {
  39. { "echo", "Example command, echos the arguments.", cliFunc_echo },
  40. { 0, 0, 0 } // Null entry for dictionary end
  41. };
  42. // Number of scans since the last USB send
  43. uint16_t Scan_scanCount = 0;
  44. // ----- Functions -----
  45. // Setup
  46. inline void Scan_setup()
  47. {
  48. // Register Scan CLI dictionary
  49. CLI_registerDictionary( scanCLIDict, scanCLIDictName );
  50. // Setup GPIO pins for matrix scanning
  51. Matrix_setup();
  52. // Reset scan count
  53. Scan_scanCount = 0;
  54. }
  55. // Main Detection Loop
  56. inline uint8_t Scan_loop()
  57. {
  58. Matrix_scan( Scan_scanCount++ );
  59. return 0;
  60. }
  61. // Signal from Macro Module that all keys have been processed (that it knows about)
  62. inline void Scan_finishedWithMacro( uint8_t sentKeys )
  63. {
  64. }
  65. // Signal from Output Module that all keys have been processed (that it knows about)
  66. inline void Scan_finishedWithOutput( uint8_t sentKeys )
  67. {
  68. // Reset scan loop indicator (resets each key debounce state)
  69. // TODO should this occur after USB send or Macro processing?
  70. Scan_scanCount = 0;
  71. }
  72. // ----- CLI Command Functions -----
  73. // XXX Just an example command showing how to parse arguments (more complex than generally needed)
  74. void cliFunc_echo( char* args )
  75. {
  76. char* curArgs;
  77. char* arg1Ptr;
  78. char* arg2Ptr = args;
  79. // Parse args until a \0 is found
  80. while ( 1 )
  81. {
  82. print( NL ); // No \r\n by default after the command is entered
  83. curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list
  84. CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
  85. // Stop processing args if no more are found
  86. if ( *arg1Ptr == '\0' )
  87. break;
  88. // Print out the arg
  89. dPrint( arg1Ptr );
  90. }
  91. }