generated from thinkode/modelRepository
added the plane rudder
This commit is contained in:
BIN
SkyControlSuite.hid
Normal file
BIN
SkyControlSuite.hid
Normal file
Binary file not shown.
18
SkyControlSuite/SkyControlSuite.h
Normal file
18
SkyControlSuite/SkyControlSuite.h
Normal file
@@ -0,0 +1,18 @@
|
||||
// C:\Users\valen\Documents\Projets\SkyControlSuite\SkyControlSuite\SkyControlSuite.h
|
||||
|
||||
|
||||
char ReportDescriptor[23] = {
|
||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||
0x09, 0x04, // USAGE (Joystick)
|
||||
0xa1, 0x01, // COLLECTION (Application)
|
||||
0x05, 0x02, // USAGE_PAGE (Simulation Controls)
|
||||
0x09, 0xba, // USAGE (Rudder)
|
||||
0x15, 0x81, // LOGICAL_MINIMUM (-127)
|
||||
0x25, 0x7f, // LOGICAL_MAXIMUM (127)
|
||||
0x85, 0x01, // REPORT_ID (1)
|
||||
0x75, 0x08, // REPORT_SIZE (8)
|
||||
0x95, 0x01, // REPORT_COUNT (1)
|
||||
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||
0xc0 // END_COLLECTION
|
||||
};
|
||||
|
||||
90
SkyControlSuite/SkyControlSuite.ino
Normal file
90
SkyControlSuite/SkyControlSuite.ino
Normal file
@@ -0,0 +1,90 @@
|
||||
#include <HID.h>
|
||||
|
||||
static const uint8_t ReportDescriptor[] PROGMEM = {
|
||||
|
||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||
0x09, 0x04, // USAGE (Joystick)
|
||||
0xa1, 0x01, // COLLECTION (Application)
|
||||
0x05, 0x02, // USAGE_PAGE (Simulation Controls)
|
||||
0x09, 0xba, // USAGE (Rudder)
|
||||
0x15, 0x81, // LOGICAL_MINIMUM (-127)
|
||||
0x25, 0x7f, // LOGICAL_MAXIMUM (127)
|
||||
0x85, 0x01, // REPORT_ID (1)
|
||||
0x75, 0x08, // REPORT_SIZE (8)
|
||||
0x95, 0x01, // REPORT_COUNT (1)
|
||||
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||
0xc0 // END_COLLECTION
|
||||
};
|
||||
|
||||
const int rudderPin = A0;
|
||||
|
||||
const int sensibility = 5;
|
||||
const int maxRudder = 1023;
|
||||
const int minRudder = 20;
|
||||
|
||||
int middle = (maxRudder - minRudder) / 2;
|
||||
|
||||
float smoothedValue = 0; // Valeur lissée;
|
||||
|
||||
const int numReadings = 10; // Nombre d'échantillons pour la moyenne
|
||||
int readings[numReadings]; // Tableau pour stocker les valeurs des échantillons
|
||||
|
||||
int readIndex = 0; // Index pour le tableau
|
||||
int total = 0; // Total des valeurs lues
|
||||
int average = 0; // Valeur moyenne
|
||||
|
||||
int oldAverage = average;
|
||||
|
||||
uint8_t data[1];
|
||||
|
||||
void setup() {
|
||||
static HIDSubDescriptor node(ReportDescriptor, sizeof(ReportDescriptor));
|
||||
HID().AppendDescriptor(&node);
|
||||
|
||||
// Initialiser le tableau de lectures
|
||||
for (int i = 0; i < numReadings; i++) {
|
||||
readings[i] = 0;
|
||||
}
|
||||
|
||||
//Serial.begin(9600);
|
||||
|
||||
pinMode(rudderPin, INPUT_PULLUP);
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Soustraire la lecture précédente de la somme
|
||||
total = total - readings[readIndex];
|
||||
|
||||
// Lire la valeur du potentiomètre
|
||||
readings[readIndex] = analogRead(rudderPin);
|
||||
|
||||
// Ajouter la lecture actuelle à la somme
|
||||
total = total + readings[readIndex];
|
||||
|
||||
// Calculer la moyenne
|
||||
average = total / numReadings;
|
||||
|
||||
//Serial.println(average);
|
||||
|
||||
// Send value to the PC
|
||||
int8_t mapped = map(average, minRudder, maxRudder, -127, 127);
|
||||
int8_t value = constrain(mapped, -127, 127);
|
||||
|
||||
data[0] = value;
|
||||
//Serial.println(value);
|
||||
HID().SendReport(0x01, data, sizeof(data));
|
||||
|
||||
// Switch on the LED if it's in the middle
|
||||
digitalWrite(LED_BUILTIN, abs(value) <= sensibility);
|
||||
|
||||
oldAverage = average;
|
||||
|
||||
// Avancer à la lecture suivante dans le tableau
|
||||
readIndex = readIndex + 1;
|
||||
|
||||
// Recommencer au début du tableau si nécessaire
|
||||
if (readIndex >= numReadings) {
|
||||
readIndex = 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user