COSA
An Object-Oriented Platform for Arduino Programming
Rotary::Encoder Class Reference

#include <Rotary.hh>

Inheritance diagram for Rotary::Encoder:
Inheritance graph
Collaboration diagram for Rotary::Encoder:
Collaboration graph

Classes

class  SignalPin
 

Public Types

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

Public Member Functions

 Encoder (Board::InterruptPin clk, Board::InterruptPin dt, Mode mode=FULL_CYCLE)
 
Mode mode () const
 
void mode (Mode mode)
 
void enable ()
 
void disable ()
 
virtual void on_event (uint8_t type, uint16_t value)
 

Protected Member Functions

Direction detect ()
 

Protected Attributes

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

Rotary Encoder using pin change interrupts. Handles half and full cycle detection. Will push an Event::CHANGE_TYPE with the direction of the change.

Circuit

KY-040 Rotary Encoder Module.

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

Definition at line 60 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.

Rotary Encoder cycle mode.

Enumerator
HALF_CYCLE 
FULL_CYCLE 

Definition at line 74 of file Rotary.hh.

Constructor & Destructor Documentation

Rotary::Encoder::Encoder ( Board::InterruptPin  clk,
Board::InterruptPin  dt,
Mode  mode = FULL_CYCLE 
)
inline

Create Rotary Encoder with given interrupt pins. Setup must call InterruptPin::begin() to initiate handling of pins.

Parameters
[in]clkpin.
[in]dtpin.
[in]modecycle (default FULL_CYCLE).

Definition at line 86 of file Rotary.hh.

Member Function Documentation

Rotary::Encoder::Direction Rotary::Encoder::detect ( )
protected

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 ( )
inline

Disable the encoder.

Definition at line 127 of file Rotary.hh.

void Rotary::Encoder::enable ( )
inline

Enable the encoder.

Definition at line 117 of file Rotary.hh.

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

Get current cycle mode.

Returns
mode.

Definition at line 100 of file Rotary.hh.

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

Set cycle mode.

Parameters
[in]modecycle.

Definition at line 109 of file Rotary.hh.

virtual void Event::Handler::on_event ( uint8_t  type,
uint16_t  value 
)
inlinevirtualinherited

Default null event handler. Should be redefined by sub-classes. Called by Event::dispatch().

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

Reimplemented in Menu::RotaryController, Rotary::Dial< T >, AnalogPin, Job, TWI::Slave, ProtoThread, AnalogPins, and Periodic.

Definition at line 107 of file Event.hh.

Member Data Documentation

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

Full-cycle state transition tables.

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

dot_inline_dotgraph_6.png

Definition at line 161 of file Rotary.hh.

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

Half-cycle state transition tables.

Definition at line 158 of file Rotary.hh.

SignalPin Rotary::Encoder::m_clk
protected

Signal pins, previous state and cycle mode.

Definition at line 164 of file Rotary.hh.

SignalPin Rotary::Encoder::m_dt
protected

Definition at line 165 of file Rotary.hh.

Mode Rotary::Encoder::m_mode
protected

Definition at line 167 of file Rotary.hh.

uint8_t Rotary::Encoder::m_state
protected

Definition at line 166 of file Rotary.hh.


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