Refactor code substantially, moving buttons into separate classes and using a lot more pointers to conserve memory until it is needed.

This commit is contained in:
2021-11-08 01:37:30 +00:00
parent 346e612f65
commit a69c2d3364
6 changed files with 285 additions and 185 deletions

View File

@ -5,7 +5,7 @@
#include <Joystick.h>
#include <Mux.h>
using admux::Pinset;
using namespace admux;
bool debug = false;
Joystick joystick(debug);
@ -26,7 +26,9 @@ void setup() {
Pinset addr_pins = Pinset(10, 11, 12, 13);
uint8_t mux_id = joystick.AddMux(9, addr_pins);
joystick.AddMuxButton(mux_id, 0, BUTTON_PASSTHRU);
Mux* mux = new Mux(Pin(9, INPUT_PULLUP, PinType::Digital), Pinset(10, 11, 12, 13));
joystick.AddButton(0, BUTTON_PASSTHRU, true, mux);
// start up serial communication
joystick.Init();

View File

@ -9,6 +9,8 @@
#include <Joystick.h>
#include <Mux.h>
using namespace admux;
bool debug = false;
Joystick joystick(debug);
@ -29,17 +31,17 @@ void setup() {
joystick.AddButton(A0, BUTTON_PASSTHRU);
// to get more room for our inputs, we add an 8-bit multiplexer
uint8_t mux = joystick.AddMux(A1, admux::Pinset(A2, A3, A4, A5), 4);
Mux* mux = new Mux(Pin(A1, INPUT_PULLUP, PinType::Digital), Pinset(A2, A3, A4, A5));
// now we can add the rest of the buttons
joystick.AddMuxButton(mux, 0, BUTTON_PASSTHRU);
joystick.AddMuxButton(mux, 1, BUTTON_PASSTHRU);
joystick.AddMuxButton(mux, 2, BUTTON_PASSTHRU);
joystick.AddMuxButton(mux, 3, BUTTON_PASSTHRU);
joystick.AddMuxButton(mux, 4, BUTTON_PASSTHRU);
joystick.AddMuxButton(mux, 5, BUTTON_PASSTHRU);
joystick.AddMuxButton(mux, 6, BUTTON_PASSTHRU);
joystick.AddMuxButton(mux, 7, BUTTON_PASSTHRU);
joystick.AddButton(0, BUTTON_PASSTHRU, true, mux);
joystick.AddButton(1, BUTTON_PASSTHRU, true, mux);
joystick.AddButton(2, BUTTON_PASSTHRU, true, mux);
joystick.AddButton(3, BUTTON_PASSTHRU, true, mux);
joystick.AddButton(4, BUTTON_PASSTHRU, true, mux);
joystick.AddButton(5, BUTTON_PASSTHRU, true, mux);
joystick.AddButton(6, BUTTON_PASSTHRU, true, mux);
joystick.AddButton(7, BUTTON_PASSTHRU, true, mux);
joystick.Init();
}