-/* 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 <http://www.gnu.org/licenses/>.
+ * 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 -----
// Project Includes
#include <cli.h>
#include <led.h>
+#include <macro.h>
#include <print.h>
// Local Includes
// ----- 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
}
-// 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;
}
}
}
- 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;
}
}
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);
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
}
}
// 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 );
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
// <key> [<strobe>:<mux>] : <sense val> : <delta + threshold> : <margin>
- dbug_msg("0x");
- printHex_op( key, 2 );
+ dbug_msg("");
+ printHex_op( key, 1 );
print(" [");
printInt8( strobe );
print(":");
// 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;
// If there was an argument, use that instead
if ( *arg1Ptr != '\0' )
{
- senseDebugCount = decToInt( arg1Ptr );
+ senseDebugCount = numToInt( arg1Ptr );
}
}