-
-
Save dude8604/98f7d8e7e6f4d74349b1b974e8ea0d17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <LinkedList.h> | |
const uint8_t PinLeft = 2; | |
const uint8_t PinMiddle = 3; | |
const uint8_t PinRight = 4; | |
const uint8_t PinLED = 13; | |
enum MouseButtons {LEFT, MIDDLE, RIGHT} ; | |
bool leftPressed = false; | |
bool middlePressed = false; | |
bool rightPressed = false; | |
void sendMouseState() { | |
Mouse.set_buttons(leftPressed, middlePressed, rightPressed); | |
} | |
void mouseButtonPress(MouseButtons theButton); | |
void mouseButtonPress(MouseButtons theButton) { | |
if (theButton == MouseButtons::LEFT) { | |
leftPressed = true; | |
} else if(theButton == MouseButtons::MIDDLE) { | |
middlePressed = true; | |
} else if (theButton == MouseButtons::RIGHT) { | |
rightPressed = true; | |
} | |
} | |
void mouseButtonRelease(MouseButtons button); | |
void mouseButtonRelease(MouseButtons button) { | |
if (button == MouseButtons::LEFT) { | |
leftPressed = false; | |
} else if(button == MouseButtons::MIDDLE) { | |
middlePressed = false; | |
} else if (button == MouseButtons::RIGHT) { | |
rightPressed = false; | |
} | |
} | |
volatile unsigned int nextPressLeft = 0; | |
volatile unsigned int nextPressCenter = 0; | |
volatile unsigned int nextPressRight = 0; | |
const int timeBetween = 150; //milliseconds | |
enum ActionType {KB, MOU}; //keyboard or mouse | |
class Action { | |
public: | |
uint16_t keyCode; | |
ActionType actionType; | |
Action (uint16_t keyCode, ActionType actionType) : keyCode(keyCode), actionType(actionType) {} | |
}; | |
class ModeAction { | |
public: | |
LinkedList<Action> keys; | |
void addAction(Action action) { | |
keys.add(action); | |
} | |
}; | |
class ActionManager { | |
private: | |
uint8_t modeL = 1; | |
uint8_t modeM = 1; | |
uint8_t modeR = 1; | |
LinkedList<ModeAction> lActions; | |
LinkedList<ModeAction> mActions; | |
LinkedList<ModeAction> rActions; | |
bool lActing = false, mActing = false, rActing = false; | |
public: | |
ActionManager() { | |
//lActions = new LinkedList<ModeAction>(); | |
//mActions = new LinkedList<ModeAction>(); | |
//rActions = new LinkedList<ModeAction>(); | |
//actions for left switch | |
//mode 1 | |
{ | |
ModeAction tempMA; | |
tempMA.addAction(Action(MouseButtons::LEFT, ActionType::MOU)); | |
lActions.add(tempMA); | |
} | |
//mode 2 | |
{ | |
ModeAction tempMA; | |
tempMA.addAction(Action(KEY_F11, ActionType::KB)); | |
lActions.add(tempMA); | |
} | |
//mode 3 | |
{ | |
ModeAction tempMA; | |
tempMA.addAction(Action(KEY_LEFT_CTRL, ActionType::KB)); | |
tempMA.addAction(Action(KEY_LEFT_ALT, ActionType::KB)); | |
lActions.add(tempMA); | |
} | |
//mode 4 | |
{ | |
ModeAction tempMA; | |
tempMA.addAction(Action(KEY_W, ActionType::KB)); | |
lActions.add(tempMA); | |
} | |
//actions for middle switch | |
//mode 1 | |
{ | |
ModeAction tempMA; | |
tempMA.addAction(Action(MouseButtons::MIDDLE, ActionType::MOU)); | |
mActions.add(tempMA); | |
} | |
//actions for right switch | |
//mode 1 | |
{ | |
ModeAction tempMA; | |
tempMA.addAction(Action(MouseButtons::RIGHT, ActionType::MOU)); | |
rActions.add(tempMA); | |
} | |
} | |
void cycleModeL() { | |
modeL++; | |
if(modeL >= lActions.size()) { | |
modeL = 1; | |
} | |
} | |
void cycleModeM() { | |
modeM++; | |
if(modeM >= mActions.size()) { | |
modeM = 1; | |
} | |
} | |
void cycleModeR() { | |
modeR++; | |
if(modeR >= rActions.size()) { | |
modeR = 1; | |
} | |
} | |
private: | |
//void doDownActions(ModeAction modeActions, uint8_t mode) { | |
//for (int i = 0; i < modeActions.at(mode).keys.length(); i++) { | |
//if (modeActions[mode][i].keys[i].actionType == ActionType.KB) { | |
//Keyboard.press(modeActions[mode].keys[i].keyCode) | |
//} else if (modeActions[mode].keys[i].actionType == ActionType.MOU) { | |
//mouseButtonPress(modeActions[mode].keys[i].keyCode); | |
//} | |
//} | |
//sendMouseState(); | |
//} | |
// | |
//void doUpActions(ModeAction modeActions, uint8_t mode) { | |
//for (int i = 0; i < modeActions[mode].keys.length(); i++) { | |
//if (modeActions[mode][i].keys[i].actionType == ActionType.KB) { | |
//Keyboard.release(modeActions[mode].keys[i].keyCode) | |
//} else if (modeActions[mode].keys[i].actionType == ActionType.MOU) { | |
//mouseButtonRelease(modeActions[mode].keys[i].keyCode); | |
//} | |
//} | |
//sendMouseState(); | |
//} | |
public: | |
//void leftDown() { | |
//if (lActing == false) { | |
//lActing = true; | |
//doDownActions(lActions, modeL); | |
//} | |
//} | |
// | |
//void middleDown() { | |
//if (mActing == false) { | |
//mActing = true; | |
//doDownActions(mActions, modeM); | |
//} | |
//} | |
// | |
//void rightDown() { | |
//if (rActing == false) { | |
//rActing = true; | |
//doDownActions(rActions, modeR); | |
//} | |
//} | |
// | |
//void leftUp() { | |
//if (lActing == true) { | |
//lActing = false; | |
//doUpActions(lActions, modeL); | |
//} | |
//} | |
// | |
//void middleUp() { | |
//if (mActing == true) { | |
//mActing = false; | |
//doUpActions(mActions, modeM); | |
//} | |
//} | |
// | |
//void rightUp() { | |
//if (rActing == true) { | |
//rActing = false; | |
//doUpActions(rActions, modeR); | |
//} | |
//} | |
}; | |
ActionManager actionManager = ActionManager(); | |
void setup() { | |
Serial.begin(115200); | |
pinMode(PinLED, OUTPUT); | |
//pinMode(PinRight, INPUT_PULLUP); // sets the digital pin as output | |
//attachInterrupt(PinRight, isrChangeR, CHANGE); // interrrupt is data ready | |
// | |
//pinMode(PinMiddle, INPUT_PULLUP); // sets the digital pin as output | |
//attachInterrupt(PinMiddle, isrChangeM, CHANGE); // interrrupt is data ready | |
// | |
//pinMode(PinLeft, INPUT_PULLUP); // sets the digital pin as output | |
//attachInterrupt(PinLeft, isrChangeL, CHANGE); // interrrupt is data ready | |
} | |
void loop() { | |
//if (Serial.available()) { | |
////change mode | |
//mode = Serial.parseInt(); | |
// | |
////release all buttons | |
//Keyboard.releaseAll(); | |
//Mouse.set_buttons(0, 0, 0); | |
// | |
////turn off LED | |
//digitalWrite(PinLED, LOW); | |
// | |
////flush the serial input buffer | |
//while (Serial.available()) { | |
//Serial.read(); | |
//} | |
// | |
//} | |
//delay(1000); | |
//Serial.println("Running"); | |
} | |
//void isrChangeL() { | |
//cli(); | |
//if (digitalRead(PinLeft) == LOW && nextPressLeft < millis()) { | |
////Serial.println("Pressed"); | |
//digitalWrite(PinLED, HIGH); //set the LED on | |
// | |
//if (mode == 0) { | |
//Mouse.set_buttons(1, 0, 0); | |
//} else if (mode == 1) { | |
//Keyboard.press(KEY_F11); | |
//} else if (mode == 2) { | |
//Keyboard.press(KEY_LEFT_CTRL); | |
//Keyboard.press(KEY_LEFT_ALT); | |
//} else if (mode == 3) { | |
//Keyboard.press(KEY_W); | |
//} | |
// | |
//nextPressLeft = millis() + timeBetween; | |
// | |
//} else { | |
//// Serial.println("Released"); | |
//digitalWrite(PinLED, LOW); // set the LED off | |
// | |
//if (mode == 0) { | |
//Mouse.set_buttons(0, 0, 0); | |
//} else if (mode == 1) { | |
//Keyboard.release(KEY_F11); | |
//} else if (mode == 2) { | |
//Keyboard.release(KEY_LEFT_CTRL); | |
//Keyboard.release(KEY_LEFT_ALT); | |
//} else if (mode == 3) { | |
//Keyboard.release(KEY_W); | |
//} | |
// | |
//nextPressLeft = millis() + timeBetween * 0.6; | |
// | |
// | |
//} | |
//sei(); | |
//} | |
// | |
//void isrChangeM() { | |
//cli(); | |
////if (digitalRead(PinMiddle) == LOW && nextPressCenter < millis()) | |
////{ | |
////Keyboard.press(KEY_SPACE); | |
////delay(250); | |
////Keyboard.release(KEY_SPACE); | |
////} | |
// | |
//if (digitalRead(PinMiddle) == LOW && nextPressCenter < millis()) { | |
////Serial.println("Pressed"); | |
//digitalWrite(PinLED, HIGH); //set the LED on | |
////Mouse.set_buttons(0, 1, 0); | |
// | |
//nextPressCenter = millis() + timeBetween; | |
// | |
//} else { | |
//// Serial.println("Released"); | |
//digitalWrite(PinLED, LOW); // set the LED off | |
////Mouse.set_buttons(0, 0, 0); | |
// | |
//nextPressCenter = millis() + timeBetween * 0.6; | |
// | |
// | |
//} | |
// | |
//sei(); | |
//} | |
// | |
//void isrChangeR() { | |
//cli(); | |
//if (digitalRead(PinRight) == LOW && nextPressRight < millis()) { | |
////Serial.println("Pressed"); | |
//digitalWrite(PinLED, HIGH); // set the LED on | |
//Mouse.set_buttons(0, 0, 1); | |
////Keyboard.press(KEY_F11); | |
//nextPressRight = millis() + timeBetween; | |
//} else { | |
//// Serial.println("Released"); | |
//digitalWrite(PinLED, LOW); // set the LED off | |
//Mouse.set_buttons(0, 0, 0); | |
////Keyboard.release(KEY_F11); | |
//nextPressRight = millis() + timeBetween * 0.6; | |
//} | |
//sei(); | |
//} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment