Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev twindad #33

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
dc1bf7b
Add WiThrottle class
msunderwd Jan 25, 2017
e656241
The rest of the WiThrottle / Inglenook changes
msunderwd Jan 25, 2017
e6316e5
Update Inglenook to keep its own static LCD object.
msunderwd Jan 27, 2017
72817cb
Update Inglenook to make use of LCD class. Clean up some junk too.
msunderwd Jan 31, 2017
bc8607d
Update LCDThrottle to make use of LCD class. Add power on/off with l…
msunderwd Jan 31, 2017
5dc2f04
Updating LCD class
msunderwd Jan 31, 2017
0be6638
Working copy. Fixed most things, including getting the LCD to work (…
msunderwd Feb 1, 2017
935534e
Remove WiThrottle from this branch, which should be LCDThrottle-speci…
msunderwd Feb 1, 2017
9aaaa0f
Forgot to add Inglenook
msunderwd Feb 1, 2017
be60fff
Forgot to add Inglenook
msunderwd Feb 1, 2017
23cb182
Removed LCDThrottle and related files. This branch should be "pure" …
msunderwd Feb 1, 2017
5141379
Add support for power control and turnout control.
msunderwd Feb 7, 2017
3e0f9cc
Enabled looking at mainRegs for speed/direction
msunderwd Feb 7, 2017
89fd8bc
1) Created an ersatz "session" by separating the while(client.connect…
msunderwd Feb 8, 2017
f88501b
Function keys now work properly.
msunderwd Feb 8, 2017
d0a5db6
Enable dual throttles on a single phone
msunderwd Feb 8, 2017
efc7619
Fix responses to function commands for EngineDriver. Not tested.
msunderwd Feb 8, 2017
b26e1e8
merge conflicts between withrottle2 and lcd_throttle
msunderwd Feb 8, 2017
37af673
Resolved conflicts and restored files for merged withrottle2 and lcd_…
msunderwd Feb 8, 2017
0f297f9
1) Added code for LCD Throttle support. Disabled in Config.h
msunderwd Feb 9, 2017
9084cbd
Try to get withrottle working with the ESP8266 over serial
msunderwd Mar 1, 2017
5420012
Add "-2" response code to prog track writes.
msunderwd Mar 18, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion DCCpp_Uno/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ Part of DCC++ BASE STATION for the Arduino
// 0 = ARDUINO MOTOR SHIELD (MAX 18V/2A PER CHANNEL)
// 1 = POLOLU MC33926 MOTOR SHIELD (MAX 28V/3A PER CHANNEL)

#define MOTOR_SHIELD_TYPE 0
#define MOTOR_SHIELD_TYPE 1

// SET THIS TO 1 IF THE MOTOR SHIELD HAS CURRENT FEEDBACK
// SET THIS TO 0 IF THE MOTOR SHIELD DOES NOT HAVE CURRENT FEEDBACK
#define MOTOR_SHIELD_SUPPORTS_FEEDBACK 0

/////////////////////////////////////////////////////////////////////////////////////
//
Expand All @@ -39,6 +43,7 @@ Part of DCC++ BASE STATION for the Arduino
//

//#define IP_ADDRESS { 192, 168, 1, 200 }
//#define IP_ADDRESS { 192, 168, 0, 42 }

/////////////////////////////////////////////////////////////////////////////////////
//
Expand All @@ -55,4 +60,25 @@ Part of DCC++ BASE STATION for the Arduino
#define MAC_ADDRESS { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF }

/////////////////////////////////////////////////////////////////////////////////////
//
// ENABLE THE WITHROTTLE INTERFACE
//

#define WITHROTTLE_SUPPORT 1

/////////////////////////////////////////////////////////////////////////////////////
//
// ENABLE BONJOUR/ZEROCONF SUPPORT
//

#define BONJOUR 0

/////////////////////////////////////////////////////////////////////////////////////
//
// ENABLE THE LCD THROTTLE. REQUIRES AN LCD WITH 5 BUTTONS.
//

#define LCD_THROTTLE 0

/////////////////////////////////////////////////////////////////////////////////////

33 changes: 32 additions & 1 deletion DCCpp_Uno/DCCpp_Uno.ino
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ DCC++ BASE STATION is configured through the Config.h file that contains all use
#include "EEStore.h"
#include "Config.h"
#include "Comm.h"
#if (LCD_THROTTLE == 1)
#include "LCDThrottle.h"
#endif
#if ((COMM_TYPE == 1) && (BONJOUR == 1))
#include <EthernetBonjour.h>
#endif

void showConfiguration();

Expand All @@ -185,6 +191,9 @@ void showConfiguration();
#if COMM_TYPE == 1
byte mac[] = MAC_ADDRESS; // Create MAC address (to be used for DHCP when initializing server)
EthernetServer INTERFACE(ETHERNET_PORT); // Create and instance of an EnternetServer
#if (BONJOUR == 1)
const char bonjourname = "DCCpp._withrottle._tcp";
#endif
#endif

// NEXT DECLARE GLOBAL OBJECTS TO PROCESS AND STORE DCC PACKETS AND MONITOR TRACK CURRENTS.
Expand All @@ -196,11 +205,23 @@ volatile RegisterList progRegs(2); // create a shorter list
CurrentMonitor mainMonitor(CURRENT_MONITOR_PIN_MAIN,"<p2>"); // create monitor for current on Main Track
CurrentMonitor progMonitor(CURRENT_MONITOR_PIN_PROG,"<p3>"); // create monitor for current on Program Track

#if (LCD_THROTTLE == 1)
LCDThrottle *lcdThrottle;
#endif

///////////////////////////////////////////////////////////////////////////////
// MAIN ARDUINO LOOP
///////////////////////////////////////////////////////////////////////////////

void loop(){

#if (LCD_THROTTLE == 1)
lcdThrottle->run();
#endif

#if ((COMM_TYPE == 1 && BONJOUR == 1))
EthernetBonjour.run();
#endif

SerialCommand::process(); // check for, and process, and new serial commands

Expand All @@ -210,7 +231,7 @@ void loop(){
}

Sensor::check(); // check sensors for activate/de-activate

} // loop

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -222,6 +243,11 @@ void setup(){
Serial.begin(115200); // configure serial interface
Serial.flush();

#if (LCD_THROTTLE == 1)
lcdThrottle = new LCDThrottle();
lcdThrottle->begin(1);
#endif

#ifdef SDCARD_CS
pinMode(SDCARD_CS,OUTPUT);
digitalWrite(SDCARD_CS,HIGH); // Deselect the SD card
Expand Down Expand Up @@ -253,6 +279,11 @@ void setup(){
Ethernet.begin(mac); // Start networking using DHCP to get an IP Address
#endif
INTERFACE.begin();

#if (BONJOUR == 1)
EthernetBonjour.begin("arduino");
EthernetBonjour.addServiceRecord("DCCpp._withrottle", ETHERNET_PORT, MDNSServiceTCP, "jmri=4.5.7");
#endif
#endif

SerialCommand::init(&mainRegs, &progRegs, &mainMonitor); // create structure to read and parse commands from serial line
Expand Down
109 changes: 109 additions & 0 deletions DCCpp_Uno/Inglenook.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include <Arduino.h>
#include "LCD.h"
//#include <MenuBackend.h>

#include "Inglenook.h"

// Game State Machine States
#define STATE_IDLE 0
#define STATE_MENUS 1
#define STATE_ACTION 2
#define STATE_BUILD 3
int game_state = STATE_MENUS;

// Array holding the current sorting of the train to be built.
int train[TRAIN_LENGTH];

InglenookGame::InglenookGame() {
; // Do nothing
}

static void InglenookGame::begin() {
randomSeed(analogRead(44));
car_index = -1;
}

/*
void InglenookGame::printWelcome(LCD *lcd, char *row1, char *row2) {
lcd->clear();
sprintf(row1, "INGLENOOK GAME");
sprintf(row2, "Select to start");
lcd->updateDisplay(row1, row2); // TODO: Fix this.
}
*/

int InglenookGame::carIndex() {
return(car_index);
}

void InglenookGame::setCarIndex(int c) {
car_index = c;
}

void InglenookGame::buildTrain() {
bool cars_used[NUM_CARS] = { false, false, false, false, false, false, false, false };
int car = 0;
bool found_one = false;
game_state = STATE_BUILD;
for (int i = 0; i < TRAIN_LENGTH; i++) {
found_one = false;
do {
car = random(0, NUM_CARS) & 0xFFFF;
//Serial.println("found " + String(car));
if (cars_used[car] == false) {
// Car is not used. Use it.
cars_used[car] = true;
train[i] = car;
found_one = true;
//Serial.println("using " + String(car));
} // if
} while (!found_one);
//Serial.println("i = " + String(i) + " car = " + String(car));
} // for
}

void InglenookGame::doDisplayTrain(LCD *lcd, char *row1, char *row2) {
// DEBUG:
//Serial.println("BUILD THIS TRAIN");
//for (int i = 0; i < TRAIN_LENGTH; i++) {
//Serial.print(String(i+1) + ": " + carnames[train[i]] + "; ");
//}
//Serial.println("");
// END DEBUG
lcd->clear();
sprintf(row1, "BUILD THIS TRAIN");
sprintf(row2, "");
for (int i = 0; i < TRAIN_LENGTH; i++) {
sprintf(row2, "%s%d ", row2, train[i]+1);
}
lcd->updateDisplay(row1, row2);
lcd->noBlink();
}

void InglenookGame::doListTrain(LCD *lcd, char *row1, char *row2, int car) {
String s1, s2;
switch(car) {
case 1:
s1 = "2:" + carnames[train[1]];
s2 = "3:" + carnames[train[2]];
break;
case 2:
s1 = "3:" + carnames[train[2]];
s2 = "4:" + carnames[train[3]];
break;
case 3:
s1 = "4:" + carnames[train[3]];
s2 = "5:" + carnames[train[4]];
break;
case 0:
default:
s1 = "1:" + carnames[train[0]];
s2 = "2:" + carnames[train[1]];
break;
} // switch(car)
lcd->clear();
sprintf(row1, s1.c_str());
sprintf(row2, s2.c_str());
lcd->updateDisplay(row1, row2);
}

40 changes: 40 additions & 0 deletions DCCpp_Uno/Inglenook.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef INGLENOOK_H
#define INGLENOOK_H

// NOTE: These are actually set by the rules of the game...
// WARNING: There are several places (initialization, etc.) where
// the value of these is assumed fixed at 5 and 8.
#define TRAIN_LENGTH 5
#define NUM_CARS 8

const String carnames[NUM_CARS] = { // String names of cars on the layout (for display)
"Blue Boxcar",
"Red Boxcar",
"Green Boxcar",
"Black Tank Car",
"Black Gondola",
"Grey Hopper",
"Brown Flatcar",
"Brown Boxcar"
};

class InglenookGame {
private:
int car_index;

public:
InglenookGame();
void begin();
void buildTrain(void);
void doDisplayTrain(LCD *lcd, char *row1, char *row2);
int carIndex();
void setCarIndex(int c);
void doMenuDisplay(LCD *lcd, char *row1, char *row2);
void doListTrain(LCD *lcd, char *row1, char *row2, int car);

protected:
//void printWelcome(LCD *lcd, char *row1, char *row2);
};


#endif
Loading