Moozy_firmware/Moozy_firmware.ino

137 lines
4.1 KiB
C++

/*
Moozy_firmware by Laurent CLAUDE
2023-09
Licence GPL v3 or later
*/
#include "USB.h"
#include "USBHIDMouse.h"
#include "USBHIDKeyboard.h"
#include <Preferences.h>
USBHIDMouse Mouse;
USBHIDKeyboard Keyboard;
Preferences moozyPrefs;
// 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;
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(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 flash nvs
moozyPrefs.begin("myapp", true); //namespace / true = RO MODE
speed1 = moozyPrefs.getInt("speed1");
speed2 = moozyPrefs.getInt("speed2");
speed3 = moozyPrefs.getInt("speed3");
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érées en Flash // pour débug
Serial.println("Les valeurs en Flash/EEPROM :");
Serial.print("Vitesse 1 : ");
Serial.println(speed1);
Serial.print("Vitesse 2 : ");
Serial.println(speed2);
Serial.print("Vitesse 3 : ");
Serial.println(speed3);
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() {
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(); }
todo = "";
}