class::ev::DeviceButton

class ev::DeviceButton
  : public ev::Button
  : public hal::Device

The Device Button class implements one or more buttons using the sos/dev/button.h device driver interface.

Because the button events are running at the device driver level, the button responses will be better than ui::PinButton.

Also, using a device driver for the buttons makes the applications much more portable.

Summary

DeviceButton()

int count() const

virtual enum ev::Event::button_id event_id() const

virtual bool get_actuated()

virtual chrono::MicroTime get_duration()

virtual bool get_held()

virtual bool get_pressed()

virtual bool get_released()

int init()

virtual bool is_active() const

virtual void reset()

void set(

int location
)

int set_attributes(

const arg::Location location,
enum ev::Event::button_id id,
const arg::ButtonHeldThreshold held_threshold,
const arg::ButtonActuatedThreshold actuated_threshold
)

protected virtual void update()

Members

DeviceButton()

int count() const

Returns the number of buttons available.

This will query the device for the number of buttons available. The set() method will select which button is read.


virtual enum ev::Event::button_id event_id() const

Access the event ID of the button


virtual bool get_actuated()

Returns true if the button was pressed then released This will return true only once per button press.


virtual chrono::MicroTime get_duration()

Returns the duration of the last button press. This method will only return a non-zero value once per button press.


virtual bool get_held()

Returns true if the button has been held for the specified duration This will only return true once per button press.


virtual bool get_pressed()

Returns true if the button has been pressed. This will only return true once per button press.


virtual bool get_released()

Returns true if the button has been released. This will only return true one time for each button press.


int init()

Initializes the button driver.

Returns

Zero on success.


virtual bool is_active() const

Returns true if the button is currently in the active state. The active state is updated each time Button::update() is called.


virtual void reset()

Reset the state of the button


void set(

int location
)

Sets the button to the index specified.

Parameters

  • location The button channel/location value

If the device supports multiple buttons, this method will select which button is effective.

One object can emit events for multiple buttons using this method.

#include <sapi/ui.hpp>

DeviceButton button;

button.open("/dev/button0");

int count = button.count();
for(int i = 0; i < count; i++){
  button.set(i);
  Event event = button.get_event();
}

int set_attributes(

const arg::Location location,
enum ev::Event::button_id id,
const arg::ButtonHeldThreshold held_threshold,
const arg::ButtonActuatedThreshold actuated_threshold
)

Sets the attributes for the specified button.

Parameters

  • location The button index

  • id The Event ID to assign to the button

  • held_threshold The threshold to wait before button held event is triggered

  • actuated_threshold The minimum button press time for an actuation event

Returns

Zero on success


protected virtual void update()

This will update the state of the button. This method should be called periodically.


X

Thanks for Coming!

Subscribe to news and updates