#include "Accessory.hpp"
Public Member Functions | |
Accessory () | |
void | begin (ACC_STATE inStartingState = STATE_NONE) |
Port * | GetPort () const |
ACC_STATE | GetState () const |
ACC_STATE | GetPreviousState () const |
bool | IsNone () const |
bool | IsFirst () const |
bool | IsSecond () const |
uint8_t | AddMovingPosition (unsigned long inId, int inPosition) |
unsigned int | GetDebounceDelay () const |
unsigned long | GetLastMoveTime () const |
unsigned long | GetDuration () const |
bool | loop () |
virtual void | Event (unsigned long inId, ACCESSORIES_EVENT_TYPE inEvent = ACCESSORIES_EVENT_MOVEPOSITIONID, int inData = 0) |
virtual int | EEPROMSave (int inPos, bool inSimulate = false) |
virtual int | EEPROMLoad (int inPos) |
void | AdjustMovingPositionsSize (uint8_t inNewSize) |
bool | IsEmpty () const |
uint8_t | IndexOfMovingPosition (unsigned long inId) const |
int | GetMovingPosition (unsigned long inId) const |
int | GetMovingPositionByIndex (int inIndex) const |
unsigned long | GetMovingPositionIdByIndex (int inIndex) const |
const uint8_t | GetLastMovingPosition () const |
const uint8_t | GetMovingPositionSize () const |
void | SetLastMovingPosition (uint8_t inLastPositionIndex) |
void | SetDebounceDelay (unsigned int inDebounceDelay) |
void | SetLastMoveTime () |
void | SetDuration (unsigned long inDuration) |
void | SetNextAccessory (Accessory *inAccessory) |
Accessory * | GetNextAccessory () const |
unsigned long | GetActionStartingMillis () const |
virtual void | StartAction () |
virtual void | StartAction (ACC_STATE inState) |
virtual void | ResetAction () |
virtual bool | ActionEnded () |
bool | IsActionDelayPending () const |
virtual bool | IsGroupActionPending () const |
virtual void | Move (unsigned long inMovingPositionId) = 0 |
virtual ACC_STATE | Toggle () = 0 |
virtual bool | CanBePositional () const |
virtual void | MovePosition (int inPosition) |
virtual void | SetState (ACC_STATE inNewState) |
void | SetStateRaw (ACC_STATE inNewState) |
void | SetStartingMillis () |
void | ResetStartingMillis () |
Static Public Member Functions | |
static void | ExecuteEvent (unsigned long inId, ACCESSORIES_EVENT_TYPE inEvent = ACCESSORIES_EVENT_MOVEPOSITIONID, int inData = 0) |
static uint8_t | GetCount () |
static bool | IsActionPending () |
static Accessory * | GetFirstAccessory () |
Protected Attributes | |
Port * | pPort |
ACC_STATE | prevState |
This is the base class for all the accessories.
This class is a pure virtual class, so it cant be instanciated !
An accessory is a class driving a physical motor or light, receiving events to change its state. With each accessory is defined a port, giving power to the accessory. There is no accessory without port.
Each accessory have one or more MovingPosition, with each one defined by an Id. Each accessory have also a current state, a current speed and can have a current position. All these states are saved in EEPROM at each state change, with a protection to avoid more than one saving by second.
The EEPROM area starting from EEPROMStart will be filled on EEPROMsize with the current version number (a byte), and the total number of accessories and groups. The fourth byte will be the checksum of the three starting bytes... If any of these four bytes are different from the actual values, the EEPROM will be considered as free. Two bytes are then added to store the size of one complete record, in order to be able to configurate the CircularBuffer.
Following these bytes, there is the CircularBuffer of accessories. For each one the current state, the current position and the current speed will be saved. After that, each group save its current item id.
+-+ Version |V| Accessory number |A| Group number |G| header checksum |C| size byte 1 |s1] size byte 2 |s2] +-+ Circular buffer | | +-+ End of file.
And the Circular buffer is :
+-+ Acc 1 : State |S| Acc 1 : Position |P| Acc 1 : Speed |s| +-+ Acc 2 : State |S| Acc 2 : Position |P| Acc 2 : Speed |s| +-+ Acc 3 : State |S| Acc 3 : Position |P| Acc 3 : Speed |s| ... +-+ Group 1 : current ID |I| Group 3 : current ID |I| Group 3 : current ID |I| +-+ End of record.
Definition at line 140 of file Accessory.hpp.
Accessory::Accessory | ( | ) |
Default constructor.
Definition at line 15 of file Accessory.cpp.
|
virtual |
Ends the current action of this accessory.
Reimplemented in AccessoryMotor.
Definition at line 134 of file Accessory.cpp.
uint8_t Accessory::AddMovingPosition | ( | unsigned long | inId, |
int | inPosition | ||
) |
Add one moving position to the accessory.
[in] | inId | new Id |
[in] | inPosition | Position for this id. |
Definition at line 49 of file Accessory.cpp.
void Accessory::AdjustMovingPositionsSize | ( | uint8_t | inNewSize | ) |
Sets the number of MovingPosition. If some MovingPosition was previously existing, they will be preserved.
inNewSize | new size. |
Definition at line 29 of file Accessory.cpp.
|
inline |
Initialize the instance.
inStartingState | Starting state of the accessory. This is NOT an order to set the accessory in this state, only a way to take account of the current physical state of it ! |
Definition at line 180 of file Accessory.hpp.
|
inlinevirtual |
Checks if the accessory can be moved by an absolute value instead of a fix position.
Reimplemented in AccessoryServo, and AccessoryStepper.
Definition at line 419 of file Accessory.hpp.
|
virtual |
Reload all data from the EEPROM.
Reimplemented in AccessoryServo, AccessoryMotor, and AccessoryLight.
|
virtual |
Save all the data in the EEPROM.
|
inlinevirtual |
Execute a new event.
inId | Id of an accessory or an accessory item. |
inEvent | Type of the new event. Default is ACCESSORIES_EVENT_MOVEPOSITIONID. |
inData | Associated data to the event type. Default is 0. |
Reimplemented in AccessoryServo, AccessoryLightMulti, AccessoryMotor, AccessoryLight, and AccessoryStepper.
Definition at line 266 of file Accessory.hpp.
|
static |
Execute the event.
Definition at line 388 of file Accessory.cpp.
|
inline |
Gets the time of the starting of the current movement.
Definition at line 366 of file Accessory.hpp.
|
static |
Gets the number of accessories.
Definition at line 233 of file Accessory.cpp.
|
inline |
Gets the debounce delay of the accessory, when relevant.
Definition at line 243 of file Accessory.hpp.
|
inline |
Gets the duration. Some accessories needs a duration: blinking light, step for servo motor...
Definition at line 254 of file Accessory.hpp.
|
inlinestatic |
Sets the first accessory address in the list.
Definition at line 355 of file Accessory.hpp.
|
inline |
Gets the time of the last change of this accessory. A move can be done only if the elapsed time since last move is bigger than 'debounce' delay.
Definition at line 249 of file Accessory.hpp.
|
inline |
Gets the last position reached by this accessory.
Definition at line 318 of file Accessory.hpp.
int Accessory::GetMovingPosition | ( | unsigned long | inId | ) | const |
Gets the position associated with the given Id.
inId | id of the MovingPosition to find. |
Definition at line 68 of file Accessory.cpp.
|
inline |
Gets the position at the given index of the list.
inIndex | index of the MovingPosition in the list. |
Definition at line 307 of file Accessory.hpp.
|
inline |
Gets the id of the MovingPosition at the given index of the list.
inIndex | index of the MovingPosition in the list. |
Definition at line 313 of file Accessory.hpp.
|
inline |
Gets the number of MovingPosition.
Definition at line 323 of file Accessory.hpp.
|
inline |
Gets the next accessory in the list.
Definition at line 360 of file Accessory.hpp.
|
inline |
Gets the associated port.
Definition at line 185 of file Accessory.hpp.
|
inline |
Gets the previous state of the accessory, when relevant.
Definition at line 215 of file Accessory.hpp.
|
inline |
Gets the current state of the accessory.
Definition at line 209 of file Accessory.hpp.
uint8_t Accessory::IndexOfMovingPosition | ( | unsigned long | inId | ) | const |
Find the index of a MovingPosition from its Id.
inId | id of the MovingPosition to find. |
Definition at line 59 of file Accessory.cpp.
|
inline |
Checks if an action is still pending.
Definition at line 398 of file Accessory.hpp.
|
static |
Checks if there is at least one accessory which needs more loop() calls.
Definition at line 260 of file Accessory.cpp.
|
inline |
Checks if at least one MovingPosition has been defined.
Definition at line 289 of file Accessory.hpp.
|
inline |
Checks if current state is STATE_FIRST.
Definition at line 225 of file Accessory.hpp.
|
inlinevirtual |
Checks if an action is still pending on a group.
Definition at line 404 of file Accessory.hpp.
|
inline |
Checks if current state is STATE_NONE.
Definition at line 220 of file Accessory.hpp.
|
inline |
Checks if current state is STATE_SECOND.
Definition at line 230 of file Accessory.hpp.
|
inline |
Main loop function.
Definition at line 259 of file Accessory.hpp.
|
pure virtual |
Basic moving function.
[in] | inMovingPositionId | new position id from MovingPosition to reach. |
Implemented AccessoryServo, AccessoryMotor, and AccessoryStepper.
|
inlinevirtual |
Basic moving function for a positional motor.
[in] | inPosition | new position to reach. |
Reimplemented in AccessoryServo, and AccessoryStepper.
Definition at line 425 of file Accessory.hpp.
|
inlinevirtual |
Prepare for a future action
Definition at line 385 of file Accessory.hpp.
|
inline |
Resets the starting time of the current action.
Definition at line 446 of file Accessory.hpp.
|
inline |
Sets the debounce delay. This delay is used to be sure that the current move is finished. A new move will only operate if this delay is expired.
[in] | inDebounceDelay | delay needed to finish an action (movement...) of the accessory. |
Definition at line 334 of file Accessory.hpp.
|
inline |
Sets duration. This duration is used by lights for blinking, or by servos for the interval between elementary movements.
[in] | inDuration | duration of the accessory. |
Definition at line 344 of file Accessory.hpp.
|
inline |
Sets the last move time from the current time.
Definition at line 339 of file Accessory.hpp.
void Accessory::SetLastMovingPosition | ( | uint8_t | inLastPositionIndex | ) |
Sets the last position reached by this accessory.
[in] | inLastPositionIndex | last position reached by the accessory. |
Definition at line 157 of file Accessory.cpp.
|
inline |
Sets the next accessory in the list.
[in] | inAccessory | address of the next accessory in the list. |
Definition at line 350 of file Accessory.hpp.
|
inline |
Sets the starting time of a new action.
Definition at line 441 of file Accessory.hpp.
|
inlinevirtual |
Change the state of the accessory. The accessory will physically move to reach the new state.
inNewState | new state to reach. |
Reimplemented in AccessoryMotor, and AccessoryLight.
Definition at line 430 of file Accessory.hpp.
void Accessory::SetStateRaw | ( | ACC_STATE | inNewState | ) |
Change the state of the accessory. The accessory will NOT move to reach the new state.
inNewState | new state to reach. |
Definition at line 165 of file Accessory.cpp.
|
virtual |
|
virtual |
Starts a new action and sets the current state of this accessory.
[in] | inState | new current state of this accessory. |
Definition at line 90 of file Accessory.cpp.
|
pure virtual |
Basic function to toggle the accessory. A turnout will change its position, a light will change its state to on or off depending of its current state...
Implemented AccessoryMotor, and AccessoryLight.
|
protected |
Port to drive the accessory. An accessory should always have a port, even if this is the Arduino itself...
Definition at line 167 of file Accessory.hpp.
|
protected |
Previous state of the accessory.
Definition at line 170 of file Accessory.hpp.