Your Name il y a 3 ans
commit
9335d93e31
3 fichiers modifiés avec 162 ajouts et 0 suppressions
  1. 35 0
      AVRPort23.h
  2. BIN
      RCUSB4 Wiring.jpg
  3. 127 0
      RCUSB4.ino

+ 35 - 0
AVRPort23.h

@@ -0,0 +1,35 @@
+/* 
+ * kekse23.de AVRPort23
+ * Copyright (c) 2017, Nicholas Regitz
+ * 
+ * Diese Datei ist Lizensiert unter der Creative Commons 4.0 CC BY-NC-SA
+ * https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
+ */
+
+/*
+   portMode(port, pin, mode, state)
+   portMode2(port, pin, mode)
+   portRead(port, pin)
+   portWrite(port, pin, value)
+   portToggle(port, pin)
+*/
+
+#define __portGet(port, pin)          ((PIN##port >> pin) & 0x01)
+#define __portSet(port, pin)          ((PORT##port) |= (1 << pin))
+#define __portClear(port, pin)        ((PORT##port) &= ~(1 << pin))
+#define __portToggle(port, pin)       ((PIN##port) |= (1 << pin))
+#define __portToggle2(port, pin)      ((PORT##port) ^= (1 << pin)) //Belegt 4 byte mehr
+#define __portInput(port, pin)        ((DDR##port) &= ~(1 << pin))
+#define __portOutput(port, pin)       ((DDR##port) |= (1 << pin))
+
+#define __portMode(port, pin, mode, state)  (mode ? __portOutput(port, pin) : __portInput(port, pin)) & (state ? __portSet(port, pin) : __portClear(port, pin))
+#define __portModeS(port, pin, mode)  (mode ? __portOutput(port, mode) : __portInput(port, mode))
+#define __portWrite(port, pin, value) (value ? __portSet(port, pin) : __portClear(port, pin))
+
+#define portMode(args...) __portMode(args)
+#define portModeS(args...) __portModeS(args)
+
+#define portRead(args...) __portGet(args)
+#define portWrite(args...) __portWrite(args)
+#define portToggle(args...) __portToggle(args)
+

BIN
RCUSB4 Wiring.jpg


+ 127 - 0
RCUSB4.ino

@@ -0,0 +1,127 @@
+/* 
+ * kekse23.de RCUSB4 v1.1
+ * Copyright (c) 2020, Nicholas Regitz
+ * 
+ * Diese Datei ist Lizensiert unter der Creative Commons 4.0 CC BY-NC-SA
+ * https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
+ */
+
+#include <Joystick.h>
+#include "AVRPort23.h"
+
+#define CHAN1 D,0
+#define _INT1 0
+#define CHAN2 D,1
+#define _INT2 1
+#define CHAN3 D,3
+#define _INT3 3
+#define CHAN4 D,2
+#define _INT4 2
+#define RXLED B,0
+#define TXLED D,5
+
+Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD,
+  0, 0,                 // Button Count, Hat Switch Count
+  true, true, false,  // X, Y, Z
+  true, true, false,  // Rx, Ry, Rz
+  false, false,          // Rudder, Throttle
+  false, false, false);    // Accelerator, Brake, Steering
+
+void setup()
+{
+  portMode(CHAN1, INPUT, HIGH);
+  portMode(CHAN2, INPUT, HIGH);
+  portMode(CHAN3, INPUT, HIGH);
+  portMode(CHAN4, INPUT, HIGH);
+  portMode(RXLED, OUTPUT, LOW);
+  portMode(TXLED, OUTPUT, LOW);
+  
+  Joystick.begin();
+  Joystick.setXAxisRange(2250, 750);
+  Joystick.setYAxisRange(2250, 750);
+  Joystick.setRxAxisRange(2250, 750);
+  Joystick.setRyAxisRange(2250, 750);
+  
+  attachInterrupt(_INT1, isr1, CHANGE);
+  attachInterrupt(_INT2, isr2, CHANGE);
+  attachInterrupt(_INT3, isr3, CHANGE);
+  attachInterrupt(_INT4, isr4, CHANGE);
+}
+
+volatile unsigned long Time[4];
+volatile unsigned int Value[4];
+volatile bool ValChanged[4];
+unsigned int NewValue[4];
+
+void loop()
+{   
+  if (ValChanged[0])
+  {
+    NewValue[0] = (NewValue[0]+Value[0])/2;
+    Joystick.setXAxis(NewValue[0]);
+    ValChanged[0] = false;
+  }
+
+  if (ValChanged[1])
+  {
+    NewValue[1] = (NewValue[1]+Value[1])/2;
+    Joystick.setYAxis(NewValue[1]);
+    ValChanged[1] = false;
+  }
+  
+   if (ValChanged[2])
+  {
+    NewValue[2] = (NewValue[2]+Value[2])/2;
+    Joystick.setRxAxis(NewValue[2]);
+    ValChanged[2] = false;
+  }
+  
+   if (ValChanged[3])
+  {
+    NewValue[3] = (NewValue[3]+Value[3])/2;
+    Joystick.setRyAxis(NewValue[3]);
+    ValChanged[3] = false;
+  }
+  
+  delay(1);
+}
+
+void isr1()
+{
+  if (portRead(CHAN1)) Time[0] = micros();
+  else if (micros() > Time[0])
+  {
+    Value[0] = (Value[0]+(micros()-Time[0]))/2;
+    ValChanged[0] = true;
+  }
+}
+
+void isr2()
+{
+  if (portRead(CHAN2)) Time[1] = micros();
+  else if (micros() > Time[1])
+  {
+    Value[1] = (Value[1]+(micros()-Time[1]))/2;
+    ValChanged[1] = true;
+  }
+}
+
+void isr3()
+{
+  if (portRead(CHAN3)) Time[2] = micros();
+  else if (micros() > Time[2])
+  {
+    Value[2] = (Value[2]+(micros()-Time[2]))/2;
+    ValChanged[2] = true;
+  }
+}
+
+void isr4()
+{
+  if (portRead(CHAN4)) Time[3] = micros();
+  else if (micros() > Time[3])
+  {
+    Value[3] = (Value[3]+(micros()-Time[3]))/2;
+    ValChanged[3] = true;
+  }
+}