Split train class into item and train
Use SVector to store trains
This commit is contained in:
43
train.h
43
train.h
@ -1,47 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "writepin.h"
|
||||
#include <util/delay.h>
|
||||
#include <stdint.h>
|
||||
#include <avr/io.h>
|
||||
#include "item.h"
|
||||
|
||||
class Train
|
||||
class Train: public Item
|
||||
{
|
||||
public:
|
||||
|
||||
static constexpr uint8_t HIGH = 2;
|
||||
static constexpr uint8_t LOW = 1;
|
||||
static constexpr uint8_t OFF = 0;
|
||||
|
||||
private:
|
||||
|
||||
static constexpr unsigned char _pinHighA = PD5;
|
||||
static constexpr unsigned char _pinLowA = PD4;
|
||||
static constexpr unsigned char _pinHighB = PD2;
|
||||
static constexpr unsigned char _pinLowB = PD3;
|
||||
|
||||
uint8_t _address;
|
||||
uint8_t _function = 0;
|
||||
uint8_t _function = 0;
|
||||
uint8_t _functionmask;
|
||||
uint8_t _speed = 0;
|
||||
bool _direction = false;
|
||||
|
||||
static const uint8_t SEND_COUNT = 2;
|
||||
|
||||
inline static void off();
|
||||
static void sendBit(const bool bit);
|
||||
static void sendAddress(uint8_t address);
|
||||
uint16_t packetAddSpeed();
|
||||
uint16_t packetAddDirection();
|
||||
uint16_t packetAddFunction(const uint8_t function);
|
||||
uint16_t assemblePacket();
|
||||
uint16_t assembleSpeedPacket();
|
||||
|
||||
public:
|
||||
|
||||
static void setOutput(const uint8_t state);
|
||||
|
||||
Train(const uint8_t address, uint8_t functionmask = 0b1111);
|
||||
Train();
|
||||
Train(const uint8_t address, uint8_t functionmask = 0b0000);
|
||||
|
||||
void sendData();
|
||||
|
||||
@ -51,8 +27,6 @@ public:
|
||||
|
||||
bool isActive() {return getSpeed() || getFunctions();}
|
||||
|
||||
uint8_t getAddress();
|
||||
|
||||
uint16_t getLastPacket();
|
||||
|
||||
void setSpeed(uint8_t speed);
|
||||
@ -65,12 +39,5 @@ public:
|
||||
|
||||
uint8_t getFunctionMask();
|
||||
|
||||
void setAddress(const uint8_t address);
|
||||
|
||||
void sendFunction(const uint8_t function, bool enable = true);
|
||||
|
||||
void sendRaw(const uint16_t data);
|
||||
|
||||
static void sendRawAddr(const uint16_t address, const uint16_t data);
|
||||
|
||||
};
|
||||
|
Reference in New Issue
Block a user