2020-06-03 15:26:49 +02:00
|
|
|
#ifndef Turnouts_h
|
|
|
|
#define Turnouts_h
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
#include "DCC.h"
|
|
|
|
|
2020-06-23 18:43:50 +02:00
|
|
|
const byte STATUS_ACTIVE=0x80; // Flag as activated
|
|
|
|
const byte STATUS_PWM=0x40; // Flag as a PWM turnout
|
|
|
|
const byte STATUS_PWMPIN=0x3F; // PWM pin 0-63
|
|
|
|
|
2020-06-03 15:26:49 +02:00
|
|
|
struct TurnoutData {
|
2020-06-23 18:43:50 +02:00
|
|
|
int id;
|
|
|
|
uint8_t tStatus; // has STATUS_ACTIVE, STATUS_PWM, STATUS_PWMPIN
|
|
|
|
union {uint8_t subAddress; char moveAngle;}; //DCC sub addrerss or PWM difference from inactiveAngle
|
|
|
|
union {int address; int inactiveAngle;}; // DCC address or PWM servo angle
|
2020-06-03 15:26:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Turnout{
|
|
|
|
static Turnout *firstTurnout;
|
2020-06-23 18:43:50 +02:00
|
|
|
TurnoutData data;
|
2020-06-03 15:26:49 +02:00
|
|
|
Turnout *nextTurnout;
|
2020-06-22 12:58:33 +02:00
|
|
|
static bool activate(int n, bool state);
|
2020-06-03 15:26:49 +02:00
|
|
|
static Turnout* get(int);
|
|
|
|
static bool remove(int);
|
|
|
|
static void load();
|
|
|
|
static void store();
|
2020-06-23 18:43:50 +02:00
|
|
|
static Turnout *create(int id , int address , int subAddress);
|
|
|
|
static Turnout *create(int id , byte pin , int activeAngle, int inactiveAngle);
|
|
|
|
static Turnout *create(int id);
|
2020-06-12 15:28:35 +02:00
|
|
|
static void show(Print & stream, int n);
|
|
|
|
static bool showAll(Print & stream);
|
2020-06-22 12:58:33 +02:00
|
|
|
virtual void activate(bool state);
|
2020-06-03 15:26:49 +02:00
|
|
|
}; // Turnout
|
|
|
|
|
|
|
|
#endif
|