PServo v0.2.1
Loading...
Searching...
No Matches
Namespaces | Classes | Typedefs | Enumerations | Functions
ps Namespace Reference

Namespaces

namespace  Default
 

Classes

struct  Props
 
class  PServo
 

Typedefs

typedef struct ps::Props Props
 

Enumerations

enum class  State : unsigned char {
  STANDBY , INITIALIZED , HALT , IN_ACTION ,
  PAUSED , ERROR_UNEXPECTED , ERROR_NOACTION , ERROR_TIMERPTR
}
 

Functions

char const * state_text (State s)
 

Detailed Description

Precise servo. Holds the core classes, functions and constants related to the state machine that will control the position (it wont write anything anywere because it doesn't depends on the Arduino.h library).

When used in .ino files, it is recommended that the developer consider not using this namespace globally, the names inside this namespace may cause some confusion without the namespace's name as a context. Only inside a function definition it's OK to use using namespace ps; at the top.

Typedef Documentation

◆ Props

typedef struct ps::Props ps::Props

List of all the private properties of ps::PServo. It's primary useful for testing and monitoring strategies, but be aware that you cannot hack those values inside the class, those are read only througth this struct.

Usage example:

unsigned char active_action = myservo_machine.props().active_action;
unsigned char const actions_count myservo_machine.props().actions_count;
Serial.print("Current action: ");
Serial.print(active_action);
if (active_action >= actions_count) {
Serial.println(" (last one)");
} else {
Serial.println();
}
See also
ps::State
ps::PServo

Enumeration Type Documentation

◆ State

enum class ps::State : unsigned char
strong

This class members has all the possible states for the ps::PServo state machine. Use it along side with the ps::PServo::get_state() method to build a more complex logic to your sketch.

Since it's each state is, in fact, a unsigned char. Maybe you'll need to cast it to a integer type if you want to print the state number on the serial port.

For an example:

if (myservo_machine.get_state() == State::HALT) {
Serial.println("All movements was completed!");
Serial.print("State ID: ");
Serial.println((int)state);
}
@ HALT
No operation, the final action was completed (NOOP).

Note: The NOOP means that the state will not perform any action nor update any value inside the machine. The responsability to handle and update to a valid state will be at the user's hand.

See also
ps::PServo
Enumerator
STANDBY 

Will count each action on this state.

INITIALIZED 

Measn that the actions was counted, so start it!

HALT 

No operation, the final action was completed (NOOP).

IN_ACTION 

Will keep updating the servo's position.

PAUSED 

No operation, but keep updating the _pc var (NOOP).

ERROR_UNEXPECTED 

An unexpected state appeard somewhere (NOOP).

ERROR_NOACTION 

Any actions was registered since being() (NOOP).

ERROR_TIMERPTR 

The timer pointer was not defined properly (NOOP).

Function Documentation

◆ state_text()

char const * ps::state_text ( ps::State s)

Return the specified state name in a string. Mainly used for debug and monitoring propurses.

Usage example:

ps::State const current_state = myservo_machine.get_state();
Serial.print("Current state: ");
Serial.println(ps::state_text(current_state));
char const * state_text(State s)
Definition PServo.cpp:155
State
Definition PServo.h:39
Parameters
sValid state object of an ps::PServo state machine.
Returns
A string representing the name of the specified state.
See also
ps::PServo
ps::State