X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=Scan%2FDPH%2Fscan_loop.c;h=5d8d832a5cc034901e51d6597bee29a8154ccce0;hb=f57e069bb9d00b8bf59c2388a922a85d2e30ec66;hp=27eb92ee32fd0aa9b21c5dbeec2800c44a8b89a8;hpb=c3e1335678376d926c4d2842c4b1227d08dedafb;p=kiibohd-controller.git diff --git a/Scan/DPH/scan_loop.c b/Scan/DPH/scan_loop.c index 27eb92e..5d8d832 100644 --- a/Scan/DPH/scan_loop.c +++ b/Scan/DPH/scan_loop.c @@ -1,18 +1,23 @@ -/* Copyright (C) 2011-2013 by Joseph Makuch - * Additions by Jacob Alexander (2013-2014) +/* Copyright (C) 2011-2013 by Joseph Makuch (jmakuch+f@gmail.com) + * Additions by Jacob Alexander (2013-2014) (haata@kiibohd.com) * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3.0 of the License, or (at your option) any later version. + * 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: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . + * 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 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ // ----- Includes ----- @@ -23,6 +28,7 @@ // Project Includes #include #include +#include #include // Local Includes @@ -142,27 +148,29 @@ void recovery( uint8_t on ); // ----- Variables ----- -// Buffer used to inform the macro processing module which keys have been detected as pressed -volatile uint8_t KeyIndex_Buffer[KEYBOARD_BUFFER]; -volatile uint8_t KeyIndex_BufferUsed; - - // Scan Module command dictionary -char* scanCLIDictName = "DPH Module Commands"; -CLIDictItem scanCLIDict[] = { - { "echo", "Example command, echos the arguments.", cliFunc_echo }, - { "avgDebug", "Enables/Disables averaging results." NL "\t\tDisplays each average, starting from Key 0x00, ignoring 0 valued averages.", cliFunc_avgDebug }, - { "keyDebug", "Enables/Disables long debug for each keypress." NL "\t\tkeycode - [strobe:mux] : sense val : threshold+delta=total : margin", cliFunc_keyDebug }, - { "pressDebug", "Enables/Disables short debug for each keypress.", cliFunc_pressDebug }, - { "problemKeys", "Display current list of problem keys,", cliFunc_problemKeys }, - { "senseDebug", "Prints out the current sense table N times." NL "\t\tsense:max sense:delta", cliFunc_senseDebug }, +CLIDict_Entry( echo, "Example command, echos the arguments." ); +CLIDict_Entry( avgDebug, "Enables/Disables averaging results." NL "\t\tDisplays each average, starting from Key 0x00, ignoring 0 valued averages." ); +CLIDict_Entry( keyDebug, "Enables/Disables long debug for each keypress." NL "\t\tkeycode - [strobe:mux] : sense val : threshold+delta=total : margin" ); +CLIDict_Entry( pressDebug, "Enables/Disables short debug for each keypress." ); +CLIDict_Entry( problemKeys, "Display current list of problem keys," ); +CLIDict_Entry( senseDebug, "Prints out the current sense table N times." NL "\t\tsense:max sense:delta" ); + +CLIDict_Def( scanCLIDict, "DPH Module Commands" ) = { + CLIDict_Item( echo ), + CLIDict_Item( avgDebug ), + CLIDict_Item( keyDebug ), + CLIDict_Item( pressDebug ), + CLIDict_Item( problemKeys ), + CLIDict_Item( senseDebug ), { 0, 0, 0 } // Null entry for dictionary end }; + // CLI Control Variables uint8_t enableAvgDebug = 0; uint8_t enableKeyDebug = 0; -uint8_t enablePressDebug = 1; +uint8_t enablePressDebug = 0; uint8_t senseDebugCount = 3; // In order to get boot-time oddities @@ -319,19 +327,17 @@ inline uint8_t Scan_loop() } -// Signal KeyIndex_Buffer that it has been properly read +// Signal from macro module that keys have been processed // NOTE: Only really required for implementing "tricks" in converters for odd protocols -void Scan_finishedWithBuffer( uint8_t sentKeys ) +void Scan_finishedWithMacro( uint8_t sentKeys ) { - // Convenient place to clear the KeyIndex_Buffer - KeyIndex_BufferUsed = 0; return; } -// Signal KeyIndex_Buffer that it has been properly read and sent out by the USB module +// Signal from output module that keys have been processed/sent // NOTE: Only really required for implementing "tricks" in converters for odd protocols -void Scan_finishedWithUSBBuffer( uint8_t sentKeys ) +void Scan_finishedWithOutput( uint8_t sentKeys ) { return; } @@ -483,7 +489,8 @@ inline void capsense_scan() } } - info_print("If problem keys were detected, and were being held down, they will be reset as soon as let go"); + info_print("If problem keys were detected, and were being held down, they will be reset as soon as let go."); + info_print("Some keys have unusually high sense values, on the first press they should be re-enabled."); break; } } @@ -607,7 +614,7 @@ void recovery( uint8_t on ) PORTD &= ~D_MASK; PORTE &= ~E_MASK; - DDRB |= (1 << RECOVERY_SINK); // SINK pull + DDRB |= (1 << RECOVERY_SINK); // SINK pull PORTB |= (1 << RECOVERY_CONTROL); PORTB |= (1 << RECOVERY_SOURCE); // SOURCE high DDRB |= (1 << RECOVERY_SOURCE); @@ -617,7 +624,7 @@ void recovery( uint8_t on ) PORTB &= ~(1 << RECOVERY_CONTROL); DDRB &= ~(1 << RECOVERY_SOURCE); PORTB &= ~(1 << RECOVERY_SOURCE); // SOURCE low - DDRB &= ~(1 << RECOVERY_SINK); // SINK high-imp + DDRB &= ~(1 << RECOVERY_SINK); // SINK high-imp } } @@ -764,9 +771,10 @@ void testColumn( uint8_t strobe ) // Check if this is a bad key (e.g. test point, or non-existent key) if ( keys_problem[key] ) { - // If the sample value of the problem key goes below full_avg (overall initial average) + // If the sample value of the problem key goes above initally recorded result + threshold // re-enable the key - if ( (db_sample = samples[strobe][mux] >> 1) < full_avg ) + if ( (db_sample = samples[strobe][mux] >> 1) > keys_problem[key] + threshold ) + //if ( (db_sample = samples[strobe][mux] >> 1) < high_avg ) { info_msg("Re-enabling problem key: "); printHex( key ); @@ -802,23 +810,26 @@ void testColumn( uint8_t strobe ) print(" "); } - // Only add the key to the buffer once - // NOTE: Buffer can easily handle multiple adds, just more efficient - // and nicer debug messages :P - //Macro_bufferAdd( key ); + // Initial Keypress + Macro_keyState( key, 0x01 ); } keys_debounce[key]++; } + else if ( keys_debounce[key] >= DEBOUNCE_THRESHOLD ) + { + // Held Key + Macro_keyState( key, 0x02 ); + } // Long form key debugging if ( enableKeyDebug ) { // Debug message // [:] : : : - dbug_msg("0x"); - printHex_op( key, 2 ); + dbug_msg(""); + printHex_op( key, 1 ); print(" ["); printInt8( strobe ); print(":"); @@ -839,23 +850,11 @@ void testColumn( uint8_t strobe ) // Clear debounce entry if no keypress detected else { - // If the key was previously pressed, remove from the buffer - for ( uint8_t c = 0; c < KeyIndex_BufferUsed; c++ ) - { - // Key to release found - if ( KeyIndex_Buffer[c] == key ) - { - // Shift keys from c position - for ( uint8_t k = c; k < KeyIndex_BufferUsed - 1; k++ ) - KeyIndex_Buffer[k] = KeyIndex_Buffer[k + 1]; - - // Decrement Buffer - KeyIndex_BufferUsed--; - - break; - } - } - + // Release Key + if ( keys_debounce[key] >= DEBOUNCE_THRESHOLD ) + { + Macro_keyState( key, 0x03 ); + } // Clear debounce entry keys_debounce[key] = 0; @@ -1035,7 +1034,7 @@ void cliFunc_senseDebug( char* args ) // If there was an argument, use that instead if ( *arg1Ptr != '\0' ) { - senseDebugCount = decToInt( arg1Ptr ); + senseDebugCount = numToInt( arg1Ptr ); } }