ArduinoLibs
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | List of all members
BoolField Class Reference

Field that manages the input of a boolean value. More...

#include <BoolField.h>

Inheritance diagram for BoolField:
Field

Public Member Functions

 BoolField (const String &label)
 Constructs a new boolean field with a specific label. More...
 
 BoolField (Form &form, const String &label, const String &trueLabel, const String &falseLabel, bool value)
 Constructs a new boolean field with a specific label and attaches it to a form. More...
 
int dispatch (int event)
 Dispatches event via this field. More...
 
void enterField (bool reverse)
 Enters the field due to form navigation. More...
 
bool value () const
 Returns the current value of this field, true or false. More...
 
void setValue (bool value)
 Sets the current value of this field to value. More...
 
const String & trueLabel () const
 Returns the string that is displayed when value() is true. More...
 
void setTrueLabel (const String &trueLabel)
 Sets the string that is displayed when value() is true to trueLabel. More...
 
const String & falseLabel () const
 Returns the string that is displayed when value() is false. More...
 
void setFalseLabel (const String &falseLabel)
 Sets the string that is displayed when value() is false to falseLabel. More...
 
- Public Member Functions inherited from Field
 Field (const String &label)
 Constructs a new field with a specific label. More...
 
 Field (Form &form, const String &label)
 Constructs a new field with a specific label and attaches it to a form.
 
 ~Field ()
 Destroys this field and removes it from its owning Form. More...
 
Formform () const
 Returns the Form that owns this field; null if not associated with a Form.
 
virtual void exitField ()
 Exits the field due to form navigation. More...
 
const String & label () const
 Returns the label to display in the first line of this field. More...
 
void setLabel (const String &label)
 Sets the label to display in the first line of this field. More...
 
bool isCurrent () const
 Returns true if this field is the currently-displayed field in its owning form; false otherwise. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Field
LiquidCrystal * lcd () const
 Returns the LCD that this field is being drawn on.
 
virtual void updateCursor ()
 Updates the cursor position after the label has been drawn by setLabel(). More...
 

Detailed Description

Field that manages the input of a boolean value.

BoolField is intended for field values that are modifiable by the user. Pressing one of Up or Down will toggle the field's current value.

The following example creates a boolean field that shows the state of the status LED on D13. When the LED is on (the default), the string "On" will be displayed on the LCD screen. When the LED is off, the string "Off" will be displayed instead.

Form mainForm(lcd);
BoolField ledField(mainForm, "Status LED", "On", "Off", true);
FormBool.png

To actually toggle the LED, the application's main loop() function should contain the following code:

int event = lcd.getButton();
if (mainForm.dispatch(event) == FORM_CHANGED) {
if (mainForm.isCurrent(ledField)) {
if (ledField.value())
digitalWrite(STATUS_LED, HIGH);
else
digitalWrite(STATUS_LED, LOW);
}
}

Use TextField for read-only fields that report boolean values but which are not modifiable by the user.

ListField can be used to select between more than two items.

See Also
Field, ListField, TextField

Definition at line 28 of file BoolField.h.

Constructor & Destructor Documentation

BoolField::BoolField ( const String &  label)
explicit

Constructs a new boolean field with a specific label.

The field is initially not associated with a Form. The field can be added to a form later using Form::addField().

The initial value() will be false.

See Also
Form::addField()

Definition at line 77 of file BoolField.cpp.

BoolField::BoolField ( Form form,
const String &  label,
const String &  trueLabel,
const String &  falseLabel,
bool  value 
)

Constructs a new boolean field with a specific label and attaches it to a form.

The initial value() of the field is set to the parameter value. When value() is true, trueLabel will be displayed on the screen. When value() is false, falseLabel will be displayed on the screen.

See Also
value()

Definition at line 94 of file BoolField.cpp.

Member Function Documentation

int BoolField::dispatch ( int  event)
virtual

Dispatches event via this field.

The event is usually obtained from LCD::getButton().

Returns zero if the event has been handled and no further action is required.

Returns FORM_CHANGED if the event has changed the value of this field in a manner that may require the application to take further action based on the new field value.

Returns -1 if the event is not handled by this field, and should be handled by the Form itself (particularly for Left and Right buttons). The default implementation returns -1 for all events.

See Also
Form::dispatch(), LCD::getButton()

Reimplemented from Field.

Definition at line 103 of file BoolField.cpp.

void BoolField::enterField ( bool  reverse)
virtual

Enters the field due to form navigation.

This function is typically called when the user presses Left and Right buttons to navigate to the field. If reverse is true, then navigation was due to the Left button being pressed.

This function can assume that the display has been cleared and the cursor is positioned at (0, 0).

The default implementation prints the label().

See Also
exitField()

Reimplemented from Field.

Definition at line 113 of file BoolField.cpp.

const String & BoolField::falseLabel ( ) const
inline

Returns the string that is displayed when value() is false.

See Also
setFalseLabel(), trueLabel()

Definition at line 43 of file BoolField.h.

void BoolField::setFalseLabel ( const String &  falseLabel)

Sets the string that is displayed when value() is false to falseLabel.

See Also
falseLabel(), setTrueLabel()

Definition at line 173 of file BoolField.cpp.

void BoolField::setTrueLabel ( const String &  trueLabel)

Sets the string that is displayed when value() is true to trueLabel.

See Also
trueLabel(), setFalseLabel()

Definition at line 153 of file BoolField.cpp.

void BoolField::setValue ( bool  value)

Sets the current value of this field to value.

See Also
value()

Definition at line 131 of file BoolField.cpp.

const String & BoolField::trueLabel ( ) const
inline

Returns the string that is displayed when value() is true.

See Also
setTrueLabel(), falseLabel()

Definition at line 40 of file BoolField.h.

bool BoolField::value ( ) const
inline

Returns the current value of this field, true or false.

See Also
setValue()

Definition at line 37 of file BoolField.h.


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