COSA
An Object-Oriented Platform for Arduino Programming
Rotary::Dial< T > Class Template Reference

#include <Rotary.hh>

Inheritance diagram for Rotary::Dial< T >:
Inheritance graph
Collaboration diagram for Rotary::Dial< T >:
Collaboration graph

Public Types

enum  Direction { NONE = 0x00, CW = 0x10, CCW = 0x20 }
 
enum  Mode { HALF_CYCLE, FULL_CYCLE }
 

Public Member Functions

 Dial (Board::InterruptPin clk, Board::InterruptPin dt, Mode mode, T initial, T min, T max, T step)
 
value () const
 
step () const
 
void step (T step)
 
virtual void on_change (T value)
 
Mode mode () const
 
void mode (Mode mode)
 
void enable ()
 
void disable ()
 

Protected Member Functions

virtual void on_event (uint8_t type, uint16_t value)
 
Direction detect ()
 

Protected Attributes

m_value
 
m_min
 
m_max
 
m_step
 
SignalPin m_clk
 
SignalPin m_dt
 
uint8_t m_state
 
Mode m_mode
 

Static Protected Attributes

static const uint8_t half_cycle_table [6][4]
 
static const uint8_t full_cycle_table [7][4]
 

Detailed Description

template<typename T>
class Rotary::Dial< T >

Use Rotary Encoder as a simple dial (integer value). Allows a dial within a given number(T) range (min, max) and a given initial value.

Parameters
[in]Tvalue type.

Circuit

+------------+
(PCIc)--------------1-|CLK |
(PCId)--------------2-|DT |
3-|SW (/) |
(VCC)---------------4-|VCC |
(GND)---------------5-|GND |
+------------+

Definition at line 197 of file Rotary.hh.

Member Enumeration Documentation

Rotary Encoder turn direction.

Enumerator
NONE 

No direction change.

CW 

Clock-wise direction.

CCW 

Anti-clock-wise direction.

Definition at line 65 of file Rotary.hh.

enum Rotary::Encoder::Mode
inherited

Rotary Encoder cycle mode.

Enumerator
HALF_CYCLE 
FULL_CYCLE 

Definition at line 74 of file Rotary.hh.

Constructor & Destructor Documentation

template<typename T >
Rotary::Dial< T >::Dial ( Board::InterruptPin  clk,
Board::InterruptPin  dt,
Mode  mode,
initial,
min,
max,
step 
)
inline

Construct Rotary Dial connected to given interrupt pins with given mode, min, max, initial and step value. The mode is one of the Rotary Encoder modes; HALF_CYCLE or FULL_CYCLE.

Parameters
[in]clkinterrupt pin.
[in]dtinterrupt pin.
[in]modestep.
[in]initialvalue.
[in]minvalue.
[in]maxvalue.
[in]stepvalue.

Definition at line 211 of file Rotary.hh.

Member Function Documentation

Rotary::Encoder::Direction Rotary::Encoder::detect ( )
protectedinherited

Detect Rotary Encoder state change. Reads current input pin values and performs a possible state change. Return turn direction or none.

Returns
direction

Definition at line 222 of file Rotary.cpp.

void Rotary::Encoder::disable ( )
inlineinherited

Disable the encoder.

Definition at line 127 of file Rotary.hh.

void Rotary::Encoder::enable ( )
inlineinherited

Enable the encoder.

Definition at line 117 of file Rotary.hh.

Mode Rotary::Encoder::mode ( ) const
inlineinherited

Get current cycle mode.

Returns
mode.

Definition at line 100 of file Rotary.hh.

void Rotary::Encoder::mode ( Mode  mode)
inlineinherited

Set cycle mode.

Parameters
[in]modecycle.

Definition at line 109 of file Rotary.hh.

template<typename T >
virtual void Rotary::Dial< T >::on_change ( value)
inlinevirtual

Default on change function.

Parameters
[in]value.

Definition at line 252 of file Rotary.hh.

template<typename T >
virtual void Rotary::Dial< T >::on_event ( uint8_t  type,
uint16_t  value 
)
inlineprotectedvirtual

Update the dial value on change. The event value is the direction (CW or CCW).

Parameters
[in]typethe event type.
[in]valuethe event value.

Reimplemented from Event::Handler.

Definition at line 270 of file Rotary.hh.

template<typename T >
T Rotary::Dial< T >::step ( ) const
inline

Get current step (increment/decrement).

Returns
step.

Definition at line 233 of file Rotary.hh.

template<typename T >
void Rotary::Dial< T >::step ( step)
inline

Set step (increment/decrement).

Parameters
[in]stepvalue.

Definition at line 242 of file Rotary.hh.

template<typename T >
T Rotary::Dial< T >::value ( ) const
inline

Return current dial value.

Returns
value.

Definition at line 224 of file Rotary.hh.

Member Data Documentation

const uint8_t Rotary::Encoder::full_cycle_table
staticprotectedinherited
Initial value:

Full-cycle state transition tables.

Full-cycle state table (emits a code at 00 only)

dot_inline_dotgraph_5.png

Definition at line 161 of file Rotary.hh.

const uint8_t Rotary::Encoder::half_cycle_table[6][4]
staticprotectedinherited

Half-cycle state transition tables.

Definition at line 158 of file Rotary.hh.

SignalPin Rotary::Encoder::m_clk
protectedinherited

Signal pins, previous state and cycle mode.

Definition at line 164 of file Rotary.hh.

SignalPin Rotary::Encoder::m_dt
protectedinherited

Definition at line 165 of file Rotary.hh.

template<typename T >
T Rotary::Dial< T >::m_max
protected

Definition at line 260 of file Rotary.hh.

template<typename T >
T Rotary::Dial< T >::m_min
protected

Definition at line 259 of file Rotary.hh.

Mode Rotary::Encoder::m_mode
protectedinherited

Definition at line 167 of file Rotary.hh.

uint8_t Rotary::Encoder::m_state
protectedinherited

Definition at line 166 of file Rotary.hh.

template<typename T >
T Rotary::Dial< T >::m_step
protected

Definition at line 261 of file Rotary.hh.

template<typename T >
T Rotary::Dial< T >::m_value
protected

Definition at line 258 of file Rotary.hh.


The documentation for this class was generated from the following file: