Git Product home page Git Product logo

Comments (2)

Mcletsplay001 avatar Mcletsplay001 commented on September 21, 2024

forgot to add the error (in German) :
Dieses Gerät wurde angehalten, weil es Fehler gemeldet hat. (Code 43)
Fehler bei einer Anforderung des USB-Gerätedeskriptors.

from hoodloader2.

Mcletsplay001 avatar Mcletsplay001 commented on September 21, 2024

yes I fixt it had to change the way it recived the values

#include <Mouse.h>
#include <Keyboard.h>

const int joystickCenterX = 512; // Beispielmittelpunkt des Joysticks für die X-Achse
const int joystickCenterY = 512; // Beispielmittelpunkt des Joysticks für die Y-Achse
const int joystickDeadzone = 10; // Totzone zur Vermeidung von Drift um den Mittelpunkt
const float scalingFactor = 0.05; // Skalierungsfaktor für die Mausbewegung

void setup() {
  // Starten der HID-Bibliotheken
  Keyboard.begin();
  Mouse.begin();
  // HID().begin();
  // Serielle Kommunikation initialisieren
  Serial1.begin(115200); // Kommunikation mit dem IO-MCU
  //Serial.begin(74880); // Debugging
}

void loop() {
  if (Serial1.available()) {
    char zeile[100];
    Serial1.readBytesUntil('\n', zeile, 100);
    zeile[strlen(zeile) - 1] = '\0';
    processValues(zeile);
  }
}

void processValues(char* zeile) {
  int values[15];
  int i = 0;

  // Tokenisierung des Strings
  char* token = strtok(zeile, ";");
  while (token != nullptr && i < 15) {
    values[i] = atoi(token); // ASCII to Integer
    token = strtok(nullptr, ";");
    i++;
  }

  // Werte in Variablen zuweisen
  int blinkerR = values[0];
  int blinkerL = values[1];
  int WarnB = values[2];
  int Hand = values[3];
  int Horn = values[4];
  int Z0 = values[5];
  int Z1 = values[6];
  int Z2 = values[7];
  int Z3 = values[8];
  int L1 = values[9];
  int Mousex = values[10];
  int Mousey = values[11];
  int MouseR = values[12];
  int MouseL = values[13];
  int MouseM = values[14];
  
    if (blinkerR == 1) {
      Keyboard.press(KEY_KP_7);
      Keyboard.release(KEY_KP_7);
    }

    if (blinkerL == 1) {
      Keyboard.press(',');
      Keyboard.release(',');
    }

    if (WarnB == 1) {
      Keyboard.press(KEY_KP_8);
      Keyboard.release(KEY_KP_8);
    }

    if (Hand == 1) {
      Keyboard.press('p');
      Keyboard.release('p');
    }

    if (Horn == 1) {
      Keyboard.press('h');
      Keyboard.release('h');
    }

    if (Z0 == 1) {
      Keyboard.press(KEY_F20);
      Keyboard.release(KEY_F20);
    }

    if (Z1 == 1) {
      Keyboard.press(KEY_F22);
      Keyboard.release(KEY_F22);
    }

    if (Z2 == 1) {
      Keyboard.press(KEY_F23);
      Keyboard.release(KEY_F23);
    }

    if (Z3 == 1) {
      Keyboard.press(KEY_F24);
      Keyboard.release(KEY_F24);
    }

    if (L1 == 1) {
      Keyboard.press('n');
      Keyboard.release('n');
    }
  
  //Serial.print(Mousex);
  //Serial.println(Mousey);


  int deltaX = Mousex - joystickCenterX;
  int deltaY = Mousey - joystickCenterY;

  if (abs(deltaX) < joystickDeadzone) deltaX = 0;
  if (abs(deltaY) < joystickDeadzone) deltaY = 0;
  deltaY = -deltaY;
  deltaX *= scalingFactor;
  deltaY *= scalingFactor;

  Mouse.move(deltaX, deltaY, 0);

  if (MouseR == 1) {
    Mouse.press(MOUSE_RIGHT);
  } else {
    Mouse.release(MOUSE_RIGHT);
  }

  if (MouseL == 1) {
    Mouse.press(MOUSE_LEFT);
  } else {
    Mouse.release(MOUSE_LEFT);
  }

  if (MouseM == 1) {
    Mouse.press(MOUSE_MIDDLE);
  } else {
    Mouse.release(MOUSE_MIDDLE);
  }

from hoodloader2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.