#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 |
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) |
uint8_t | AddMovingPosition (unsigned long inId, int inPosition) |
uint8_t | AddMovingPositions (const MovingPosition *inMovingPositions_P) |
void | AdjustMovingPositionsSize (uint8_t inNewSize) |
bool | IsEmpty () const |
uint8_t | IndexOfMovingPositionById (unsigned long inId) const |
int | GetMovingPositionValueById (unsigned long inId) const |
int | GetMovingPositionValueByIndex (uint8_t inIndex) const |
unsigned long | GetMovingPositionIdByIndex (uint8_t 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 instantiated !
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 configure 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 141 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 192 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 57 of file Accessory.cpp.
uint8_t Accessory::AddMovingPositions | ( | const MovingPosition * | inMovingPositions_P | ) |
Add a list of moving positions declared with PROGMEM to the accessory.
[in] | inMovingPositions_P | list of MovingPosition defined with PROGMEM attribute. |
Definition at line 68 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 30 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 200 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 445 of file Accessory.hpp.
|
virtual |
Reload all data from the EEPROM.
Reimplemented in AccessoryServo, AccessoryLight, and AccessoryMotor.
|
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, AccessoryLight, AccessoryStepper, and AccessoryMotor.
Definition at line 278 of file Accessory.hpp.
|
static |
Execute the event.
Definition at line 461 of file Accessory.cpp.
|
inline |
Gets the time of the starting of the current movement.
Definition at line 392 of file Accessory.hpp.
|
static |
Gets the number of accessories.
Definition at line 293 of file Accessory.cpp.
|
inline |
Gets the debounce delay of the accessory, when relevant.
Definition at line 255 of file Accessory.hpp.
|
inline |
Gets the duration. Some accessories needs a duration: blinking light, step for servo motor...
Definition at line 266 of file Accessory.hpp.
|
inlinestatic |
Sets the first accessory address in the list.
Definition at line 381 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 261 of file Accessory.hpp.
|
inline |
Gets the last position reached by this accessory.
Definition at line 344 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 339 of file Accessory.hpp.
|
inline |
Gets the number of MovingPosition.
Definition at line 349 of file Accessory.hpp.
|
inline |
Gets the position associated with the given Id.
inId | id of the MovingPosition to find. |
Definition at line 327 of file Accessory.hpp.
|
inline |
Gets the position at the given index of the list.
inIndex | index of the MovingPosition in the list. |
Definition at line 333 of file Accessory.hpp.
|
inline |
Gets the next accessory in the list.
Definition at line 386 of file Accessory.hpp.
|
inline |
Gets the associated port.
Definition at line 205 of file Accessory.hpp.
|
inline |
Gets the previous state of the accessory, when relevant.
Definition at line 235 of file Accessory.hpp.
|
inline |
Gets the current state of the accessory.
Definition at line 229 of file Accessory.hpp.
uint8_t Accessory::IndexOfMovingPositionById | ( | unsigned long | inId | ) | const |
Find the index of a MovingPosition from its Id.
inId | id of the MovingPosition to find. |
Definition at line 94 of file Accessory.cpp.
|
inline |
Checks if an action is still pending.
Definition at line 424 of file Accessory.hpp.
|
static |
Checks if there is at least one accessory which needs more loop() calls.
Definition at line 320 of file Accessory.cpp.
|
inline |
Checks if at least one MovingPosition has been defined.
Definition at line 315 of file Accessory.hpp.
|
inline |
Checks if current state is STATE_FIRST.
Definition at line 245 of file Accessory.hpp.
|
inlinevirtual |
Checks if an action is still pending on a group.
Definition at line 430 of file Accessory.hpp.
|
inline |
Checks if current state is STATE_NONE.
Definition at line 240 of file Accessory.hpp.
|
inline |
Checks if current state is STATE_SECOND.
Definition at line 250 of file Accessory.hpp.
|
inline |
Main loop function.
Definition at line 271 of file Accessory.hpp.
|
pure virtual |
Basic moving function.
[in] | inMovingPositionId | new position id from MovingPosition to reach. |
Implemented AccessoryServo, AccessoryStepper, and AccessoryMotor.
|
inlinevirtual |
Basic moving function for a positional motor.
[in] | inPosition | new position to reach. |
Reimplemented in AccessoryServo, and AccessoryStepper.
Definition at line 451 of file Accessory.hpp.
|
inlinevirtual |
Prepare for a future action
Definition at line 411 of file Accessory.hpp.
|
inline |
Resets the starting time of the current action.
Definition at line 472 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 360 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 370 of file Accessory.hpp.
|
inline |
Sets the last move time from the current time.
Definition at line 365 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 215 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 376 of file Accessory.hpp.
|
inline |
Sets the starting time of a new action.
Definition at line 467 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 456 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 223 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 148 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 187 of file Accessory.hpp.
|
protected |
Previous state of the accessory.
Definition at line 190 of file Accessory.hpp.