Skip to content

Commit

Permalink
Merge pull request #10 from dmadison/platforms
Browse files Browse the repository at this point in the history
Platforms
  • Loading branch information
dmadison committed Jul 27, 2018
2 parents adb9171 + 8bf8cdb commit e32c2d7
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 24 deletions.
19 changes: 2 additions & 17 deletions Arduino/DJLucio/DJLucio.ino
Expand Up @@ -32,6 +32,7 @@ const unsigned long ConnectRate = 500; // Rate to attempt reconnections, i
const unsigned long ConfigThreshold = 3000; // Time the euphoria and green buttons must be held to set a new config (ms)
const unsigned long EffectsTimeout = 1200; // Timeout for the effects tracker, in ms
const uint8_t EffectThreshold = 10; // Threshold to trigger abilities from the fx dial, 10 = 1/3rd of a revolution
// #define IGNORE_DETECT_PIN // Ignore the state of the 'controller detect' pin, for breakouts without one.

// Debug Flags (uncomment to add)
// #define DEBUG // Enable to use any prints
Expand Down Expand Up @@ -71,15 +72,8 @@ KeyboardButton jump(' ');

EffectHandler fx(dj, EffectsTimeout);

const uint8_t DetectPin = 4; // Pulled low by EXTERNAL pull-down (not optional!)
const uint8_t SafetyPin = 9; // Pulled high by internal pull-up
const uint8_t LEDPin = 17; // RX LED on the Pro Micro

const boolean LEDInverted = true; // Inverted on the Pro Micro (LOW is lit)

LEDHandler LED(LEDPin, LEDInverted);
ConnectionHelper controller(dj, DetectPin, UpdateRate, DetectTime, ConnectRate);
TurntableConfig config(dj, &DJTurntableController::buttonEuphoria, &DJTurntableController::TurntableExpansion::buttonGreen, 3000);
TurntableConfig config(dj, &DJTurntableController::buttonEuphoria, &DJTurntableController::TurntableExpansion::buttonGreen, ConfigThreshold);

