BeoChip.H Interface to Brian Hudson's BeoChip device. More...
#include <Devices/BeoChip.H>
Public Member Functions | |
void | run () |
This is our main running thread - don't call directly. | |
bool | writeByte (const byte val, const bool uselock=true) |
send a byte to the BeoChip | |
Constructors, destructors and debugging | |
BeoChip (OptionManager &mgr, const std::string &descrName="BeoChip", const std::string &tagName="BeoChip") | |
Default constructor. See ModelComponent.H. | |
~BeoChip () | |
Destructor. | |
void | setListener (rutz::shared_ptr< BeoChipListener > &listener) |
Install a callback (listener) for BeoChip events. | |
bool | echoRequest () |
Send an echo request. | |
bool | debugMode (const bool on) |
Turn debug mode on/off. | |
bool | resetChip () |
Reset the BeoChip. | |
LCD functions | |
bool | lcdGotoXY (const int x=0, const int y=0) |
Go to given cursor position. | |
bool | lcdGoto (const int i=0) |
Go to given cursor position. | |
bool | lcdPrintf (const char *fmt,...) __attribute__((format(__printf__ |
Print some text. | |
bool bool | lcdPrintf (const int x, const int y, const char *fmt,...) __attribute__((format(__printf__ |
Print some text starting at given cursor position. | |
bool bool bool | lcdClear () |
Clear LCD screen. | |
bool | lcdScrollLeft (const int i=1) |
Scroll display left by i positions. | |
bool | lcdScrollRight (const int i=1) |
Scroll display right by i positions. | |
bool | lcdMoveCursorLeft (const int i=1) |
Move cursor left by i positions. | |
bool | lcdMoveCursorRight (const int i=1) |
Move cursor right by i positions. | |
bool | lcdCursorBlock () |
Make cursor a blinking block. | |
bool | lcdCursorUnderline () |
Make cursor a blinking underline. | |
bool | lcdCursorInvisible () |
Make cursor invisible (not recommended). | |
bool | lcdLoadFont (const int font) |
Load one of the pre-programmed custom fonts. | |
bool | lcdLoadFont (const byte data[64]) |
Load a new font from an array of 64 bytes. | |
bool | lcdSetAnimation (const int anim=0) |
Select an LCD animation and start it. | |
bool | lcdSendRaw (const byte val, const bool RS, const bool uselock=true) |
Send a raw byte to the LCD. | |
Servo control functions | |
bool | shimServos (const byte shim) |
Shim the BeoChip's servo pulses. | |
void | calibrateServo (const int servo, const byte neutralval, const byte minval, const byte maxval) |
Calibrate a servo. | |
bool | setServo (const int servo, const float position) |
Moves servo # to given position in [-1.0 .. 1.0]. | |
float | getServo (const int servo) const |
Gets the current position of given servo. | |
bool | setServoRaw (const int servo, const byte val) |
Sets servo number servo to value val. | |
byte | getServoRaw (const int servo) const |
Gets the current raw position of given servo. | |
Pulse acquisition functions | |
bool | capturePulse (const int whichone, const bool on) |
Turn pulse captures on/off. | |
void | calibratePulse (const int whichone, const int neutralval, const int minval, const int maxval) |
Calibrate a pulse. | |
float | getPulse (const int whichone) |
Get current pulse value, between [-1.0..1.0]. | |
short int | getPulseRaw (const int whichone) |
Get current pulse value, raw uncalibrated. | |
Analog acquisition functions | |
bool | captureAnalog (const int whichone, const bool on) |
Turn A/D captures on/off. | |
void | calibrateAnalog (const int whichone, const int neutralval, const int minval, const int maxval) |
Calibrate an A/D converter. | |
float | getAnalog (const int whichone) |
Get current calibrated Analog value. | |
byte | getAnalogRaw (const int whichone) |
Get current raw Analog value. | |
Keyboard acquisition functions | |
bool | captureKeyboard (const bool on) |
Turn keyboard capture on/off. | |
bool | debounceKeyboard (const bool on) |
Turn keyboard debouncing on/off. | |
int | getKeyboard () |
Get current Keyboard value. | |
Digital output function | |
bool | setDigitalOut (const int outnum, const bool on) |
Turn a given digital output on/off. | |
Protected Member Functions | |
float | rawToCalib (const int raw, const int zero, const int mini, const int maxi) const |
Convert from raw (int) to calibrated (-1.0..1.0) position. | |
int | calibToRaw (const float calibrated, const int zero, const int mini, const int maxi, const int bits=8) const |
Convert from calibrated (-1.0..1.0) to raw (int) position. | |
void | start1 () |
open the port and get started | |
void | stop2 () |
close the port and get stopped | |
Protected Attributes | |
NModelParam< std::string > | itsDevName |
name of our serial device | |
NModelParam< int > | itsLCDrows |
number of rows of LCD screen (lines of text) | |
NModelParam< int > | itsLCDcols |
number of columns of LCD screen | |
rutz::shared_ptr< NModelParam < int > > * | zeroS |
zero calibration value, for 0.0F (servo) | |
rutz::shared_ptr< NModelParam < int > > * | minS |
minimum raw value, for -1.0F (servo) | |
rutz::shared_ptr< NModelParam < int > > * | maxS |
maximum raw value, for 1.0F (servo) | |
byte * | servopos |
raw servo positions [0..255] | |
rutz::shared_ptr< NModelParam < int > > * | zeroP |
zero calibration value, for 0.0F (pulse) | |
rutz::shared_ptr< NModelParam < int > > * | minP |
minimum raw value, for -1.0F (pulse) | |
rutz::shared_ptr< NModelParam < int > > * | maxP |
maximum raw value, for 1.0F (pulse) | |
short int * | pulseval |
raw pulse values (11bit int) | |
rutz::shared_ptr< NModelParam < int > > * | zeroA |
zero calibration value, for 0.0F (pulse) | |
rutz::shared_ptr< NModelParam < int > > * | minA |
minimum raw value, for -1.0F (servo) | |
rutz::shared_ptr< NModelParam < int > > * | maxA |
maximum raw value, for 1.0F (servo) | |
NModelParam< bool > | itsUseRTSCTS |
Use RTS/CTS flow control. | |
byte * | adcval |
raw adc values [0..255] | |
byte | keyboard |
our current keyboard state |
BeoChip.H Interface to Brian Hudson's BeoChip device.
Hardware interface Class. Contains interfaces to display to an LCD, read servo pulse values (2), set servo positions (8), get A/D conversion values (2), manipulate four digital outs, and finally, get some intput from 5 pushbuttons.
Definition at line 104 of file BeoChip.H.
BeoChip::BeoChip | ( | OptionManager & | mgr, | |
const std::string & | descrName = "BeoChip" , |
|||
const std::string & | tagName = "BeoChip" | |||
) |
BeoChip::~BeoChip | ( | ) |
void BeoChip::calibrateAnalog | ( | const int | whichone, | |
const int | neutralval, | |||
const int | minval, | |||
const int | maxval | |||
) |
void BeoChip::calibratePulse | ( | const int | whichone, | |
const int | neutralval, | |||
const int | minval, | |||
const int | maxval | |||
) |
int BeoChip::calibToRaw | ( | const float | calibrated, | |
const int | zero, | |||
const int | mini, | |||
const int | maxi, | |||
const int | bits = 8 | |||
) | const [protected] |
Convert from calibrated (-1.0..1.0) to raw (int) position.
Definition at line 768 of file BeoChip.C.
Referenced by setServo().
bool BeoChip::captureAnalog | ( | const int | whichone, | |
const bool | on | |||
) |
Turn A/D captures on/off.
Definition at line 557 of file BeoChip.C.
References ASSERT, and writeByte().
bool BeoChip::captureKeyboard | ( | const bool | on | ) |
bool BeoChip::capturePulse | ( | const int | whichone, | |
const bool | on | |||
) |
Turn pulse captures on/off.
Definition at line 519 of file BeoChip.C.
References ASSERT, and writeByte().
bool BeoChip::debounceKeyboard | ( | const bool | on | ) |
bool BeoChip::debugMode | ( | const bool | on | ) |
Turn debug mode on/off.
When in debug mode, the BeoChip sends an EchoReply for each command it receives.
Definition at line 232 of file BeoChip.C.
References writeByte().
bool BeoChip::echoRequest | ( | ) |
Send an echo request.
The BeoChip should reply with an EchoReply event if it is alive
Definition at line 225 of file BeoChip.C.
References writeByte().
float BeoChip::getAnalog | ( | const int | whichone | ) |
Get current calibrated Analog value.
Definition at line 576 of file BeoChip.C.
References ASSERT, getAnalogRaw(), maxS, minS, rawToCalib(), and zeroS.
byte BeoChip::getAnalogRaw | ( | const int | whichone | ) |
Get current raw Analog value.
Definition at line 585 of file BeoChip.C.
References adcval, and ASSERT.
Referenced by getAnalog().
int BeoChip::getKeyboard | ( | ) |
float BeoChip::getPulse | ( | const int | whichone | ) |
Get current pulse value, between [-1.0..1.0].
Definition at line 538 of file BeoChip.C.
References ASSERT, getPulseRaw(), maxP, minP, rawToCalib(), and zeroP.
short int BeoChip::getPulseRaw | ( | const int | whichone | ) |
Get current pulse value, raw uncalibrated.
Definition at line 547 of file BeoChip.C.
References ASSERT, and pulseval.
Referenced by getPulse().
float BeoChip::getServo | ( | const int | servo | ) | const |
Gets the current position of given servo.
Definition at line 483 of file BeoChip.C.
References ASSERT, getServoRaw(), maxS, minS, rawToCalib(), and zeroS.
byte BeoChip::getServoRaw | ( | const int | servo | ) | const |
Gets the current raw position of given servo.
Definition at line 512 of file BeoChip.C.
References ASSERT, and servopos.
Referenced by getServo().
bool BeoChip::lcdClear | ( | ) |
bool BeoChip::lcdCursorBlock | ( | ) |
bool BeoChip::lcdCursorInvisible | ( | ) |
Make cursor invisible (not recommended).
Definition at line 378 of file BeoChip.C.
References lcdSendRaw().
bool BeoChip::lcdCursorUnderline | ( | ) |
Make cursor a blinking underline.
Definition at line 374 of file BeoChip.C.
References lcdSendRaw().
bool BeoChip::lcdGoto | ( | const int | i = 0 |
) |
Go to given cursor position.
Definition at line 268 of file BeoChip.C.
References lcdSendRaw().
Referenced by lcdGotoXY().
bool BeoChip::lcdGotoXY | ( | const int | x = 0 , |
|
const int | y = 0 | |||
) |
Go to given cursor position.
Definition at line 246 of file BeoChip.C.
References NModelParam< T >::getVal(), itsLCDcols, itsLCDrows, and lcdGoto().
Referenced by lcdPrintf().
bool BeoChip::lcdLoadFont | ( | const byte | data[64] | ) |
Load a new font from an array of 64 bytes.
Definition at line 395 of file BeoChip.C.
References lcdSendRaw().
bool BeoChip::lcdLoadFont | ( | const int | font | ) |
Load one of the pre-programmed custom fonts.
Valid font values are [0..7]. Font 0 is an all-blank font.
Definition at line 382 of file BeoChip.C.
References writeByte().
bool BeoChip::lcdMoveCursorLeft | ( | const int | i = 1 |
) |
bool BeoChip::lcdMoveCursorRight | ( | const int | i = 1 |
) |
Move cursor right by i positions.
Definition at line 357 of file BeoChip.C.
References lcdSendRaw().
bool BeoChip::lcdPrintf | ( | const int | x, | |
const int | y, | |||
const char * | fmt, | |||
... | ||||
) |
Print some text starting at given cursor position.
syntax is the same as printf(), plus the x, y coordinates. Returns true on success.
Definition at line 297 of file BeoChip.C.
References NModelParam< T >::getVal(), itsLCDcols, lcdGotoXY(), and lcdPrintf().
bool BeoChip::lcdPrintf | ( | const char * | fmt, | |
... | ||||
) |
Print some text.
syntax is the same as printf(). Returns true on success.
Definition at line 278 of file BeoChip.C.
References NModelParam< T >::getVal(), itsLCDcols, and lcdSendRaw().
Referenced by lcdPrintf().
bool BeoChip::lcdScrollLeft | ( | const int | i = 1 |
) |
Scroll display left by i positions.
Definition at line 318 of file BeoChip.C.
References lcdSendRaw().
bool BeoChip::lcdScrollRight | ( | const int | i = 1 |
) |
Scroll display right by i positions.
Definition at line 331 of file BeoChip.C.
References lcdSendRaw().
bool BeoChip::lcdSendRaw | ( | const byte | val, | |
const bool | RS, | |||
const bool | uselock = true | |||
) |
Send a raw byte to the LCD.
Definition at line 425 of file BeoChip.C.
References writeByte().
Referenced by lcdClear(), lcdCursorBlock(), lcdCursorInvisible(), lcdCursorUnderline(), lcdGoto(), lcdLoadFont(), lcdMoveCursorLeft(), lcdMoveCursorRight(), lcdPrintf(), lcdScrollLeft(), and lcdScrollRight().
bool BeoChip::lcdSetAnimation | ( | const int | anim = 0 |
) |
Select an LCD animation and start it.
Valid anim values are [0..7]. Anim 0 is no animation.
Definition at line 412 of file BeoChip.C.
References writeByte().
float BeoChip::rawToCalib | ( | const int | raw, | |
const int | zero, | |||
const int | mini, | |||
const int | maxi | |||
) | const [protected] |
Convert from raw (int) to calibrated (-1.0..1.0) position.
Definition at line 755 of file BeoChip.C.
Referenced by getAnalog(), getPulse(), getServo(), and run().
bool BeoChip::resetChip | ( | ) |
void BeoChip::run | ( | ) |
bool BeoChip::setDigitalOut | ( | const int | outnum, | |
const bool | on | |||
) |
Turn a given digital output on/off.
Valid range for outnum is [0..3]
Definition at line 618 of file BeoChip.C.
References ASSERT, and writeByte().
void BeoChip::setListener | ( | rutz::shared_ptr< BeoChipListener > & | listener | ) |
bool BeoChip::setServo | ( | const int | servo, | |
const float | position | |||
) |
Moves servo # to given position in [-1.0 .. 1.0].
Returns true on success, false if some serial error occurred.
Definition at line 474 of file BeoChip.C.
References ASSERT, calibToRaw(), maxS, minS, setServoRaw(), and zeroS.
bool BeoChip::setServoRaw | ( | const int | servo, | |
const byte | val | |||
) |
Sets servo number servo to value val.
Definition at line 493 of file BeoChip.C.
References ASSERT, servopos, and writeByte().
Referenced by setServo().
bool BeoChip::shimServos | ( | const byte | shim | ) |
Shim the BeoChip's servo pulses.
Valid shim values are [0..7]. The default at bootup of the BeoChip is 4. Higher values will increase pulse length and lower values will decrease them. This may allow you to shim the pulses so as to maximally exploit the range of your servos.
Definition at line 451 of file BeoChip.C.
References writeByte().
void BeoChip::start1 | ( | ) | [protected, virtual] |
open the port and get started
Reimplemented from ModelComponent.
Definition at line 141 of file BeoChip.C.
References NModelParam< T >::getVal(), itsDevName, and itsUseRTSCTS.
void BeoChip::stop2 | ( | ) | [protected, virtual] |
close the port and get stopped
Reimplemented from ModelComponent.
bool BeoChip::writeByte | ( | const byte | val, | |
const bool | uselock = true | |||
) |
send a byte to the BeoChip
You should never have to use this, use the other functions instead. This function is made public just for testing the chip's robustness against a flood of random junk hitting it... See test-BeoChip.C
Definition at line 626 of file BeoChip.C.
References MYLOGVERB.
Referenced by captureAnalog(), captureKeyboard(), capturePulse(), debounceKeyboard(), debugMode(), echoRequest(), lcdLoadFont(), lcdSendRaw(), lcdSetAnimation(), resetChip(), setDigitalOut(), setServoRaw(), and shimServos().
byte* BeoChip::adcval [protected] |
raw adc values [0..255]
Definition at line 350 of file BeoChip.H.
Referenced by BeoChip(), getAnalogRaw(), run(), and ~BeoChip().
NModelParam<std::string> BeoChip::itsDevName [protected] |
NModelParam<int> BeoChip::itsLCDcols [protected] |
number of columns of LCD screen
Definition at line 332 of file BeoChip.H.
Referenced by lcdGotoXY(), and lcdPrintf().
NModelParam<int> BeoChip::itsLCDrows [protected] |
number of rows of LCD screen (lines of text)
Definition at line 331 of file BeoChip.H.
Referenced by lcdGotoXY().
NModelParam<bool> BeoChip::itsUseRTSCTS [protected] |
byte BeoChip::keyboard [protected] |
our current keyboard state
Definition at line 352 of file BeoChip.H.
Referenced by BeoChip(), getKeyboard(), and run().
rutz::shared_ptr<NModelParam<int> >* BeoChip::maxA [protected] |
maximum raw value, for 1.0F (servo)
Definition at line 346 of file BeoChip.H.
Referenced by BeoChip(), calibrateAnalog(), run(), and ~BeoChip().
rutz::shared_ptr<NModelParam<int> >* BeoChip::maxP [protected] |
maximum raw value, for 1.0F (pulse)
Definition at line 341 of file BeoChip.H.
Referenced by BeoChip(), calibratePulse(), getPulse(), run(), and ~BeoChip().
rutz::shared_ptr<NModelParam<int> >* BeoChip::maxS [protected] |
maximum raw value, for 1.0F (servo)
Definition at line 336 of file BeoChip.H.
Referenced by BeoChip(), calibrateServo(), getAnalog(), getServo(), setServo(), and ~BeoChip().
rutz::shared_ptr<NModelParam<int> >* BeoChip::minA [protected] |
minimum raw value, for -1.0F (servo)
Definition at line 345 of file BeoChip.H.
Referenced by BeoChip(), calibrateAnalog(), run(), and ~BeoChip().
rutz::shared_ptr<NModelParam<int> >* BeoChip::minP [protected] |
minimum raw value, for -1.0F (pulse)
Definition at line 340 of file BeoChip.H.
Referenced by BeoChip(), calibratePulse(), getPulse(), run(), and ~BeoChip().
rutz::shared_ptr<NModelParam<int> >* BeoChip::minS [protected] |
minimum raw value, for -1.0F (servo)
Definition at line 335 of file BeoChip.H.
Referenced by BeoChip(), calibrateServo(), getAnalog(), getServo(), setServo(), and ~BeoChip().
short int* BeoChip::pulseval [protected] |
raw pulse values (11bit int)
Definition at line 342 of file BeoChip.H.
Referenced by BeoChip(), getPulseRaw(), run(), and ~BeoChip().
byte* BeoChip::servopos [protected] |
raw servo positions [0..255]
Definition at line 337 of file BeoChip.H.
Referenced by BeoChip(), getServoRaw(), setServoRaw(), and ~BeoChip().
rutz::shared_ptr<NModelParam<int> >* BeoChip::zeroA [protected] |
zero calibration value, for 0.0F (pulse)
Definition at line 344 of file BeoChip.H.
Referenced by BeoChip(), calibrateAnalog(), run(), and ~BeoChip().
rutz::shared_ptr<NModelParam<int> >* BeoChip::zeroP [protected] |
zero calibration value, for 0.0F (pulse)
Definition at line 339 of file BeoChip.H.
Referenced by BeoChip(), calibratePulse(), getPulse(), run(), and ~BeoChip().
rutz::shared_ptr<NModelParam<int> >* BeoChip::zeroS [protected] |
zero calibration value, for 0.0F (servo)
Definition at line 334 of file BeoChip.H.
Referenced by BeoChip(), calibrateServo(), getAnalog(), getServo(), setServo(), and ~BeoChip().