Skip to content

Commit

Permalink
Arduino Enum Renaming
Browse files Browse the repository at this point in the history
The former enum names conflicted with Arduino.h enum names.
  • Loading branch information
TekuConcept committed Apr 19, 2017
1 parent 1660a32 commit 6255e0c
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 35 deletions.
20 changes: 11 additions & 9 deletions ArduinoController/ArduinoController.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,24 @@ const uint32_t CONTROLLER_CNT = 13u;
class IController* controllers[CONTROLLER_CNT];

void setup() {
delay(1);
Serial.begin(115200);
Serial1.begin(9600);
DMSGN("Due Ready!");
SerialTools::writeString("Ready!", 6);

controllers[0]= new KillSwitchController(controllers, CONTROLLER_CNT);
attachInterrupt(
digitalPinToInterrupt(KILLSWITCH_PIN),
[](){((KillSwitchController*)controllers[0])->isr(KILLSWITCH_PIN);},
digitalPinToInterrupt(GpioPin::KILLSWITCH_PIN),
[](){((KillSwitchController*)controllers[0])->isr(GpioPin::KILLSWITCH_PIN);},
CHANGE
);
controllers[1] = new ThrustController(PWM::MOVE_PIN);
controllers[2] = new ThrustController(PWM::STRAFE_PIN);
controllers[3] = new ThrustController(PWM::DIVE_PIN);
controllers[4] = new ThrustController(PWM::YAW_PIN);
controllers[5] = new ThrustController(PWM::PITCH_PIN);
controllers[6] = new ThrustController(PWM::ROLL_PIN);
controllers[1] = new ThrustController(PwmPin::MOVE_PIN);
controllers[2] = new ThrustController(PwmPin::STRAFE_PIN);
controllers[3] = new ThrustController(PwmPin::DIVE_PIN);
controllers[4] = new ThrustController(PwmPin::YAW_PIN);
controllers[5] = new ThrustController(PwmPin::PITCH_PIN);
controllers[6] = new ThrustController(PwmPin::ROLL_PIN);
controllers[7] = new EscController();
controllers[8] = new LedController();
controllers[9] = new PingController();
Expand All @@ -47,4 +49,4 @@ void loop() {
DMSG("Controller: "); DMSGN(controllerIndex);
controllers[controllerIndex]->execute();
}
}
}
12 changes: 6 additions & 6 deletions ArduinoController/EscController.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ class EscController : public IController {

private:
uint8_t GPIO_PINS[GPIO_CNT] = {
GPIO::ESC_S1_PIN,
GPIO::ESC_S2_PIN,
GPIO::ESC_S3_PIN,
GPIO::ESC_S4_PIN,
GPIO::ESC_S5_PIN,
GPIO::ESC_S6_PIN
GpioPin::ESC_S1_PIN,
GpioPin::ESC_S2_PIN,
GpioPin::ESC_S3_PIN,
GpioPin::ESC_S4_PIN,
GpioPin::ESC_S5_PIN,
GpioPin::ESC_S6_PIN
};
public:
EscController() {
Expand Down
4 changes: 2 additions & 2 deletions ArduinoController/IController.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef ITHRUSTER_H
#define ITHRUSTER_H
#ifndef ICONTROLLER_H
#define ICONTROLLER_H

#include "Arduino.h"
#include "SerialTools.h"
Expand Down
4 changes: 2 additions & 2 deletions ArduinoController/KillSwitchController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class KillSwitchController : public IController {
KillSwitchController(IController ** _list_, int _count_) {
list = _list_;
count = _count_;
pinMode(GPIO::LED_STAT_PIN, OUTPUT);
pinMode(GpioPin::LED_STAT_PIN, OUTPUT);
}

void execute() {
Expand All @@ -31,7 +31,7 @@ class KillSwitchController : public IController {
active = !digitalRead(interrupt);
if(active)
kill();
digitalWrite(GPIO::LED_STAT_PIN, active);
digitalWrite(GpioPin::LED_STAT_PIN, active);
interrupts();
}
};
10 changes: 5 additions & 5 deletions ArduinoController/LedController.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ class LedController : public IController {
private:
public:
LedController() {
pinMode(GPIO::LED_CTRL_PIN, OUTPUT);
digitalWrite(GPIO::LED_CTRL_PIN, LOW);
pinMode(GpioPin::LED_CTRL_PIN, OUTPUT);
digitalWrite(GpioPin::LED_CTRL_PIN, LOW);
}
void execute() {
for(int i = 0; i < 2; i++) {
digitalWrite(GPIO::LED_CTRL_PIN, HIGH);
digitalWrite(GpioPin::LED_CTRL_PIN, HIGH);
delay(250);
digitalWrite(GPIO::LED_CTRL_PIN, LOW);
digitalWrite(GpioPin::LED_CTRL_PIN, LOW);
delay(250);
}
}
void kill() {
digitalWrite(GPIO::LED_CTRL_PIN, LOW);
digitalWrite(GpioPin::LED_CTRL_PIN, LOW);
}
};
6 changes: 3 additions & 3 deletions ArduinoController/LightController.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
class LightController : public IController {
public:
LightController() {
pinMode(GPIO::LIGHTS_PIN, OUTPUT);
digitalWrite(GPIO::LIGHTS_PIN, HIGH);
pinMode(GpioPin::LIGHTS_PIN, OUTPUT);
digitalWrite(GpioPin::LIGHTS_PIN, HIGH);
}
void execute() {
digitalWrite(GPIO::LIGHTS_PIN, !SerialTools::readByte());
digitalWrite(GpioPin::LIGHTS_PIN, !SerialTools::readByte());
}
void kill() { }
};
8 changes: 4 additions & 4 deletions ArduinoController/PinMap.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef PIN_MAP_H
#define PIN_MAP_H

enum GPIO {
enum GpioPin {
KILLSWITCH_PIN = 50,
LED_STAT_PIN = 22,
LED_CTRL_PIN = 52,
Expand All @@ -13,15 +13,15 @@ enum GPIO {
ESC_S5_PIN = 49,
ESC_S6_PIN = 53,
VOLT_PIN = 10,
}
};

enum PWM {
enum PwmPin {
MOVE_PIN = 13,
STRAFE_PIN = 12,
DIVE_PIN = 11,
YAW_PIN = 9,
PITCH_PIN = 8,
ROLL_PIN = 7,
}
};

#endif
9 changes: 7 additions & 2 deletions ArduinoController/ThrustController.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef ITHRUSTER_H
#define ITHRUSTER_H

#include <Servo.h>
#include "IController.h"

Expand All @@ -8,7 +11,7 @@ class ThrustController : public IController {
const uint16_t REVERSE = 1000;
Servo servo_;
public:
ThrustController(PWM servoPin) {
ThrustController(PwmPin servoPin) {
servo_.attach(servoPin);
servo_.writeMicroseconds(IDLE);
}
Expand All @@ -27,4 +30,6 @@ class ThrustController : public IController {
else if(value < REVERSE) return REVERSE;
else return value;
}
};
};

#endif
4 changes: 2 additions & 2 deletions ArduinoController/VoltageController.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ class VoltageController : public IController {
const double R2 = 7500.0;
public:
VoltageController() {
pinMode(GPIO::VOLT_PIN, INPUT);
pinMode(GpioPin::VOLT_PIN, INPUT);
}

void execute() {
int value = analogRead(GPIO::VOLT_PIN);
int value = analogRead(GpioPin::VOLT_PIN);
/*
* Measured Values for Calibration
* P1 = (11.32, 700); P2 = (8.38, 517)
Expand Down

0 comments on commit 6255e0c

Please sign in to comment.