Skip to content

Commit

Permalink
[Impl] Rudimentäre Unterstützung des ESP32
Browse files Browse the repository at this point in the history
  • Loading branch information
littleyoda committed May 11, 2019
1 parent e81fff7 commit d1f68dc
Show file tree
Hide file tree
Showing 44 changed files with 323 additions and 134 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ Ein flexibles Framework für Modelleisenbahnen-Decoder, auf Basis eines ESP8266.

Der Funktionsumfang lässt sich leicht durch weitere Klassen erweitern.

Weitere Informationen befinden sich im [Wiki](https://github.com/littleyoda/littleyoda-DCC-Decoder/wiki)
Weitere Informationen befinden sich im [Dokumentation](https://littleyoda.github.io/littleyoda-DCC-Decoder-DOC/)

## Status
* in Entwicklung, wird von mehreren Dekodern genutzt
* wird von mehreren Personen produktiv genutzt für verschiedene Arten von
Dekodern

Die folgenden Dekoder nutzen diese Software:
* [Weichendekoder](http://spurg.open4me.de/wordpress/784/Weichendecoder)
Expand Down
16 changes: 10 additions & 6 deletions decoder/ActionDCCGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Based on the work of Juian Zimmermann
* http://www.spassbahn.de/forum/index.php?thread/11462-spa%C3%9Flan-topfschlagen-im-minenfeld/&postID=119804&highlight=julian%2Bdcc#post119804
*/
#ifdef ESP8266

#include <Arduino.h>
#include "Consts.h"
#include "ActionDCCGeneration.h"
Expand All @@ -18,18 +20,18 @@ ActionDCCGeneration::ActionDCCGeneration(Pin* gpio, int locoaddr, int dccoutput)
LOCO_ADR = locoaddr;
enableGpio = gpio;
Logger::getInstance()->addToLog("Starting DCC Generator");
Logger::getInstance()->addToLog("DCC-Output:" + GPIO.gpio2string(SPI.getUsedPin())
Logger::getInstance()->addToLog("DCC-Output:" + GPIOobj.gpio2string(SPI.getUsedPin())
+ " Enabled: " + enableGpio->toString()
+ " Loko-Adresse: " + String(LOCO_ADR)
+ " genutzte DCC Adresse: " + String(DCC_ADRESSE)
);
SPISettings spi = SPISettings(17241, LSBFIRST, SPI_MODE3, false) ;
SPISettings spi = SPISettings(17241, LSBFIRST, my_SPI_MODE3, false) ;
SPI.begin(spi, "DCC");
SPI.beginTransaction(spi);

if (enableGpio->getPin() != Consts::DISABLE) {
GPIO.pinMode(enableGpio, OUTPUT, "DCC Generation");
GPIO.digitalWrite(enableGpio, 0);
GPIOobj.pinMode(enableGpio, OUTPUT, "DCC Generation");
GPIOobj.digitalWrite(enableGpio, 0);
} else {
// Keine Enable-Pin => also immer aktiv
trackenabled = true;
Expand Down Expand Up @@ -87,10 +89,10 @@ void ActionDCCGeneration::DCCSpeed(int id, int speed, int direction, int SpeedSt
Serial.println("Emergency? " + String(speed == Consts::SPEED_EMERGENCY));
if (speed == Consts::SPEED_EMERGENCY) {
trackenabled = false;
GPIO.digitalWrite(enableGpio, 0); // disable Track
GPIOobj.digitalWrite(enableGpio, 0); // disable Track
} else {
trackenabled = true;
GPIO.digitalWrite(enableGpio, 1); // Enable Track
GPIOobj.digitalWrite(enableGpio, 1); // Enable Track
}
} else {
trackenabled = true; // Always tre
Expand Down Expand Up @@ -295,3 +297,5 @@ void ActionDCCGeneration::send() {
SPI.send(SPIBuf, SPIBufUsed);
SPIBufUsed = 0;
}

#endif
3 changes: 3 additions & 0 deletions decoder/ActionDCCGeneration.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#ifndef ACTIONDCCGENERATION_H_
#define ACTIONDCCGENERATION_H_
#ifdef ESP8266

#include "INotify.h"
#include "ILoop.h"
Expand Down Expand Up @@ -61,4 +62,6 @@ class ActionDCCGeneration: public INotify, public ILoop {
requestInfo* r;
};

#endif

#endif /* ACTIONDCCGENERATION_H_ */
2 changes: 2 additions & 0 deletions decoder/ActionDFPlayerMP3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Created on: 21.08.2016
* Author: sven
*/
#ifdef ESP8266

#include "ActionDFPlayerMP3.h"
#include <SoftwareSerial.h>
Expand Down Expand Up @@ -176,3 +177,4 @@ void ActionDFPlayerMP3::checkReceiveBuffer() {
Serial.println("Finish playing! " + String(ansbuf[4] << 16 | ansbuf[5] << 8 | ansbuf[6]));
}
}
#endif
4 changes: 4 additions & 0 deletions decoder/ActionDFPlayerMP3.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#ifndef ACTIONDFPLAYERMP3_H_
#define ACTIONDFPLAYERMP3_H_

#ifdef ESP8266

#include <SoftwareSerial.h>

#include "INotify.h"
Expand Down Expand Up @@ -40,4 +42,6 @@ class ActionDFPlayerMP3: public INotify {
};
;

#endif

#endif /* ACTIONDFPLAYERMP3_H_ */
6 changes: 3 additions & 3 deletions decoder/ActionLed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ActionLed::ActionLed(Pin* g) {
gpio = g;
Logger::getInstance()->addToLog("Starting LED " + g->toString());
GPIO.pinMode(gpio, OUTPUT, "LED");
GPIOobj.pinMode(gpio, OUTPUT, "LED");
}

ActionLed::~ActionLed() {
Expand Down Expand Up @@ -51,10 +51,10 @@ void ActionLed::setSettings(int status) {
}
Logger::getInstance()->addToLog("Led " + gpio->toString() + " changed to " + String(status));
if (status == 0) {
GPIO.digitalWrite(gpio, 0);
GPIOobj.digitalWrite(gpio, 0);
currentStatus = 0;
} else if (status == 1) {
GPIO.digitalWrite(gpio, 1);
GPIOobj.digitalWrite(gpio, 1);
currentStatus = 1;
}
}
Expand Down
42 changes: 21 additions & 21 deletions decoder/ActionPWMOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
ActionPWMOutput::ActionPWMOutput(uint8_t pwm, uint8_t forward, uint8_t reverse) {
Logger::getInstance()->addToLog("Starting PWM...");
Logger::getInstance()->addToLog("PWM-Pin: "
+ GPIO.gpio2string(pwm) + " Forward-Pin: "
+ GPIO.gpio2string(forward) + " Reverse-Pin: "
+ GPIO.gpio2string(reverse)
+ GPIOobj.gpio2string(pwm) + " Forward-Pin: "
+ GPIOobj.gpio2string(forward) + " Reverse-Pin: "
+ GPIOobj.gpio2string(reverse)
);
GPIO.analogWriteFreq(100);
GPIOobj.analogWriteFreq(100);
gpioPWM = pwm;
gpioForward = forward;
gpioReverse = reverse;
String fctname = " PWM Signal";
if (gpioPWM != Consts::DISABLE) {
GPIO.pinMode(gpioPWM, OUTPUT, "PWM: PWM Signal"); GPIO.digitalWrite(gpioPWM, LOW); // PWM Signal
GPIOobj.pinMode(gpioPWM, OUTPUT, "PWM: PWM Signal"); GPIOobj.digitalWrite(gpioPWM, LOW); // PWM Signal
fctname = "";
}
GPIO.pinMode(gpioForward, OUTPUT, "PWM: Forward" + fctname); GPIO.digitalWrite(gpioForward, LOW); // Forward
GPIO.pinMode(gpioReverse, OUTPUT, "PWM: Reverse" + fctname); GPIO.digitalWrite(gpioReverse, LOW); // Reverse
GPIOobj.pinMode(gpioForward, OUTPUT, "PWM: Forward" + fctname); GPIOobj.digitalWrite(gpioForward, LOW); // Forward
GPIOobj.pinMode(gpioReverse, OUTPUT, "PWM: Reverse" + fctname); GPIOobj.digitalWrite(gpioReverse, LOW); // Reverse
setDirection(1);
}

Expand Down Expand Up @@ -76,7 +76,7 @@ void ActionPWMOutput::setSettings(String key, String value) {
setSpeedInProcent(s);
} else if (key.equals("freq")) {
Serial.println("Freq");
GPIO.analogWriteFreq(value.toInt());
GPIOobj.analogWriteFreq(value.toInt());
}
}

Expand All @@ -86,17 +86,17 @@ void ActionPWMOutput::setDirection(int dir) {
return;
}
if (dir == 1) {
GPIO.digitalWrite(gpioForward, HIGH);
GPIO.digitalWrite(gpioReverse, LOW);
GPIOobj.digitalWrite(gpioForward, HIGH);
GPIOobj.digitalWrite(gpioReverse, LOW);
direction = 1;
} else if (dir == -1) {
GPIO.digitalWrite(gpioForward, LOW);
GPIO.digitalWrite(gpioReverse, HIGH);
GPIOobj.digitalWrite(gpioForward, LOW);
GPIOobj.digitalWrite(gpioReverse, HIGH);
direction = -1;
} else {
Serial.println("Error: Direction " + String(dir));
GPIO.digitalWrite(gpioForward, LOW);
GPIO.digitalWrite(gpioReverse, LOW);
GPIOobj.digitalWrite(gpioForward, LOW);
GPIOobj.digitalWrite(gpioReverse, LOW);
direction = 0;
}
}
Expand All @@ -117,23 +117,23 @@ void ActionPWMOutput::setSpeedInProcent(int speedProc) {
handleSpeedandDirectionWithoutPWMPin(direction, speedProc);
return;
}
GPIO.analogWrite(gpioPWM, speedProc);
GPIOobj.analogWrite(gpioPWM, speedProc);
}

void ActionPWMOutput::handleSpeedandDirectionWithoutPWMPin(int dir, int speed) {
currentSpeed = speed;
if (dir == 1) {
GPIO.analogWrite(gpioForward, currentSpeed);
GPIO.analogWrite(gpioReverse, 0);
GPIOobj.analogWrite(gpioForward, currentSpeed);
GPIOobj.analogWrite(gpioReverse, 0);
direction = 1;
} else if (dir == -1) {
GPIO.analogWrite(gpioForward, 0);
GPIO.analogWrite(gpioReverse, currentSpeed);
GPIOobj.analogWrite(gpioForward, 0);
GPIOobj.analogWrite(gpioReverse, currentSpeed);
direction = -1;
} else {
Serial.println("Error: Direction " + String(dir));
GPIO.digitalWrite(gpioForward, LOW);
GPIO.digitalWrite(gpioReverse, LOW);
GPIOobj.digitalWrite(gpioForward, LOW);
GPIOobj.digitalWrite(gpioReverse, LOW);
direction = 0;
}
}
7 changes: 7 additions & 0 deletions decoder/ActionPWMOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@

#include "ISettings.h"

#ifndef ESP8266

// HACK
#define PWMRANGE 1024

#endif

class ActionPWMOutput: public ISettings {
public:
ActionPWMOutput(uint8_t pwm, uint8_t forward, uint8_t reverse);
Expand Down
7 changes: 5 additions & 2 deletions decoder/ActionSUSIGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* falsch!
*
*/
#ifdef ESP8266

#include <Arduino.h>
#include "Consts.h"
#include "ActionSUSIGeneration.h"
Expand All @@ -20,12 +22,12 @@
ActionSUSIGeneration::ActionSUSIGeneration(int locoaddr) {
LOCO_ADR = locoaddr;
Logger::getInstance()->addToLog("Starting Susi Generator");
Logger::getInstance()->addToLog("SUSI-Output:" + GPIO.gpio2string(SPI.getUsedPin())
Logger::getInstance()->addToLog("SUSI-Output:" + GPIOobj.gpio2string(SPI.getUsedPin())
+ " Loko-Adresse: " + String(LOCO_ADR)
);

// TODO Negieren oder nicht negieren
SPISettings spiS = SPISettings(17241, LSBFIRST, SPI_MODE3, true);
SPISettings spiS = SPISettings(17241, LSBFIRST, my_SPI_MODE3, true);
SPI.begin(spiS, "SUSI");
SPI.beginTransaction(spiS);

Expand Down Expand Up @@ -120,3 +122,4 @@ void ActionSUSIGeneration::send() {
SPI.send(SPIBuf, SPIBufUsed);
SPIBufUsed = 0;
}
#endif
3 changes: 2 additions & 1 deletion decoder/ActionSUSIGeneration.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#ifndef ACTIONSUSIGENERATION_H_
#define ACTIONSUSIGENERATION_H_
#ifdef ESP8266


#include "INotify.h"
Expand Down Expand Up @@ -34,5 +35,5 @@ class ActionSUSIGeneration: public INotify, public ILoop {
uint8_t SPEED_STATE = 0;
};


#endif
#endif /* ACTIONSUSIGENERATION_H_ */
4 changes: 2 additions & 2 deletions decoder/ActionSendTurnoutCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class ActionSendTurnoutCommand : public ISettings, public INotify {
virtual void TurnoutCmd(int id, int direction, int source);
private:
Controller* controller;
sint16 id;
uint8 richtung;
int16_t id;
uint8_t richtung;
};

#endif /* ACTIONSENDTURNOUTCOMMAND_H_ */
5 changes: 4 additions & 1 deletion decoder/ActionServo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
#include "Logger.h"
#include "GPIO.h"

#ifdef ESP8266

ActionServo::ActionServo(int pin) {
Logger::getInstance()->addToLog(
"Starting Servo GPIO: " + String(pin));
GPIO.pinMode(pin, OUTPUT, "Servo");
GPIOobj.pinMode(pin, OUTPUT, "Servo");
this->pin = pin;
}

Expand Down Expand Up @@ -89,3 +91,4 @@ void ActionServo::detach() {
isAttach = false;
}

#endif
3 changes: 3 additions & 0 deletions decoder/ActionServo.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#ifndef ACTIONSERVO_H_
#define ACTIONSERVO_H_

#ifdef ESP8266

#include <Servo.h>

#include "INotify.h"
Expand All @@ -33,4 +35,5 @@ class ActionServo: public ILoop, public ISettings {

};

#endif
#endif /* ACTIONSERVO_H_ */
6 changes: 3 additions & 3 deletions decoder/ActionStepperOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ActionStepperOutput::ActionStepperOutput(Pin* p1, Pin* p2, Pin* p3, Pin* p4) {
pins[2] = p3;
pins[3] = p4;
for (int i = 0; i < 4; i++) {
GPIO.pinMode(pins[i], OUTPUT, "Stepper");
GPIOobj.pinMode(pins[i], OUTPUT, "Stepper");
}
}

Expand All @@ -25,7 +25,7 @@ ActionStepperOutput::~ActionStepperOutput() {
int ActionStepperOutput::loop() {
if (current == target) {
for (int i = 0; i < 4; i++) {
GPIO.digitalWrite(pins[i], 0);
GPIOobj.digitalWrite(pins[i], 0);
}
return 50;
}
Expand All @@ -43,7 +43,7 @@ int ActionStepperOutput::loop() {
}
}
for (int i = 0; i < 4; i++) {
GPIO.digitalWrite(pins[i], steps[state][i]);
GPIOobj.digitalWrite(pins[i], steps[state][i]);
}
return 1;
}
Expand Down
20 changes: 10 additions & 10 deletions decoder/ActionTurnOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ ActionTurnOut::ActionTurnOut(int dir1, int dir2, int enable) {
this->enable = enable;
int i;
for (i = 0; i < 2; i++) {
GPIO.pinMode(dirPin[i], OUTPUT, "Weiche Richtung " + String(0));
GPIO.digitalWrite(dirPin[i], 0);
GPIOobj.pinMode(dirPin[i], OUTPUT, "Weiche Richtung " + String(0));
GPIOobj.digitalWrite(dirPin[i], 0);
}
GPIO.pinMode(enable, OUTPUT, "Weiche Enable");
GPIOobj.pinMode(enable, OUTPUT, "Weiche Enable");
off();

}
Expand All @@ -47,9 +47,9 @@ String ActionTurnOut::getHTMLController(String urlprefix) {
}

void ActionTurnOut::off() {
GPIO.digitalWrite(enable, 0);
GPIOobj.digitalWrite(enable, 0);
for (int i = 0; i < 2; i++) {
GPIO.digitalWrite(dirPin[i], 0);
GPIOobj.digitalWrite(dirPin[i], 0);
}
}

Expand All @@ -64,13 +64,13 @@ ActionTurnOut::~ActionTurnOut() {
void ActionTurnOut::setSettings(String key, String value) {
int status = value.toInt();
if (status == 1) {
GPIO.digitalWrite(dirPin[0], 0);
GPIO.digitalWrite(dirPin[1], 1);
GPIOobj.digitalWrite(dirPin[0], 0);
GPIOobj.digitalWrite(dirPin[1], 1);
} else {
GPIO.digitalWrite(dirPin[0], 1);
GPIO.digitalWrite(dirPin[1], 0);
GPIOobj.digitalWrite(dirPin[0], 1);
GPIOobj.digitalWrite(dirPin[1], 0);
}
GPIO.digitalWrite(enable, 1);
GPIOobj.digitalWrite(enable, 1);
delay(200);
off();
}
Expand Down
Loading

0 comments on commit d1f68dc

Please sign in to comment.