void setup() {
#ifdef DEBUG
Expand All @@ -93,8 +87,6 @@ void setup() {
for (;;); // Safety loop!
}

startMultiplexer(); // Enable the multiplexer, currently being used as a level shifter (to be removed)

LED.begin(); // Set LED pin mode
config.read(); // Set expansion pointers from EEPROM config
controller.begin(); // Initialize controller bus and detect pins
Expand Down Expand Up @@ -211,10 +203,3 @@ void joyWASD(uint8_t x, uint8_t y) {
moveForward.press(y > JoyCenter + JoyDeadzone);
moveBack.press(y < JoyCenter - JoyDeadzone);
}

void startMultiplexer() {
Wire.begin();
Wire.beginTransmission(0x70);
Wire.write(1);
Wire.endTransmission();
}
13 changes: 9 additions & 4 deletions Arduino/DJLucio/DJLucio_ConfigMode.h
Expand Up @@ -81,6 +81,7 @@ class TurntableConfig {
void read() {
EEPROM.get(EEPROM_Addr, currentConfig);
if (!validConfig(currentConfig)) {
D_CFGLN("CFG: EEPROM is bad! Rewriting...");
write(Config::Right); // Fix dirty memory
}
reload();
Expand All @@ -93,10 +94,13 @@ class TurntableConfig {
if (currentConfig == Config::Left) {
mainTable = &Controller.left;
altTable = &Controller.right;
D_CFGLN("CFG: Set main table LEFT");
}
// Right as main, left as alternate
else if (currentConfig == Config::Right) {
mainTable = &Controller.right;
altTable = &Controller.left;
D_CFGLN("CFG: Set main table RIGHT");
}
}

Expand All @@ -112,17 +116,18 @@ class TurntableConfig {

LED.blink(5, 1000); // Flash the LED to alert the user! 5 hz for 1 second (non-blocking)

D_CFG("Wrote new config! Main table: ");
D_CFG("CFG: Wrote new config! Main table: ");
D_CFGLN(side == Config::Left ? "Left" : "Right");
}

boolean validConfig(Config side) {
return side == Config::Left || side == Config::Right;
}

// Just for fun. Works out to be 508, which is less than
// the 512 bytes available on most smaller AVR boards
static const uint16_t EEPROM_Addr = 'L' + 'u' + 'c' + 'i' + 'o';
// Just for fun. Works out to be 540. No capital 'L' to
// avoid writing to the 0 address on the Teensy LC (508 % 127)
static const uint16_t EEPROM_Addr = ('l' + 'u' + 'c' + 'i' + 'o') % E2END;
static_assert(EEPROM_Addr + 1 <= E2END, "EEPROM address larger than EEPROM space!"); // Var is two bytes

DJTurntableController & Controller;
const DJFunction ConfigInput;
Expand Down
7 changes: 6 additions & 1 deletion Arduino/DJLucio/DJLucio_Controller.h
Expand Up @@ -38,6 +38,7 @@
#define D_COMMS(x)
#endif

extern DJTurntableController dj;
extern LEDHandler LED;

// EffectHandler: Keeps track of changes to the turntable's "effect dial"
Expand Down Expand Up @@ -177,7 +178,11 @@ class ConnectionHelper {

private:
boolean controllerDetected() {
return detect.isDetected();
#ifdef IGNORE_DETECT_PIN
return true;
#else
return detect.isDetected();
#endif
}

ExtensionController & controller;
Expand Down
4 changes: 2 additions & 2 deletions Arduino/DJLucio/DJLucio_HID.h
Expand Up @@ -36,7 +36,7 @@
// HID_Button: Handles HID button state to prevent input spam
class HID_Button {
public:
HID_Button(char k) : key(k) {
HID_Button(uint16_t k) : key(k) {
// If linked list is empty, set both head and tail
if (head == nullptr) {
head = this;
Expand Down Expand Up @@ -105,7 +105,7 @@ class HID_Button {
}
}

const unsigned char key;
const uint16_t key;
private:
static HID_Button * head;
static HID_Button * tail;
Expand Down
4 changes: 4 additions & 0 deletions Arduino/DJLucio/DJLucio_LED.h
Expand Up @@ -21,6 +21,8 @@
#ifndef DJLucio_LED_h
#define DJLucio_LED_h

#include "DJLucio_Platforms.h"

// SoftwareOscillator: oscillates its state output based on the given period, using the millis() timer
class SoftwareOscillator {
public:
Expand Down Expand Up @@ -128,4 +130,6 @@ class LEDHandler {
unsigned long patternStart;
};

LEDHandler LED(LED_Pin, LED_Inverted);

#endif
106 changes: 106 additions & 0 deletions Arduino/DJLucio/DJLucio_Platforms.h
@@ -0,0 +1,106 @@
/*
* Project DJ Hero - Lucio
* @author David Madison
* @link github.com/dmadison/DJHero-Lucio
* @license GPLv3 - Copyright (c) 2018 David Madison
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef DJLucio_Platforms_h
#define DJLucio_Platforms_h

/* Each board type requires the following definitions:
*
* * LED_Pin: the built-in LED pin on the board
* * LED_Inverted: a boolean for whether the built-in LED is
* active high (false) or active low (true)
*
* * DetectPin: pin for detecting whether the controller is
* connected. Typically the next pin after the
* I2C pins. Requires an external pull-down.
*
* * SafetyPin: last-resort pin to recover the microcontroller
* in case of a programming error. Ground this pin to
* halt execution at program start. Typically the Last
* pin on the left side of the controller.
*/

#if defined(__AVR_ATmega32U4__)

// Arduino Pro Micro 5V / 3.3V
#if defined(ARDUINO_AVR_PROMICRO)
const uint8_t LED_Pin = 17; // RX LED on the Pro Micro
const boolean LED_Inverted = true; // Inverted on the Pro Micro (LOW is lit)

const uint8_t DetectPin = 4; // SDA 2, SCL 3
const uint8_t SafetyPin = 9;

// Arduino Leonardo
#elif defined(ARDUINO_AVR_LEONARDO)
const uint8_t LED_Pin = 13;
const boolean LED_Inverted = false;

const uint8_t DetectPin = 4; // SDA 2, SCL 3
const uint8_t SafetyPin = 12;

// Teensy 2.0
#elif defined(CORE_TEENSY)
const uint8_t LED_Pin = 11;
const boolean LED_Inverted = false;

const uint8_t DetectPin = 7; // SCL 5, SDA 6
const uint8_t SafetyPin = 10;

#endif // 32U4 boards

// Teensy 2.0++
#elif defined(__AVR_AT90USB1286__) && defined(CORE_TEENSY)
const uint8_t LED_Pin = 6;
const boolean LED_Inverted = false;

const uint8_t DetectPin = 2; // SCL 0, SDA 1
const uint8_t SafetyPin = 17;

// Teensy 3.0/3.1-3.2/LC/3.5/3.6
#elif (defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__) || \
defined(__MK64FX512__) || defined(__MK66FX1M0__)) && defined(CORE_TEENSY)
const uint8_t LED_Pin = 13;
const boolean LED_Inverted = false;

const uint8_t DetectPin = 17; // SCL 19, SDA 18

// --- Teensy Short boards (3.0 / 3.1-3.2 / LC)
#if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__)
const uint8_t SafetyPin = 12;

// --- Teensy Long boards (3.5 / 3.6)
#elif defined(__MK64FX512__) || defined(__MK66FX1M0__)
const uint8_t SafetyPin = 32;
#endif // Teensy 3.0 short vs long boards

#else
#error Unsupported board! Use a Leonardo, Pro Micro, or Teensy
#endif

// Check Teensy USB type setting
#if defined(TEENSYDUINO)
#if !defined(USB_HID) && !defined(USB_SERIAL_HID) && !defined(USB_HID_TOUCHSCREEN)
#error No USB HID! Did you select a board mode with Mouse + Keyboard?
#elif !defined(LAYOUT_US_ENGLISH)
#error Wrong keyboard layout: requires US English
#endif
#endif

#endif

0 comments on commit e32c2d7

Please sign in to comment.