From d71e82081c0a01db9dd0fdd53d141d8e3bab22ed Mon Sep 17 00:00:00 2001 From: James Wood Date: Mon, 1 Nov 2021 23:16:34 +1100 Subject: [PATCH] Initial commit --- .DS_Store | Bin 0 -> 6148 bytes .gitignore | 5 +++ .vscode/extensions.json | 7 +++ include/README | 39 +++++++++++++++++ lib/README | 46 ++++++++++++++++++++ platformio.ini | 25 +++++++++++ src/main.cpp | 94 ++++++++++++++++++++++++++++++++++++++++ test/README | 11 +++++ 8 files changed, 227 insertions(+) create mode 100644 .DS_Store create mode 100755 .gitignore create mode 100755 .vscode/extensions.json create mode 100755 include/README create mode 100755 lib/README create mode 100755 platformio.ini create mode 100755 src/main.cpp create mode 100755 test/README diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..df6ccb1de8a9ad9494e654a87294dedb59a2ded7 GIT binary patch literal 6148 zcmeHLyH3ME5S$}ML?9$eMCFbSi9axrX=(BUC=WqUf+I+%T~hHWw6qApA0Y87l+50p zj5l^D5kkAt-S}>IZ`Nb^E)D?KTaJ!_Jpf%c!DO3Vi-})a!#3i~KGDe<(~IN&u$avo zkv3rpm;!%M0eN>59ASo(6T_tjP1hw2(P&2Ib@7!^?^GkAC#eFKc_l*)vnI zMczByVu%7Gj1@Z$cA62o2E2XT`x;i(nHBX))Ydf`Qg0+5Psc;g5M*hl)3PTlsErgQ4czefNCcqxmXjJA8)B z(|oJm7QO@vjG4R8jP8?+l}~e4cTw}Vs$2P6c)7e872ugI)|EHS%oH#MOo6%rvOlD3 zf?32epx-*!ZEz_5L{N;^{_G;Aahydg1JXltA(a?XUHrswA)WJSjLRaH0Yf^RXXZMQ z*~Kpu=h-=*`f#``p!KGJDWDbTgyEi?|EKG}|8dLChkS0Xajn9|B$m>r8=PRp1LWI THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/platformio.ini b/platformio.ini new file mode 100755 index 0000000..539124f --- /dev/null +++ b/platformio.ini @@ -0,0 +1,25 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:due] +platform = atmelsam +board = dueUSB +framework = arduino +lib_deps = + mheironimus/Joystick @ ^2.0.7 + paulstoffregen/Encoder @ ^1.4.1 + ; nicohood/HID-Project @ ^2.6.1 +monitor_speed = 115200 +; monitor_port = /dev/tty.usbmodemHIDPE1 +upload_port = /dev/tty.usbmodem22301 +monitor_port = /dev/tty.usbmodem22301 +; upload_port = /dev/tty.usbmodem22301 +; monitor_port = /dev/cu.usbmodemHIDAF1 +; upload_port = /dev/cu.usbmodemHIDAF1 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100755 index 0000000..27cc22c --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,94 @@ +#include +#include +#include + +#define MAXLAG 5 +#define NUMBEROFENCODERS 5 +#define NUMBEROFBUTTONS 6 +#define BUTTONPRESSTIME 50 +#define BUTTONRELEASETIME 25 + +const int dataPins[]={28,31,33,35,37}; +const int clockPins[]={29,30,32,34,36}; +const int encButtonPins[]={38,40,42,44,46}; +const int buttonPins[]={2,3,4,5,6,7}; + +Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, + JOYSTICK_TYPE_GAMEPAD, (NUMBEROFENCODERS * 3) + NUMBEROFBUTTONS, 0, + false, false, false, false, false, false, + false, false, false, false, false); + +enum buttonStates {ready, requested, active, hold}; +buttonStates encButtonState[NUMBEROFENCODERS * 3]; +unsigned long encButtonActiveTime[NUMBEROFENCODERS * 3]; +long reportedPosition[NUMBEROFENCODERS]; + +// struct RGB { +// byte r; +// byte g; +// byte b; +// }; + +// RGB variable = { 255 , 0 , 0 }; + +Encoder myEnc[NUMBEROFENCODERS] = { + Encoder(clockPins[0], dataPins[0]), + Encoder(clockPins[1], dataPins[1]), + Encoder(clockPins[2], dataPins[2]), + Encoder(clockPins[3], dataPins[3]), + Encoder(clockPins[4], dataPins[4]) +}; + +void setup() { + for(int i = 0; i reportedPosition[encoderNumber])) { + encButtonState[upBtn] = requested; + encoderPosition - reportedPosition[encoderNumber] > MAXLAG ? reportedPosition[encoderNumber] = encoderPosition - MAXLAG : reportedPosition[encoderNumber]++; + } + if((encButtonState[dnBtn] == ready) && (reportedPosition[encoderNumber] > encoderPosition)) { + encButtonState[dnBtn] = requested; + reportedPosition[encoderNumber] - encoderPosition > MAXLAG ? reportedPosition[encoderNumber] = encoderPosition + MAXLAG : reportedPosition[encoderNumber]--; + } +} + +void performPresses(int buttonNumber){ + if(encButtonState[buttonNumber] == requested) pushEncButton(buttonNumber); + if((encButtonState[buttonNumber] == active) && (millis() - encButtonActiveTime[buttonNumber] > BUTTONPRESSTIME)) releaseEncButton(buttonNumber); + if((encButtonState[buttonNumber] == hold) && (millis() - encButtonActiveTime[buttonNumber] > BUTTONRELEASETIME)) encButtonState[buttonNumber] = ready; +} + +void loop() { + for(int buttonNumber = 0; buttonNumber