mobile_io.hpp
Go to the documentation of this file.
1 #pragma once
2 
10 #include <array>
11 #include <bitset>
12 #include <memory>
13 
14 #include "hebi_cpp_api/group.hpp"
16 
17 namespace hebi {
18 namespace experimental {
19 
20 static constexpr size_t NumButtons = 8;
21 
22 struct MobileIODiff;
23 class MobileIO;
24 
25 // The current state at any time
26 struct MobileIOState {
27  // Note: one-indexed to match buttons on the screen
28  bool getButton(size_t button) const;
29  float getAxis(size_t axis) const;
30 
31 private:
32  std::bitset<NumButtons> buttons_;
33  std::array<float, NumButtons> axes_;
34 
35  friend struct MobileIODiff;
36  friend class MobileIO;
37 };
38 
39 // Difference between two IO states, useful for checking to see if a button
40 // has been pressed.
41 struct MobileIODiff {
42  MobileIODiff(const MobileIOState& prev, const MobileIOState& current);
43 
44  enum class ButtonState {
45  Off, On, // These occur if last + current state are the same
46  ToOff, ToOn // Edge triggers; these occur if last + current state are different
47  };
48 
49  // Note: one-indexed to match buttons on the screen
50  ButtonState get(int button) const;
51 
52 private:
53  std::array<ButtonState, NumButtons> buttons_;
54 };
55 
56 // Wrapper around a mobile IO controller
57 class MobileIO {
58 public:
59  enum class ButtonMode {
61  };
62 
63  static std::unique_ptr<MobileIO> create(const std::string& family, const std::string& name);
64 
65  // Input/feedback
67  // Input/feedback; the "got_feedback" flag indicates if feedback was received within the timeout
68  // or not.
69  MobileIOState getState(bool& got_feedback);
70 
71  // Outputs
72  // Note: one-indexed to match axes/buttons on the screen
73 
74  bool disableSnap(size_t axis_number) {
75  return setSnap(axis_number, std::numeric_limits<float>::quiet_NaN());
76  }
77 
78  bool setSnap(size_t axis_number, float snap_to);
79  bool setAxisValue(size_t axis_number, float value);
80 
81  bool setButtonMode(size_t button_number, ButtonMode mode);
82  bool setButtonOutput(size_t button_number, bool on);
83 
84  bool setLedColor(uint8_t r, uint8_t g, uint8_t b);
85 
86  bool sendText(const std::string& message);
87  bool clearText();
88 
89  // Return Feedback object specific to the mobile device (not GroupFeedback)
90  const hebi::Feedback& getLastFeedback() const { return fbk_[0]; };
91 
92 private:
93  MobileIO(std::shared_ptr<hebi::Group>);
94 
95  std::shared_ptr<hebi::Group> group_;
98 };
99 
100 } // namespace experimental
101 } // namespace hebi
hebi::experimental::MobileIOState::axes_
std::array< float, NumButtons > axes_
Definition: mobile_io.hpp:33
hebi::experimental::MobileIO::setSnap
bool setSnap(size_t axis_number, float snap_to)
Definition: mobile_io.cpp:85
hebi::experimental::MobileIO::setButtonMode
bool setButtonMode(size_t button_number, ButtonMode mode)
Definition: mobile_io.cpp:97
hebi::experimental::MobileIO::ButtonMode::Momentary
@ Momentary
hebi::experimental::MobileIO::getLastFeedback
const hebi::Feedback & getLastFeedback() const
Definition: mobile_io.hpp:90
hebi::experimental::MobileIO::group_
std::shared_ptr< hebi::Group > group_
Definition: mobile_io.hpp:95
hebi::experimental::MobileIOState::getButton
bool getButton(size_t button) const
Definition: mobile_io.cpp:11
hebi::experimental::MobileIO::clearText
bool clearText()
Definition: mobile_io.cpp:121
hebi::GroupFeedback
A list of Feedback objects that can be received from a Group of modules; the size() must match the nu...
Definition: group_feedback.hpp:16
hebi::experimental::MobileIO::setAxisValue
bool setAxisValue(size_t axis_number, float value)
Definition: mobile_io.cpp:91
hebi::experimental::MobileIO::fbk_
hebi::GroupFeedback fbk_
Definition: mobile_io.hpp:96
hebi::experimental::NumButtons
static constexpr size_t NumButtons
Definition: mobile_io.hpp:20
hebi::experimental::MobileIODiff::ButtonState::ToOff
@ ToOff
hebi::experimental::MobileIODiff::buttons_
std::array< ButtonState, NumButtons > buttons_
Definition: mobile_io.hpp:53
group.hpp
hebi::experimental::MobileIO::create
static std::unique_ptr< MobileIO > create(const std::string &family, const std::string &name)
Definition: mobile_io.cpp:43
hebi::experimental::MobileIO
Definition: mobile_io.hpp:57
hebi::experimental::MobileIOState
Definition: mobile_io.hpp:26
hebi::experimental::MobileIO::current_state_
MobileIOState current_state_
Definition: mobile_io.hpp:97
hebi::experimental::MobileIO::ButtonMode
ButtonMode
Definition: mobile_io.hpp:59
hebi::experimental::MobileIODiff::ButtonState::On
@ On
hebi::experimental::MobileIOState::buttons_
std::bitset< NumButtons > buttons_
Definition: mobile_io.hpp:32
hebi::experimental::MobileIO::ButtonMode::Toggle
@ Toggle
group_feedback.hpp
hebi::experimental::MobileIODiff::ButtonState
ButtonState
Definition: mobile_io.hpp:44
hebi::experimental::MobileIODiff
Definition: mobile_io.hpp:41
hebi::experimental::MobileIO::setButtonOutput
bool setButtonOutput(size_t button_number, bool on)
Definition: mobile_io.cpp:103
hebi
Definition: arm.cpp:5
hebi::experimental::MobileIO::setLedColor
bool setLedColor(uint8_t r, uint8_t g, uint8_t b)
Definition: mobile_io.cpp:109
hebi::experimental::MobileIODiff::MobileIODiff
MobileIODiff(const MobileIOState &prev, const MobileIOState &current)
Definition: mobile_io.cpp:24
hebi::experimental::MobileIODiff::get
ButtonState get(int button) const
Definition: mobile_io.cpp:37
hebi::experimental::MobileIO::disableSnap
bool disableSnap(size_t axis_number)
Definition: mobile_io.hpp:74
hebi::experimental::MobileIODiff::ButtonState::Off
@ Off
hebi::experimental::MobileIO::sendText
bool sendText(const std::string &message)
Definition: mobile_io.cpp:115
hebi::experimental::MobileIODiff::ButtonState::ToOn
@ ToOn
hebi::Feedback
Feedback objects have various fields representing feedback from modules; which fields are populated d...
Definition: feedback.hpp:32
hebi::experimental::MobileIO::getState
MobileIOState getState()
Definition: mobile_io.cpp:51
hebi::experimental::MobileIOState::getAxis
float getAxis(size_t axis) const
Definition: mobile_io.cpp:17
hebi::experimental::MobileIO::MobileIO
MobileIO(std::shared_ptr< hebi::Group >)
Definition: mobile_io.cpp:127


hebi_cpp_api_ros
Author(s): Chris Bollinger , Matthew Tesch
autogenerated on Fri Aug 2 2024 08:35:18