WIP fonctions paramétrables
This commit is contained in:
parent
0da357ce07
commit
e6a467b2ad
@ -13,39 +13,63 @@ USBHIDMouse Mouse;
|
||||
USBHIDKeyboard Keyboard;
|
||||
Preferences moozyPrefs;
|
||||
|
||||
// set pin numbers for the five buttons:
|
||||
const int upButton = 14;
|
||||
const int downButton = 13;
|
||||
const int leftButton = 14;
|
||||
const int rightButton = 12;
|
||||
const int mouseButton = 0;
|
||||
// Variable and constant declarations
|
||||
// ----------------------------------
|
||||
|
||||
// set pin numbers for the five inputs:
|
||||
const int PinInput1 = 9;
|
||||
const int PinInput2 = 10;
|
||||
const int PinInput3 = 11;
|
||||
const int PinInput4 = 12;
|
||||
const int PinInput5 = 13;
|
||||
const int PinInput6 = 14;
|
||||
|
||||
bool keypressed = false;
|
||||
int cursorspeed, speed1, speed2, speed3;
|
||||
String input1, input2, input3;
|
||||
int currentspeed = 2;
|
||||
String todo, fctinput1, fctinput2, fctinput3, fctinput4, fctinput5, fctinput6;
|
||||
|
||||
// Interrupt Service Routine
|
||||
// -------------------------
|
||||
void ISR_Inputs () {
|
||||
if (!digitalRead(PinInput1)) { todo = fctinput1; Serial.print("I1"); }
|
||||
if (!digitalRead(PinInput2)) { todo = fctinput2; }
|
||||
if (!digitalRead(PinInput3)) { todo = fctinput3; }
|
||||
if (!digitalRead(PinInput4)) { todo = fctinput4; }
|
||||
if (!digitalRead(PinInput5)) { todo = fctinput5; }
|
||||
if (!digitalRead(PinInput6)) { todo = fctinput6; }
|
||||
Serial.print("Interruption");
|
||||
}
|
||||
|
||||
// Initialisations
|
||||
// ---------------
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
// initialize the buttons' inputs:
|
||||
pinMode(upButton, INPUT_PULLUP);
|
||||
pinMode(downButton, INPUT_PULLUP);
|
||||
pinMode(leftButton, INPUT_PULLUP);
|
||||
pinMode(rightButton, INPUT_PULLUP);
|
||||
pinMode(mouseButton, INPUT_PULLUP);
|
||||
pinMode(PinInput1, INPUT_PULLUP);
|
||||
pinMode(PinInput2, INPUT_PULLUP);
|
||||
pinMode(PinInput3, INPUT_PULLUP);
|
||||
pinMode(PinInput4, INPUT_PULLUP);
|
||||
pinMode(PinInput5, INPUT_PULLUP);
|
||||
pinMode(PinInput6, INPUT_PULLUP);
|
||||
|
||||
// retrieve settings from memory
|
||||
// retrieve settings from flash nvs
|
||||
moozyPrefs.begin("myapp", true); //namespace / true = RO MODE
|
||||
speed1 = moozyPrefs.getInt("speed1");
|
||||
speed2 = moozyPrefs.getInt("speed2");
|
||||
speed3 = moozyPrefs.getInt("speed3");
|
||||
input1 = moozyPrefs.getString("input1");
|
||||
input2 = moozyPrefs.getString("input2");
|
||||
input3 = moozyPrefs.getString("input3");
|
||||
fctinput1 = moozyPrefs.getString("input1");
|
||||
fctinput2 = moozyPrefs.getString("input2");
|
||||
fctinput3 = moozyPrefs.getString("input3");
|
||||
fctinput4 = moozyPrefs.getString("input4");
|
||||
fctinput5 = moozyPrefs.getString("input5");
|
||||
fctinput6 = moozyPrefs.getString("input6");
|
||||
moozyPrefs.end();
|
||||
|
||||
cursorspeed = speed2 / 10;
|
||||
|
||||
// Affichage des valeurs récupérer en Flash, pour débug
|
||||
// Affichage des valeurs récupérées en Flash // pour débug
|
||||
Serial.println("Les valeurs en Flash/EEPROM :");
|
||||
Serial.print("Vitesse 1 : ");
|
||||
Serial.println(speed1);
|
||||
@ -53,50 +77,60 @@ void setup() {
|
||||
Serial.println(speed2);
|
||||
Serial.print("Vitesse 3 : ");
|
||||
Serial.println(speed3);
|
||||
Serial.print("Entrée 1 : ");
|
||||
Serial.println(input1);
|
||||
Serial.print("Entrée 2 : ");
|
||||
Serial.println(input2);
|
||||
Serial.print("Entrée 3 : ");
|
||||
Serial.println(input3);
|
||||
|
||||
moozyPrefs.end();
|
||||
Serial.print("Fct entrée 1 : ");
|
||||
Serial.println(fctinput1);
|
||||
Serial.print("Fct entrée 2 : ");
|
||||
Serial.println(fctinput2);
|
||||
Serial.print("Fct entrée 3 : ");
|
||||
Serial.println(fctinput3);
|
||||
Serial.print("Fct entrée 4 : ");
|
||||
Serial.println(fctinput4);
|
||||
Serial.print("Fct entrée 5 : ");
|
||||
Serial.println(fctinput5);
|
||||
Serial.print("Fct entrée 6 : ");
|
||||
Serial.println(fctinput6);
|
||||
|
||||
// initialize mouse control:
|
||||
Mouse.begin();
|
||||
Keyboard.begin();
|
||||
USB.begin();
|
||||
|
||||
// initialize interruptions
|
||||
attachInterrupt(digitalPinToInterrupt(PinInput1), ISR_Inputs, CHANGE);
|
||||
attachInterrupt(digitalPinToInterrupt(PinInput2), ISR_Inputs, CHANGE);
|
||||
attachInterrupt(digitalPinToInterrupt(PinInput3), ISR_Inputs, CHANGE);
|
||||
attachInterrupt(digitalPinToInterrupt(PinInput4), ISR_Inputs, CHANGE);
|
||||
attachInterrupt(digitalPinToInterrupt(PinInput5), ISR_Inputs, CHANGE);
|
||||
attachInterrupt(digitalPinToInterrupt(PinInput6), ISR_Inputs, CHANGE);
|
||||
}
|
||||
|
||||
// Main loop
|
||||
// -------------
|
||||
void loop() {
|
||||
// use serial input to control the mouse:
|
||||
if (Serial.available() > 0) {
|
||||
char inChar = Serial.read();
|
||||
if (todo =="LC") { dolc(); }
|
||||
if (todo =="LCD") { dolcd(); }
|
||||
if (todo =="LCH") { dolch(); }
|
||||
if (todo =="RC") { dorc(); }
|
||||
if (todo =="RCD") { dorcd(); }
|
||||
if (todo =="RCH") { dorch(); }
|
||||
if (todo =="up") { moveup(); }
|
||||
if (todo =="down") { movedown(); }
|
||||
if (todo =="right") { moveright(); }
|
||||
if (todo =="left") { moveleft(); }
|
||||
if (todo =="upright") { moveupright(); }
|
||||
if (todo =="upleft") { moveupleft(); }
|
||||
if (todo =="downright") { movedownright(); }
|
||||
if (todo =="downleft") { movedownleft(); }
|
||||
if (todo =="scrollup") { doscrollup(); }
|
||||
if (todo =="scrolldown") { doscrolldown(); }
|
||||
if (todo =="speed1") { tospeed1(); }
|
||||
if (todo =="speed2") { tospeed2(); }
|
||||
if (todo =="speed3") { tospeed3(); }
|
||||
if (todo =="speedinc") { incspeed(); }
|
||||
if (todo =="speeddec") { decspeed(); }
|
||||
if (todo =="mode1") { tomode1(); }
|
||||
if (todo =="mode2") { tomode2(); }
|
||||
if (todo =="mode3") { tomode3(); }
|
||||
|
||||
switch (inChar) {
|
||||
case 'r':
|
||||
// move mouse right
|
||||
Mouse.move(40, 0);
|
||||
break;
|
||||
case 'm':
|
||||
// perform mouse left click
|
||||
Mouse.click(MOUSE_LEFT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((digitalRead(upButton) == HIGH) && (digitalRead(mouseButton))) {
|
||||
keypressed = false;
|
||||
} else {
|
||||
//if (keypressed == false) {
|
||||
if (digitalRead(upButton) == LOW) {
|
||||
Mouse.move(0, -cursorspeed);
|
||||
}
|
||||
if (digitalRead(mouseButton) == LOW) {
|
||||
Mouse.move(0, cursorspeed);
|
||||
}
|
||||
Keyboard.releaseAll();
|
||||
keypressed = true;
|
||||
delay(5);
|
||||
}
|
||||
//}
|
||||
todo = "";
|
||||
}
|
||||
|
146
moozyfeatures.ino
Normal file
146
moozyfeatures.ino
Normal file
@ -0,0 +1,146 @@
|
||||
|
||||
void donothing() { // Do nothing
|
||||
}
|
||||
void dolc() { // Do a left click
|
||||
Mouse.click(MOUSE_LEFT);
|
||||
Mouse.release();
|
||||
Serial.print("Clic gauche");
|
||||
todo = "";
|
||||
}
|
||||
void dolcd() { // Do a double left click
|
||||
Mouse.press(MOUSE_LEFT);
|
||||
delay(50);
|
||||
Mouse.release();
|
||||
delay(50);
|
||||
Mouse.press(MOUSE_LEFT);
|
||||
delay(50);
|
||||
Mouse.release();
|
||||
}
|
||||
void dolch() { // Do a left click and hold
|
||||
if (Mouse.isPressed(MOUSE_LEFT)) {
|
||||
Mouse.release();
|
||||
}
|
||||
else{
|
||||
Mouse.press(MOUSE_LEFT);
|
||||
}
|
||||
}
|
||||
void dorc() { // Do a right click
|
||||
Mouse.click(MOUSE_RIGHT);
|
||||
Mouse.release();
|
||||
}
|
||||
void dorcd() { // Do a double right click
|
||||
Mouse.press(MOUSE_RIGHT);
|
||||
delay(50);
|
||||
Mouse.release();
|
||||
delay(50);
|
||||
Mouse.press(MOUSE_RIGHT);
|
||||
delay(50);
|
||||
Mouse.release();
|
||||
}
|
||||
void dorch() { // Do a left click and hold
|
||||
if (Mouse.isPressed(MOUSE_RIGHT)) {
|
||||
Mouse.release();
|
||||
}
|
||||
else{
|
||||
Mouse.press(MOUSE_RIGHT);
|
||||
}
|
||||
}
|
||||
void moveup() { // Move the mouse cursor up
|
||||
Mouse.move(0, cursorspeed);
|
||||
}
|
||||
void movedown() { // Move the mouse cursor down
|
||||
Mouse.move(0, -cursorspeed);
|
||||
}
|
||||
void moveright() { // Move the mouse cursor to the right
|
||||
Mouse.move(cursorspeed, 0);
|
||||
}
|
||||
void moveleft() { // Move the mouse cursor to the left
|
||||
Mouse.move(cursorspeed, 0);
|
||||
}
|
||||
void moveupright() { // Move the mouse cursor to the diag up and right
|
||||
Mouse.move(cursorspeed, cursorspeed);
|
||||
}
|
||||
void moveupleft() { // Move the mouse cursor to the diag up and left
|
||||
Mouse.move(-cursorspeed, cursorspeed);
|
||||
}
|
||||
void movedownright() { // Move the mouse cursor to the diag down and right
|
||||
Mouse.move(cursorspeed, -cursorspeed);
|
||||
}
|
||||
void movedownleft() { // Move the mouse cursor to the diag down and left
|
||||
Mouse.move(-cursorspeed, -cursorspeed);
|
||||
}
|
||||
void doscrollup() { // Move the wheel cursor up
|
||||
Mouse.move(0, 0, cursorspeed);
|
||||
}
|
||||
void doscrolldown() { // Move the wheel cursor down
|
||||
Mouse.move(0, 0, -cursorspeed);
|
||||
}
|
||||
void tospeed1() { // Change to the speed 1
|
||||
cursorspeed = speed1 / 10;
|
||||
currentspeed = 1;
|
||||
}
|
||||
void tospeed2() { // Change to the speed 2
|
||||
cursorspeed = speed2 / 10;
|
||||
currentspeed = 2;
|
||||
}
|
||||
void tospeed3() { // Change to the speed 3
|
||||
cursorspeed = speed3 / 10;
|
||||
currentspeed = 3;
|
||||
}
|
||||
void incspeed() { // Increase actual speed (max is 100)
|
||||
switch (currentspeed) {
|
||||
case 1:
|
||||
speed1 = speed1 + 10;
|
||||
if (speed1 >=100)
|
||||
speed1 = 100;
|
||||
cursorspeed = speed1 / 10;
|
||||
break;
|
||||
case 2:
|
||||
speed2 = speed2 + 10;
|
||||
if (speed2 >=100)
|
||||
speed2 = 100;
|
||||
cursorspeed = speed2 / 10;
|
||||
break;
|
||||
case 3:
|
||||
speed3 = speed3 + 10;
|
||||
if (speed3 >=100)
|
||||
speed3 = 100;
|
||||
cursorspeed = speed3 / 10;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
void decspeed() { // Decrease actual speed (min is 0)
|
||||
switch (currentspeed) {
|
||||
case 1:
|
||||
speed1 = speed1 - 10;
|
||||
if (speed1 <= 0)
|
||||
speed1 = 0;
|
||||
cursorspeed = speed1 / 10;
|
||||
break;
|
||||
case 2:
|
||||
speed2 = speed2 - 10;
|
||||
if (speed2 <= 0)
|
||||
speed2 = 0;
|
||||
cursorspeed = speed2 / 10;
|
||||
break;
|
||||
case 3:
|
||||
speed3 = speed3 - 10;
|
||||
if (speed3 <= 0)
|
||||
speed3 = 0;
|
||||
cursorspeed = speed3 / 10;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
void tomode1() { // Switch to mode 1
|
||||
|
||||
}
|
||||
void tomode2() { // Switch to mode
|
||||
|
||||
}
|
||||
void tomode3() { // Switch to mode
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user