103 lines
2.4 KiB
C++
103 lines
2.4 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;
|
|
|
|
// 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;
|
|
|
|
bool keypressed = false;
|
|
int cursorspeed, speed1, speed2, speed3;
|
|
String input1, input2, input3;
|
|
|
|
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);
|
|
|
|
// retrieve settings from memory
|
|
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");
|
|
|
|
cursorspeed = speed2 / 10;
|
|
|
|
// Affichage des valeurs récupérer 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("Entrée 1 : ");
|
|
Serial.println(input1);
|
|
Serial.print("Entrée 2 : ");
|
|
Serial.println(input2);
|
|
Serial.print("Entrée 3 : ");
|
|
Serial.println(input3);
|
|
|
|
moozyPrefs.end();
|
|
|
|
// initialize mouse control:
|
|
Mouse.begin();
|
|
Keyboard.begin();
|
|
USB.begin();
|
|
}
|
|
|
|
void loop() {
|
|
// use serial input to control the mouse:
|
|
if (Serial.available() > 0) {
|
|
char inChar = Serial.read();
|
|
|
|
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);
|
|
}
|
|
//}
|
|
}
|