Skip to content

Commit

Permalink
Fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
peteGSX committed Feb 1, 2025
1 parent 4c505ec commit a8673d8
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class MyDelegate : public DCCEXProtocolDelegate {

public:
void receivedServerVersion(int major, int minor, int patch) {
void receivedServerVersion(int major, int minor, int patch) override {
Serial.print("\n\nReceived version: ");
Serial.print(major);
Serial.print(".");
Expand All @@ -31,16 +31,33 @@ public:
Serial.println(patch);
}

void receivedTrackPower(TrackPower state) {
void receivedTrackPower(TrackPower state) override {
Serial.print("\n\nReceived Track Power: ");
Serial.println(state);
Serial.println("\n\n");
}

void receivedLocoUpdate(Loco *loco) {
// Use for roster Locos (LocoSource::LocoSourceRoster)
void receivedLocoUpdate(Loco *loco) override {
Serial.print("Received Loco update for DCC address: ");
Serial.println(loco->getAddress());
}

// Use for locally created Locos (LocoSource::LocoSourceEntry)
void receivedLocoBroadcast(int address, int speed, Direction direction, int functionMap) override {
Serial.print("\n\nReceived Loco broadcast: address|speed|direction|functionMap: ");
Serial.print(address);
Serial.print("|");
Serial.print(speed);
Serial.print("|");
if (direction == Direction::Forward) {
Serial.print("Fwd");
} else {
Serial.print("Rev");
}
Serial.print("|");
Serial.println(functionMap);
}
};

// for random speed changes
Expand Down
2 changes: 1 addition & 1 deletion examples/DCCEXProtocol_Delegate/DCCEXProtocol_Delegate.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class MyDelegate : public DCCEXProtocolDelegate {

public:
void receivedServerVersion(int major, int minor, int patch) {
void receivedServerVersion(int major, int minor, int patch) override {
Serial.print("\n\nReceived version: ");
Serial.print(major);
Serial.print(".");
Expand Down
25 changes: 20 additions & 5 deletions examples/DCCEXProtocol_Loco_Control/DCCEXProtocol_Loco_Control.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <DCCEXProtocol.h>
#include <WiFi.h>


// If we haven't got a custom config.h, use the example
#if __has_include("config.h")
#include "config.h"
Expand All @@ -22,9 +21,8 @@ void printRoster();

// Delegate class
class MyDelegate : public DCCEXProtocolDelegate {

public:
void receivedServerVersion(int major, int minor, int patch) {
void receivedServerVersion(int major, int minor, int patch) override {
Serial.print("\n\nReceived version: ");
Serial.print(major);
Serial.print(".");
Expand All @@ -33,16 +31,33 @@ public:
Serial.println(patch);
}

void receivedTrackPower(TrackPower state) {
void receivedTrackPower(TrackPower state) override {
Serial.print("\n\nReceived Track Power: ");
Serial.println(state);
Serial.println("\n\n");
}

void receivedLocoUpdate(Loco *loco) {
// Use for roster Locos (LocoSource::LocoSourceRoster)
void receivedLocoUpdate(Loco *loco) override {
Serial.print("Received Loco update for DCC address: ");
Serial.println(loco->getAddress());
}

// Use for locally created Locos (LocoSource::LocoSourceEntry)
void receivedLocoBroadcast(int address, int speed, Direction direction, int functionMap) override {
Serial.print("\n\nReceived Loco broadcast: address|speed|direction|functionMap: ");
Serial.print(address);
Serial.print("|");
Serial.print(speed);
Serial.print("|");
if (direction == Direction::Forward) {
Serial.print("Fwd");
} else {
Serial.print("Rev");
}
Serial.print("|");
Serial.println(functionMap);
}
};

// for random speed changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class MyDelegate : public DCCEXProtocolDelegate {

public:
void receivedServerVersion(int major, int minor, int patch) {
void receivedServerVersion(int major, int minor, int patch) override {
Serial.print("\n\nReceived version: ");
Serial.print(major);
Serial.print(".");
Expand All @@ -31,16 +31,33 @@ public:
Serial.println(patch);
}

void receivedTrackPower(TrackPower state) {
void receivedTrackPower(TrackPower state) override {
Serial.print("\n\nReceived Track Power: ");
Serial.println(state);
Serial.println("\n\n");
}

void receivedLocoUpdate(Loco *loco) {
// Use for roster Locos (LocoSource::LocoSourceRoster)
void receivedLocoUpdate(Loco *loco) override {
Serial.print("Received Loco update for DCC address: ");
Serial.println(loco->getAddress());
}

// Use for locally created Locos (LocoSource::LocoSourceEntry)
void receivedLocoBroadcast(int address, int speed, Direction direction, int functionMap) override {
Serial.print("\n\nReceived Loco broadcast: address|speed|direction|functionMap: ");
Serial.print(address);
Serial.print("|");
Serial.print(speed);
Serial.print("|");
if (direction == Direction::Forward) {
Serial.print("Fwd");
} else {
Serial.print("Rev");
}
Serial.print("|");
Serial.println(functionMap);
}
};

// Example class for a throttle
Expand Down
24 changes: 12 additions & 12 deletions examples/DCCEXProtocol_Roster_etc/DCCEXProtocol_Roster_etc.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void printTurntables();
class MyDelegate : public DCCEXProtocolDelegate {

public:
void receivedServerVersion(int major, int minor, int patch) {
void receivedServerVersion(int major, int minor, int patch) override {
Serial.print("\n\nReceived version: ");
Serial.print(major);
Serial.print(".");
Expand All @@ -36,27 +36,27 @@ public:
Serial.println(patch);
}

void receivedTrackPower(TrackPower state) {
void receivedTrackPower(TrackPower state) override {
Serial.print("\n\nReceived Track Power: ");
Serial.println(state);
Serial.println("\n\n");
}

void receivedRosterList() {
void receivedRosterList() override {
Serial.println("\n\nReceived Roster");
printRoster();
}
void receivedTurnoutList() {
void receivedTurnoutList() override {
Serial.print("\n\nReceived Turnouts/Points list");
printTurnouts();
Serial.println("\n\n");
}
void receivedRouteList() {
void receivedRouteList() override {
Serial.print("\n\nReceived Routes List");
printRoutes();
Serial.println("\n\n");
}
void receivedTurntableList() {
void receivedTurntableList() override {
Serial.print("\n\nReceived Turntables list");
printTurntables();
Serial.println("\n\n");
Expand All @@ -75,13 +75,13 @@ MyDelegate myDelegate;
void printRoster() {
for (Loco *loco = dccexProtocol.roster->getFirst(); loco; loco = loco->getNext()) {
int id = loco->getAddress();
char *name = loco->getName();
const char *name = loco->getName();
Serial.print(id);
Serial.print(" ~");
Serial.print(name);
Serial.println("~");
for (int i = 0; i < 32; i++) {
char *fName = loco->getFunctionName(i);
const char *fName = loco->getFunctionName(i);
if (fName != nullptr) {
Serial.print("loadFunctionLabels() ");
Serial.print(fName);
Expand All @@ -98,7 +98,7 @@ void printRoster() {
void printTurnouts() {
for (Turnout *turnout = dccexProtocol.turnouts->getFirst(); turnout; turnout = turnout->getNext()) {
int id = turnout->getId();
char *name = turnout->getName();
const char *name = turnout->getName();
Serial.print(id);
Serial.print(" ~");
Serial.print(name);
Expand All @@ -110,7 +110,7 @@ void printTurnouts() {
void printRoutes() {
for (Route *route = dccexProtocol.routes->getFirst(); route; route = route->getNext()) {
int id = route->getId();
char *name = route->getName();
const char *name = route->getName();
Serial.print(id);
Serial.print(" ~");
Serial.print(name);
Expand All @@ -122,7 +122,7 @@ void printRoutes() {
void printTurntables() {
for (Turntable *turntable = dccexProtocol.turntables->getFirst(); turntable; turntable = turntable->getNext()) {
int id = turntable->getId();
char *name = turntable->getName();
const char *name = turntable->getName();
Serial.print(id);
Serial.print(" ~");
Serial.print(name);
Expand All @@ -131,7 +131,7 @@ void printTurntables() {
int j = 0;
for (TurntableIndex *turntableIndex = turntable->getFirstIndex(); turntableIndex;
turntableIndex = turntableIndex->getNextIndex()) {
char *indexName = turntableIndex->getName();
const char *indexName = turntableIndex->getName();
Serial.print(" index");
Serial.print(j);
Serial.print(" ~");
Expand Down
26 changes: 13 additions & 13 deletions examples/DCCEXProtocol_Serial/DCCEXProtocol_Serial.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void printTurntables();
// Setup the delegate class to process broadcasts/responses
class MyDelegate : public DCCEXProtocolDelegate {
public:
void receivedServerVersion(int major, int minor, int patch) {
void receivedServerVersion(int major, int minor, int patch) override {
CONSOLE.print("\n\nReceived version: ");
CONSOLE.print(major);
CONSOLE.print(".");
Expand All @@ -42,33 +42,33 @@ public:
CONSOLE.println(patch);
}

void receivedTrackPower(TrackPower state) {
void receivedTrackPower(TrackPower state) override {
CONSOLE.print("\n\nReceived Track Power: ");
CONSOLE.println(state);
CONSOLE.println("\n\n");
}

void receivedRosterList() {
void receivedRosterList() override {
CONSOLE.println("\n\nReceived Roster");
printRoster();
}
void receivedTurnoutList() {
void receivedTurnoutList() override {
CONSOLE.print("\n\nReceived Turnouts/Points list");
printTurnouts();
CONSOLE.println("\n\n");
}
void receivedRouteList() {
void receivedRouteList() override {
CONSOLE.print("\n\nReceived Routes List");
printRoutes();
CONSOLE.println("\n\n");
}
void receivedTurntableList() {
void receivedTurntableList() override {
CONSOLE.print("\n\nReceived Turntables list");
printTurntables();
CONSOLE.println("\n\n");
}

void receivedScreenUpdate(int screen, int row, char *message) {
void receivedScreenUpdate(int screen, int row, char *message) override {
CONSOLE.println("\n\nReceived screen|row|message");
CONSOLE.print(screen);
CONSOLE.print("|");
Expand All @@ -86,13 +86,13 @@ MyDelegate myDelegate;
void printRoster() {
for (Loco *loco = dccexProtocol.roster->getFirst(); loco; loco = loco->getNext()) {
int id = loco->getAddress();
char *name = loco->getName();
const char *name = loco->getName();
CONSOLE.print(id);
CONSOLE.print(" ~");
CONSOLE.print(name);
CONSOLE.println("~");
for (int i = 0; i < 32; i++) {
char *fName = loco->getFunctionName(i);
const char *fName = loco->getFunctionName(i);
if (fName != nullptr) {
CONSOLE.print("loadFunctionLabels() ");
CONSOLE.print(fName);
Expand All @@ -109,7 +109,7 @@ void printRoster() {
void printTurnouts() {
for (Turnout *turnout = dccexProtocol.turnouts->getFirst(); turnout; turnout = turnout->getNext()) {
int id = turnout->getId();
char *name = turnout->getName();
const char *name = turnout->getName();
CONSOLE.print(id);
CONSOLE.print(" ~");
CONSOLE.print(name);
Expand All @@ -121,7 +121,7 @@ void printTurnouts() {
void printRoutes() {
for (Route *route = dccexProtocol.routes->getFirst(); route; route = route->getNext()) {
int id = route->getId();
char *name = route->getName();
const char *name = route->getName();
CONSOLE.print(id);
CONSOLE.print(" ~");
CONSOLE.print(name);
Expand All @@ -133,7 +133,7 @@ void printRoutes() {
void printTurntables() {
for (Turntable *turntable = dccexProtocol.turntables->getFirst(); turntable; turntable = turntable->getNext()) {
int id = turntable->getId();
char *name = turntable->getName();
const char *name = turntable->getName();
CONSOLE.print(id);
CONSOLE.print(" ~");
CONSOLE.print(name);
Expand All @@ -142,7 +142,7 @@ void printTurntables() {
int j = 0;
for (TurntableIndex *turntableIndex = turntable->getFirstIndex(); turntableIndex;
turntableIndex = turntableIndex->getNextIndex()) {
char *indexName = turntableIndex->getName();
const char *indexName = turntableIndex->getName();
CONSOLE.print(" index");
CONSOLE.print(j);
CONSOLE.print(" ~");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class MyDelegate : public DCCEXProtocolDelegate {

public:
void receivedTrackType(char track, TrackManagerMode type, int address) {
void receivedTrackType(char track, TrackManagerMode type, int address) override {
Serial.print("\n\nReceived TrackType: ");
Serial.print(track);
Serial.print(" : ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void printTurnouts();
class MyDelegate : public DCCEXProtocolDelegate {

public:
void receivedServerVersion(int major, int minor, int patch) {
void receivedServerVersion(int major, int minor, int patch) override {
Serial.print("Received version: ");
Serial.print(major);
Serial.print(".");
Expand All @@ -35,12 +35,12 @@ public:
Serial.println(patch);
}

void receivedTurnoutList() {
void receivedTurnoutList() override {
Serial.print("Received turnout list:");
printTurnouts();
}

void receivedTurnoutAction(int turnoutId, bool thrown) {
void receivedTurnoutAction(int turnoutId, bool thrown) override {
Serial.print("Received turnout action ID|thrown: ");
Serial.print(turnoutId);
Serial.print("|");
Expand All @@ -63,7 +63,7 @@ MyDelegate myDelegate;
void printTurnouts() {
for (Turnout *turnout = dccexProtocol.turnouts->getFirst(); turnout; turnout = turnout->getNext()) {
int id = turnout->getId();
char *name = turnout->getName();
const char *name = turnout->getName();
Serial.print(id);
Serial.print(" ~");
Serial.print(name);
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=DCCEXProtocol
version=1.0.1
version=1.0.2
author=Peter Cole, Peter Akers <[email protected]>
maintainer=Peter Cole, Peter Akers <[email protected]>
sentence=DCC-EX Native Protocol implementation
Expand Down
Loading

0 comments on commit a8673d8

Please sign in to comment.