astyle and new astyle make target

pull/18/head
jesse 11 years ago
parent 348a8f760b
commit 5f5eac1176

@ -8,8 +8,8 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
void loop(); void loop();
void setup(); void setup();
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
#endif #endif

@ -1,6 +1,5 @@
// Do not remove the include below // Do not remove the include below
#include "ArduinoKeyboard.h" #include "ArduinoKeyboard.h"
// Copyright 2013 Jesse Vincent <jesse@fsck.com> // Copyright 2013 Jesse Vincent <jesse@fsck.com>
// All Rights Reserved. (To be licensed under an opensource license // All Rights Reserved. (To be licensed under an opensource license
// before the release of the keyboard.io model 01 // before the release of the keyboard.io model 01
@ -70,7 +69,8 @@ static const Key keymaps[LAYERS][ROWS][COLS] = {
}; };
void release_keys_not_being_pressed() { void release_keys_not_being_pressed()
{
// we use charsReportedLastTime to figure out what we might not be holding anymore and can now release. this is destructive to charsReportedLastTime // we use charsReportedLastTime to figure out what we might not be holding anymore and can now release. this is destructive to charsReportedLastTime
@ -99,7 +99,8 @@ void release_keys_not_being_pressed() {
} }
} }
void record_key_being_pressed(byte character) { void record_key_being_pressed(byte character)
{
for (int i=0; i<KEYS_HELD_BUFFER; i++) { for (int i=0; i<KEYS_HELD_BUFFER; i++) {
// todo - deal with overflowing the 12 key buffer here // todo - deal with overflowing the 12 key buffer here
if (charsBeingReported[i] == 0x00) { if (charsBeingReported[i] == 0x00) {
@ -109,66 +110,67 @@ void record_key_being_pressed(byte character) {
} }
} }
boolean key_was_pressed (byte keyState) { boolean key_was_pressed (byte keyState)
{
if ( byte((keyState >> 4)) ^ B00001111 ) { if ( byte((keyState >> 4)) ^ B00001111 ) {
return false; return false;
} } else {
else {
return true; return true;
} }
} }
boolean key_was_not_pressed (byte keyState) { boolean key_was_not_pressed (byte keyState)
{
if ( byte((keyState >> 4)) ^ B00000000 ) { if ( byte((keyState >> 4)) ^ B00000000 ) {
return false; return false;
} } else {
else {
return true; return true;
} }
} }
boolean key_is_pressed (byte keyState) { boolean key_is_pressed (byte keyState)
{
if ( byte((keyState << 4)) ^ B11110000 ) { if ( byte((keyState << 4)) ^ B11110000 ) {
return false; return false;
} } else {
else {
return true; return true;
} }
} }
boolean key_is_not_pressed (byte keyState) { boolean key_is_not_pressed (byte keyState)
{
if ( byte((keyState << 4)) ^ B00000000 ) { if ( byte((keyState << 4)) ^ B00000000 ) {
return false; return false;
} } else {
else {
return true; return true;
} }
} }
boolean key_toggled_on(byte keyState) { boolean key_toggled_on(byte keyState)
{
if (key_is_pressed(keyState) && key_was_not_pressed(keyState)) { if (key_is_pressed(keyState) && key_was_not_pressed(keyState)) {
return true; return true;
} } else {
else {
return false; return false;
} }
} }
boolean key_toggled_off(byte keyState) { boolean key_toggled_off(byte keyState)
{
if (key_was_pressed(keyState) && key_is_not_pressed(keyState)) { if (key_was_pressed(keyState) && key_is_not_pressed(keyState)) {
return true; return true;
} } else {
else {
return false; return false;
} }
} }
void reset_matrix() { void reset_matrix()
{
for (int col = 0; col < COLS; col++) { for (int col = 0; col < COLS; col++) {
for (int row = 0; row < ROWS; row++) { for (int row = 0; row < ROWS; row++) {
matrixState[row][col] <<= 1; matrixState[row][col] <<= 1;
@ -179,7 +181,8 @@ void reset_matrix() {
charsBeingReported[i] = 0x00; charsBeingReported[i] = 0x00;
} }
} }
double mouse_accel (double cycles) { double mouse_accel (double cycles)
{
double accel = atan((cycles/25)-5); double accel = atan((cycles/25)-5);
accel += 1.5707963267944; // we want the whole s curve, not just the bit that's usually above the x and y axes; accel += 1.5707963267944; // we want the whole s curve, not just the bit that's usually above the x and y axes;
accel = accel *0.85; accel = accel *0.85;
@ -189,7 +192,8 @@ double mouse_accel (double cycles) {
return accel; return accel;
} }
void send_key_events(int layer) { void send_key_events(int layer)
{
//for every newly pressed button, figure out what logical key it is and send a key down event //for every newly pressed button, figure out what logical key it is and send a key down event
// for every newly released button, figure out what logical key it is and send a key up event // for every newly released button, figure out what logical key it is and send a key up event
@ -238,8 +242,7 @@ void send_key_events(int layer) {
if (key_toggled_on (switchState)) { if (key_toggled_on (switchState)) {
Keyboard.press(mappedKey.rawKey); Keyboard.press(mappedKey.rawKey);
} }
} } else if (key_toggled_off (switchState)) {
else if (key_toggled_off (switchState)) {
Keyboard.release(mappedKey.rawKey); Keyboard.release(mappedKey.rawKey);
} }
} }
@ -253,8 +256,7 @@ void send_key_events(int layer) {
if (x>0) { if (x>0) {
moveX = (x*accel) + carriedOverX; moveX = (x*accel) + carriedOverX;
carriedOverX = moveX - floor(moveX); carriedOverX = moveX - floor(moveX);
} } else if(x<0) {
else if(x<0) {
moveX = (x*accel) - carriedOverX; moveX = (x*accel) - carriedOverX;
carriedOverX = ceil(moveX) - moveX; carriedOverX = ceil(moveX) - moveX;
} }
@ -270,7 +272,15 @@ void send_key_events(int layer) {
Serial.print("cycles: "); Serial.print("cycles: ");
Serial.println(mouseActiveForCycles); Serial.println(mouseActiveForCycles);
Serial.print("Accel: "); Serial.print("Accel: ");
Serial.print(accel); Serial.print(" moveX is "); Serial.print(moveX); Serial.print(" moveY is "); Serial.print(moveY); Serial.print(" carriedoverx is "); Serial.print(carriedOverX); Serial.print(" carriedOverY is "); Serial.println(carriedOverY); Serial.print(accel);
Serial.print(" moveX is ");
Serial.print(moveX);
Serial.print(" moveY is ");
Serial.print(moveY);
Serial.print(" carriedoverx is ");
Serial.print(carriedOverX);
Serial.print(" carriedOverY is ");
Serial.println(carriedOverY);
Mouse.move(moveX,moveY, 0); Mouse.move(moveX,moveY, 0);
} else { } else {
mouseActiveForCycles=0; mouseActiveForCycles=0;
@ -279,7 +289,8 @@ void send_key_events(int layer) {
} }
void setup_matrix() { void setup_matrix()
{
//set up the row pins as outputs //set up the row pins as outputs
for (int row = 0; row < ROWS; row++) { for (int row = 0; row < ROWS; row++) {
pinMode(rowPins[row], OUTPUT); pinMode(rowPins[row], OUTPUT);
@ -301,7 +312,8 @@ void setup_matrix() {
} }
void scan_matrix() { void scan_matrix()
{
int active_layer = current_layer; int active_layer = current_layer;
@ -313,8 +325,7 @@ void scan_matrix() {
if (digitalRead(colPins[col])) { if (digitalRead(colPins[col])) {
matrixState[row][col] |= 0; // noop. just here for clarity matrixState[row][col] |= 0; // noop. just here for clarity
} } else {
else {
matrixState[row][col] |= 1; // noop. just here for clarity matrixState[row][col] |= 1; // noop. just here for clarity
} }
// while we're inspecting the electrical matrix, we look // while we're inspecting the electrical matrix, we look
@ -337,7 +348,8 @@ void scan_matrix() {
} }
void report_matrix() { void report_matrix()
{
if (reporting_counter++ %100 == 0 ) { if (reporting_counter++ %100 == 0 ) {
for (int row = 0; row < ROWS; row++) { for (int row = 0; row < ROWS; row++) {
for (int col = 0; col < COLS; col++) { for (int col = 0; col < COLS; col++) {
@ -351,7 +363,8 @@ void report_matrix() {
} }
} }
void report(int row, int col, boolean value) { void report(int row, int col, boolean value)
{
Serial.print("Detected a change on "); Serial.print("Detected a change on ");
Serial.print(col); Serial.print(col);
Serial.print(" "); Serial.print(" ");
@ -362,14 +375,16 @@ void report(int row, int col, boolean value) {
} }
void setup() { void setup()
{
Keyboard.begin(); Keyboard.begin();
Mouse.begin(); Mouse.begin();
Serial.begin(115200); Serial.begin(115200);
setup_matrix(); setup_matrix();
} }
void loop() { void loop()
{
scan_matrix(); scan_matrix();
// report_matrix(); // report_matrix();
reset_matrix(); reset_matrix();

@ -1,7 +1,10 @@
# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile # Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile
BOARD_TAG = micro BOARD_TAG = micro
MONITOR_PORT = /dev/ttyACM0 MONITOR_PORT = /dev/ttyACM*
ARDUINO_LIBS = ARDUINO_LIBS =
include build/arduino-mk/Arduino.mk include build/arduino-mk/Arduino.mk
astyle:
astyle --style=linux ArduinoKeyboard.ino ArduinoKeyboard.h

Loading…
Cancel
Save