2023-09-27 10:25:19 +02:00
|
|
|
/*
|
|
|
|
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;
|
|
|
|
|
2023-11-07 15:38:55 +01:00
|
|
|
// Variable and constant declarations
|
|
|
|
// ----------------------------------
|
|
|
|
|
2023-11-11 19:03:57 +01:00
|
|
|
// set pin numbers for each inputs:
|
|
|
|
const int PinInput1 = 1;
|
|
|
|
const int PinInput2 = 2;
|
|
|
|
const int PinInput3 = 3;
|
|
|
|
#define LedMoozy 48
|
|
|
|
|
|
|
|
unsigned long debouncetime;
|
|
|
|
bool keypressed = false, doNotRepeat = false;
|
2023-09-27 10:25:19 +02:00
|
|
|
int cursorspeed, speed1, speed2, speed3;
|
2023-11-07 15:38:55 +01:00
|
|
|
int currentspeed = 2;
|
2023-11-11 19:03:57 +01:00
|
|
|
String todo, fctinput1, fctinput2, fctinput3;
|
2023-11-07 15:38:55 +01:00
|
|
|
|
2023-11-11 19:03:57 +01:00
|
|
|
/*
|
2023-11-07 15:38:55 +01:00
|
|
|
// Interrupt Service Routine
|
|
|
|
// -------------------------
|
|
|
|
void ISR_Inputs () {
|
2023-11-11 19:03:57 +01:00
|
|
|
if (!digitalRead(PinInput1)) { todo = fctinput1; }
|
2023-11-07 15:38:55 +01:00
|
|
|
if (!digitalRead(PinInput2)) { todo = fctinput2; }
|
|
|
|
if (!digitalRead(PinInput3)) { todo = fctinput3; }
|
2023-11-11 19:03:57 +01:00
|
|
|
}*/
|
2023-09-27 10:25:19 +02:00
|
|
|
|
2023-11-07 15:38:55 +01:00
|
|
|
// Initialisations
|
|
|
|
// ---------------
|
2023-09-27 10:25:19 +02:00
|
|
|
void setup() {
|
|
|
|
|
|
|
|
// initialize the buttons' inputs:
|
2023-11-07 15:38:55 +01:00
|
|
|
pinMode(PinInput1, INPUT_PULLUP);
|
|
|
|
pinMode(PinInput2, INPUT_PULLUP);
|
|
|
|
pinMode(PinInput3, INPUT_PULLUP);
|
2023-11-11 19:03:57 +01:00
|
|
|
pinMode(LedMoozy, OUTPUT);
|
2023-09-27 10:25:19 +02:00
|
|
|
|
2023-11-07 15:38:55 +01:00
|
|
|
// retrieve settings from flash nvs
|
2023-09-27 10:25:19 +02:00
|
|
|
moozyPrefs.begin("myapp", true); //namespace / true = RO MODE
|
|
|
|
speed1 = moozyPrefs.getInt("speed1");
|
|
|
|
speed2 = moozyPrefs.getInt("speed2");
|
|
|
|
speed3 = moozyPrefs.getInt("speed3");
|
2023-11-07 15:38:55 +01:00
|
|
|
fctinput1 = moozyPrefs.getString("input1");
|
|
|
|
fctinput2 = moozyPrefs.getString("input2");
|
|
|
|
fctinput3 = moozyPrefs.getString("input3");
|
|
|
|
moozyPrefs.end();
|
2023-09-27 10:25:19 +02:00
|
|
|
|
2023-11-11 19:03:57 +01:00
|
|
|
cursorspeed = speed2 / 20;
|
|
|
|
debouncetime = millis();
|
2023-09-27 10:25:19 +02:00
|
|
|
|
|
|
|
// initialize mouse control:
|
|
|
|
Mouse.begin();
|
|
|
|
Keyboard.begin();
|
|
|
|
USB.begin();
|
2023-11-07 15:38:55 +01:00
|
|
|
|
|
|
|
// initialize interruptions
|
2023-11-11 19:03:57 +01:00
|
|
|
/*attachInterrupt(digitalPinToInterrupt(PinInput1), ISR_Inputs, CHANGE);
|
2023-11-07 15:38:55 +01:00
|
|
|
attachInterrupt(digitalPinToInterrupt(PinInput2), ISR_Inputs, CHANGE);
|
2023-11-11 19:03:57 +01:00
|
|
|
attachInterrupt(digitalPinToInterrupt(PinInput3), ISR_Inputs, CHANGE);*/
|
|
|
|
|
|
|
|
// To say Hello on startup
|
|
|
|
digitalWrite(LedMoozy, true);
|
|
|
|
delay(150);
|
|
|
|
digitalWrite(LedMoozy, false);
|
|
|
|
delay(150);
|
|
|
|
digitalWrite(LedMoozy, true);
|
|
|
|
delay(150);
|
|
|
|
digitalWrite(LedMoozy, false);
|
2023-09-27 10:25:19 +02:00
|
|
|
}
|
|
|
|
|
2023-11-07 15:38:55 +01:00
|
|
|
// Main loop
|
|
|
|
// -------------
|
2023-09-27 10:25:19 +02:00
|
|
|
void loop() {
|
2023-11-11 19:03:57 +01:00
|
|
|
if (!digitalRead(PinInput1)) { todo = fctinput1; }
|
|
|
|
if (!digitalRead(PinInput2)) { todo = fctinput2; }
|
|
|
|
if (!digitalRead(PinInput3)) { todo = fctinput3; }
|
|
|
|
|
|
|
|
if ((todo != "") & (millis() > debouncetime + 100)) {
|
|
|
|
if ((todo =="LC") & (!doNotRepeat)) {doNotRepeat = true; dolc(); }
|
|
|
|
if ((todo =="LCD") & (!doNotRepeat)) {doNotRepeat = true; dolcd(); }
|
|
|
|
if ((todo =="LCH") & (!doNotRepeat)) {doNotRepeat = true; dolch(); }
|
|
|
|
if ((todo =="RC") & (!doNotRepeat)) {doNotRepeat = true; dorc(); }
|
|
|
|
if ((todo =="RCD") & (!doNotRepeat)) {doNotRepeat = true; dorcd(); }
|
|
|
|
if ((todo =="RCH") & (!doNotRepeat)) {doNotRepeat = true; 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") & (!doNotRepeat)) {doNotRepeat = true; tospeed1(); }
|
|
|
|
if ((todo =="speed2") & (!doNotRepeat)) {doNotRepeat = true; tospeed2(); }
|
|
|
|
if ((todo =="speed3") & (!doNotRepeat)) {doNotRepeat = true; tospeed3(); }
|
|
|
|
|
|
|
|
if (todo =="speedinc") { incspeed(); }
|
|
|
|
if (todo =="speeddec") { decspeed(); }
|
|
|
|
|
|
|
|
if ((todo =="mode1") & (!doNotRepeat)) {doNotRepeat = true; tomode1(); }
|
|
|
|
if ((todo =="mode2") & (!doNotRepeat)) {doNotRepeat = true; tomode2(); }
|
|
|
|
if ((todo =="mode3") & (!doNotRepeat)) {doNotRepeat = true; tomode3(); }
|
|
|
|
|
|
|
|
debouncetime = millis();
|
|
|
|
}
|
2023-09-27 10:25:19 +02:00
|
|
|
|
2023-11-07 15:38:55 +01:00
|
|
|
todo = "";
|
2023-11-11 19:03:57 +01:00
|
|
|
if ((digitalRead(PinInput1)) & (digitalRead(PinInput2)) & (digitalRead(PinInput3))) { doNotRepeat = false; }
|
|
|
|
|
|
|
|
digitalWrite(LedMoozy, false);
|
2023-09-27 10:25:19 +02:00
|
|
|
}
|