COSA
An Object-Oriented Platform for Arduino Programming
AnalogPin Class Reference

#include <AnalogPin.hh>

Inheritance diagram for AnalogPin:
Inheritance graph
Collaboration diagram for AnalogPin:
Collaboration graph

Public Member Functions

 AnalogPin (Board::AnalogPin pin, Board::Reference ref=Board::AVCC_REFERENCE)
 
void reference (Board::Reference ref)
 
Board::Reference reference () const
 
Board::AnalogPin pin () const
 
uint16_t value () const
 
uint16_t sample ()
 
AnalogPinoperator>> (uint16_t &var)
 
 operator uint16_t ()
 
bool sample_request (uint8_t event=Event::NULL_TYPE)
 
uint16_t sample_await ()
 
virtual void on_interrupt (uint16_t arg)
 
virtual void on_change (uint16_t value)
 
virtual void enable ()
 
virtual void disable ()
 
virtual void clear ()
 

Static Public Member Functions

static void prescale (uint8_t factor)
 
static uint16_t sample (Board::AnalogPin pin, Board::Reference ref=Board::AVCC_REFERENCE)
 
static uint16_t bandgap (uint16_t vref=1100)
 
static void powerup ()
 
static void powerdown ()
 

Protected Member Functions

bool sample_request (Board::AnalogPin pin, uint8_t ref)
 
virtual void on_event (uint8_t type, uint16_t value)
 

Protected Attributes

const Board::AnalogPin m_pin
 Analog channel number. More...
 
Board::Reference m_reference
 ADC reference voltage type. More...
 
uint16_t m_value
 Latest sample value. More...
 
uint8_t m_event
 Event to push on completion. More...
 

Static Protected Attributes

static AnalogPinsampling_pin = NULL
 Current sampling pin if any. More...
 

Friends

void ADC_vect (void)
 

Detailed Description

Abstract analog pin. Allows asynchronous sampling with interrupt and event handler.

Definition at line 32 of file AnalogPin.hh.

Constructor & Destructor Documentation

AnalogPin::AnalogPin ( Board::AnalogPin  pin,
Board::Reference  ref = Board::AVCC_REFERENCE 
)
inline

Construct abstract analog pin for given pin (channel) and reference voltage.

Parameters
[in]pinnumber.
[in]refreference voltage (default VCC).

Definition at line 40 of file AnalogPin.hh.

Member Function Documentation

uint16_t AnalogPin::bandgap ( uint16_t  vref = 1100)
static

Get power supply voltage in milli-volt. May be used for low battery detection. Uses the internal 1V1 bandgap reference.

Parameters
[in]vrefreference voltage in milli-volt (default is 1100 mv).
Returns
milli-volt.

Definition at line 33 of file AnalogPin_static.cpp.

virtual void Interrupt::Handler::clear ( )
inlinevirtualinherited

Clear interrupt.

Reimplemented in InputCapture, and ExternalInterrupt.

Definition at line 59 of file Interrupt.hh.

virtual void Interrupt::Handler::disable ( )
inlinevirtualinherited

Disable interrupt handler.

Reimplemented in InputCapture, AnalogComparator, PinChangeInterrupt, and ExternalInterrupt.

Definition at line 53 of file Interrupt.hh.

virtual void Interrupt::Handler::enable ( )
inlinevirtualinherited

Enable interrupt handler.

Reimplemented in InputCapture, PinChangeInterrupt, ExternalInterrupt, and AnalogComparator.

Definition at line 47 of file Interrupt.hh.

virtual void AnalogPin::on_change ( uint16_t  value)
inlinevirtual

Default on change function.

Parameters
[in]value.

Definition at line 195 of file AnalogPin.hh.

void AnalogPin::on_event ( uint8_t  type,
uint16_t  value 
)
protectedvirtual

Handle analog pin periodic sampling and sample completed event. Will call virtual method on_change() if the pin value has changed since latest sample.

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

Reimplemented from Event::Handler.

Reimplemented in AnalogPins.

Definition at line 51 of file AnalogPin.cpp.

void AnalogPin::on_interrupt ( uint16_t  arg)
virtual

Interrupt service on conversion completion.

Parameters
[in]argsample value.

Reimplemented from Interrupt::Handler.

Reimplemented in AnalogPins.

Definition at line 65 of file AnalogPin.cpp.

AnalogPin::operator uint16_t ( )
inline

Sample analog pin. Wait for conversion to complete before returning with sample value.

Returns
sample value.

Definition at line 159 of file AnalogPin.hh.

AnalogPin& AnalogPin::operator>> ( uint16_t &  var)
inline

Sample analog pin. Wait for conversion to complete before returning with sample value.

Parameters
[out]varvariable to receive the value.
Returns
analog pin.

Definition at line 147 of file AnalogPin.hh.

Board::AnalogPin AnalogPin::pin ( ) const
inline

Get analog pin.

Returns
pin identity.

Definition at line 69 of file AnalogPin.hh.

static void AnalogPin::powerdown ( )
inlinestatic

Disable analog conversion.

Definition at line 123 of file AnalogPin.hh.

static void AnalogPin::powerup ( )
inlinestatic

Enable analog conversion.

Definition at line 113 of file AnalogPin.hh.

void AnalogPin::prescale ( uint8_t  factor)
static

Set analog conversion clock prescale (2..128, step power 2).

Parameters
[in]factorprescale.

Definition at line 26 of file AnalogPin_static.cpp.

void AnalogPin::reference ( Board::Reference  ref)
inline

Set reference voltage for conversion.

Parameters
[in]refreference voltage.

Definition at line 51 of file AnalogPin.hh.

Board::Reference AnalogPin::reference ( ) const
inline

Get reference voltage for conversion.

Returns
reference voltage.

Definition at line 60 of file AnalogPin.hh.

uint16_t AnalogPin::sample ( Board::AnalogPin  pin,
Board::Reference  ref = Board::AVCC_REFERENCE 
)
static

Sample analog pin. Wait for conversion to complete before returning with sample value.

Parameters
[in]pinnumber.
[in]refreference voltage.
Returns
sample value.

Definition at line 50 of file AnalogPin_static.cpp.

uint16_t AnalogPin::sample ( )
inline

Sample analog pin. Wait for conversion to complete before returning with sample value.

Returns
sample value.

Definition at line 135 of file AnalogPin.hh.

uint16_t AnalogPin::sample_await ( )

Await conversion to complete. Returns sample value

Returns
sample value.

Definition at line 38 of file AnalogPin.cpp.

bool AnalogPin::sample_request ( uint8_t  event = Event::NULL_TYPE)
inline

Request sample of analog pin. Pushes given event on completion. Default event is null/no event pushed for sample_await().

Parameters
[in]eventto push on completion.
Returns
bool.

Definition at line 171 of file AnalogPin.hh.

bool AnalogPin::sample_request ( Board::AnalogPin  pin,
uint8_t  ref 
)
protected

Internal request sample of analog pin. Set up sampling of given pin with given reference voltage.

Parameters
[in]pinnumber.
[in]refreference voltage.
Returns
bool.

Definition at line 24 of file AnalogPin.cpp.

uint16_t AnalogPin::value ( ) const
inline

Get latest sample.

Returns
sample value.
Note
atomic

Definition at line 79 of file AnalogPin.hh.

Friends And Related Function Documentation

void ADC_vect ( void  )
friend

Interrupt Service Routine

Forward declare interrupt service routines to allow them as friends.

Member Data Documentation

uint8_t AnalogPin::m_event
protected

Event to push on completion.

Definition at line 205 of file AnalogPin.hh.

const Board::AnalogPin AnalogPin::m_pin
protected

Analog channel number.

Definition at line 202 of file AnalogPin.hh.

Board::Reference AnalogPin::m_reference
protected

ADC reference voltage type.

Definition at line 203 of file AnalogPin.hh.

uint16_t AnalogPin::m_value
protected

Latest sample value.

Definition at line 204 of file AnalogPin.hh.

AnalogPin * AnalogPin::sampling_pin = NULL
staticprotected

Current sampling pin if any.

Definition at line 201 of file AnalogPin.hh.


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