]> git.donarmstrong.com Git - kiibohd-controller.git/blobdiff - Macro/buffer/macro.c
Move matrix information to a cli command
[kiibohd-controller.git] / Macro / buffer / macro.c
index 657ab9105498ba5a0d86680d30acff3c62508b79..9654c90484ac7fb5f41ba3493332b6037d832646 100644 (file)
@@ -1,15 +1,15 @@
-/* Copyright (C) 2011 by Jacob Alexander
- * 
+/* Copyright (C) 2011-2014 by Jacob Alexander
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  * copies of the Software, and to permit persons to whom the Software is
  * furnished to do so, subject to the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice shall be included in
  * all copies or substantial portions of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
 // ----- Includes -----
 
-// AVR Includes
-#include <util/delay.h>
-#include <avr/interrupt.h>
+// Compiler Includes
+#include <Lib/MacroLib.h>
 
 // Project Includes
 #include <led.h>
 #include <print.h>
 #include <scan_loop.h>
-#include <usb_com.h>
+#include <output_com.h>
 
 // Keymaps
 #include <keymap.h>
 static uint8_t Bootloader_ConditionSequence[] = {1,16,6,11};
        uint8_t Bootloader_ConditionState      = 0;
        uint8_t Bootloader_NextPositionReady   = 1;
+       uint8_t Bootloader_KeyDetected         = 0;
 
 
 
 // ----- Functions -----
 
+inline void macro_finishedWithBuffer( uint8_t sentKeys )
+{
+       /* BudKeypad
+       // Boot loader sequence state handler
+       switch ( KeyIndex_BufferUsed )
+       {
+       // The next bootloader key can now be pressed, if there were no keys processed
+       case 0:
+               Bootloader_NextPositionReady = 1;
+               break;
+       // If keys were detected, and it wasn't in the sequence (or there was multiple keys detected), start bootloader sequence over
+       // This case purposely falls through
+       case 1:
+               if ( Bootloader_KeyDetected )
+                       break;
+       default:
+               Bootloader_ConditionState = 0;
+               break;
+       }
+
+       Bootloader_KeyDetected = 0;
+       */
+}
+
 void jumpToBootloader(void)
 {
+#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
        cli();
        // disable watchdog, if enabled
        // disable all peripherals
@@ -86,6 +111,7 @@ void jumpToBootloader(void)
        PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
        asm volatile("jmp 0x1FC00");
 #endif
+#endif
 }
 
 // Given a sampling array, and the current number of detected keypress
@@ -190,6 +216,34 @@ int scancodeMacro( uint8_t scanCode )
        }
        return 1;
        */
+       /*
+       // BudKeypad
+       // Is this a bootloader sequence key?
+       if ( !Bootloader_KeyDetected
+          && Bootloader_NextPositionReady
+          && scanCode == Bootloader_ConditionSequence[Bootloader_ConditionState] )
+       {
+               Bootloader_KeyDetected = 1;
+               Bootloader_NextPositionReady = 0;
+               Bootloader_ConditionState++;
+               erro_dPrint("detect");
+       }
+       else if ( Bootloader_ConditionState > 0 && scanCode == Bootloader_ConditionSequence[Bootloader_ConditionState - 1] )
+       {
+               Bootloader_KeyDetected = 0;
+               Bootloader_NextPositionReady = 1;
+               erro_dPrint("detect-again!");
+       }
+       // Cancel sequence
+       else
+       {
+               Bootloader_KeyDetected = 0;
+               Bootloader_NextPositionReady = 1;
+               Bootloader_ConditionState = 0;
+               erro_dPrint("Arg");
+       }
+       */
+
        return 0;
 }
 
@@ -199,33 +253,61 @@ uint8_t sendCode = 0;
 int usbcodeMacro( uint8_t usbCode )
 {
        // Keyboard Input Test Macro
+       /*
        switch ( usbCode )
        {
        case KEY_F1:
                sendCode--;
-               scan_sendData( 0x90 );
+               //scan_sendData( 0x90 );
                scan_sendData( sendCode );
                _delay_ms( 200 );
                break;
 
        case KEY_F2:
-               scan_sendData( 0x90 );
+               //scan_sendData( 0x90 );
                scan_sendData( sendCode );
                _delay_ms( 200 );
                break;
 
        case KEY_F3:
                sendCode++;
-               scan_sendData( 0x90 );
+               //scan_sendData( 0x90 );
+               scan_sendData( sendCode );
+               _delay_ms( 200 );
+               break;
+
+       case KEY_F4:
+               sendCode += 0x10;
+               //scan_sendData( 0x90 );
                scan_sendData( sendCode );
                _delay_ms( 200 );
                break;
 
+       case KEY_F5:
+               // Set 9th bit to 0
+               UCSR1B &= ~(1 << 0);
+               _delay_ms( 200 );
+               break;
+
+       case KEY_F6:
+               // Set 9th bit to 1
+               UCSR1B |=  (1 << 0);
+               _delay_ms( 200 );
+               break;
+
+       case KEY_F11:
+               // Set click code
+               KeyIndex_Add_InputSignal = sendCode;
+               _delay_ms( 200 );
+               break;
+
        default:
                return 0;
        }
        
        return 1;
+       */
+       return 0;
 }
 
 
@@ -289,8 +371,11 @@ void keyPressBufferRead( uint8_t *modifiers, uint8_t numberOfModifiers, uint8_t
                }
        }
 
+       // Signal Macro processor that all of the buffered keys have been processed
+       macro_finishedWithBuffer( KeyIndex_BufferUsed );
+
        // Signal buffer that we've used it
-       scan_finishedWithBuffer();
+       scan_finishedWithBuffer( KeyIndex_BufferUsed );
 }
 
 inline void process_macros(void)
@@ -303,7 +388,7 @@ inline void process_macros(void)
        keyPressBufferRead( MODIFIER_MASK, sizeof(MODIFIER_MASK), KEYINDEX_MASK );
 
        // Check for bootloader condition
-       //if ( Bootloader_ConditionState == sizeof( Bootloader_ConditionSequence ) )
-       //      jumpToBootloader();
+       if ( Bootloader_ConditionState == sizeof( Bootloader_ConditionSequence ) )
+               jumpToBootloader();
 }