HiveMind
UserInterface.h
Go to the documentation of this file.
1 #ifndef __USERINTERFACE_H_
2 #define __USERINTERFACE_H_
3 
4 #include "bsp/IBSP.h"
5 #include "bsp/IUserInterface.h"
6 #include <array>
7 #include <ros/subscriber.h>
8 #include <string>
9 
10 struct ButtonState {
12  void* m_context = NULL;
13 };
14 
15 struct UIState {
16  UIState();
18  std::array<bool, g_nbrLED> m_ledStates;
19  uint8_t m_hexDisplay;
20 };
21 
22 class UserInterface : public IUserInterface {
23  public:
24  UserInterface(const IBSP& bsp);
25  ~UserInterface() override = default;
26 
27  Mutex& getPrintMutex() override;
28  void flush() override;
29  int print(const char* format, ...) override;
30  int print(const char* format, va_list args) override;
31  int printLine(const char* format, ...) override;
32  int printLine(const char* format, va_list args) override;
33 
34  void setRGBLed(RgbColor color) override;
35  void setLed(LED led, bool state) override;
36  void setHexDisplay(uint8_t value) override;
37  void setButtonCallback(Button button,
38  buttonCallbackFunction_t callback,
39  void* context) override;
40 
41  private:
42  std::string uiStateToString();
43  std::array<ros::Subscriber, g_nbrLED> m_buttonSubscribers;
44 
45  const IBSP& m_bsp;
46  std::string m_accumulatedString;
47  Mutex m_mutex;
49 };
50 
51 #endif // __USERINTERFACE_H_
UserInterface::setHexDisplay
void setHexDisplay(uint8_t value) override
Sets the hex display to a given 8 bit value (not available on the HiveSight)
Definition: UserInterface.cpp:92
UserInterface::printLine
int printLine(const char *format,...) override
Provides an interface to print a line to the console or serial port. Flushes the input and adds a new...
Definition: UserInterface.cpp:70
ButtonState::m_callback
buttonCallbackFunction_t m_callback
Definition: UserInterface.h:11
UIState
Definition: UserInterface.h:15
IBSP.h
ButtonState
Definition: UserInterface.h:10
UserInterface::flush
void flush() override
Adds a newline and flushes the input to the serial port.
Definition: UserInterface.cpp:37
LED
LED
LED present on the board.
Definition: IUserInterface.h:22
ButtonState::m_context
void * m_context
Definition: UserInterface.h:12
UserInterface::uiStateToString
std::string uiStateToString()
Definition: UserInterface.cpp:114
UserInterface::m_buttonSubscribers
std::array< ros::Subscriber, g_nbrLED > m_buttonSubscribers
Definition: UserInterface.h:43
UserInterface::setLed
void setLed(LED led, bool state) override
Sets an LED on or off.
Definition: UserInterface.cpp:88
Button
Button
Buttons present on the board.
Definition: IUserInterface.h:16
UIState::m_hexDisplay
uint8_t m_hexDisplay
Definition: UserInterface.h:19
RgbColor
RgbColor
Possible colors obtainable with an RGB LED.
Definition: IUserInterface.h:11
IBSP
Definition: IBSP.h:6
UserInterface::~UserInterface
~UserInterface() override=default
UserInterface::m_bsp
const IBSP & m_bsp
Definition: UserInterface.h:45
UserInterface::m_accumulatedString
std::string m_accumulatedString
Definition: UserInterface.h:46
IUserInterface.h
UIState::m_rgbLed
RgbColor m_rgbLed
Definition: UserInterface.h:17
UserInterface::setButtonCallback
void setButtonCallback(Button button, buttonCallbackFunction_t callback, void *context) override
Sets the callback associated with a given button press.
Definition: UserInterface.cpp:94
UserInterface::m_uiState
UIState m_uiState
Definition: UserInterface.h:48
UserInterface::print
int print(const char *format,...) override
Provides an interface to print to the console or serial port. The arguments and return values match t...
Definition: UserInterface.cpp:43
UserInterface::UserInterface
UserInterface(const IBSP &bsp)
Definition: UserInterface.cpp:33
UserInterface::setRGBLed
void setRGBLed(RgbColor color) override
Sets the RGB LED to a given color.
Definition: UserInterface.cpp:86
UserInterface::m_mutex
Mutex m_mutex
Definition: UserInterface.h:47
IUserInterface
Manages the user interface The user interface can consist of buttons, LED, serial print ports,...
Definition: IUserInterface.h:36
UIState::m_ledStates
std::array< bool, g_nbrLED > m_ledStates
Definition: UserInterface.h:18
UserInterface::getPrintMutex
Mutex & getPrintMutex() override
get the mutex for printing. Note that the mutex is not used in any functions, the user needs to lock ...
Definition: UserInterface.cpp:35
buttonCallbackFunction_t
void(* buttonCallbackFunction_t)(void *instance)
Prototype for a callback from a button press.
Definition: IUserInterface.h:28
UserInterface
Definition: UserInterface.h:22
UIState::UIState
UIState()
Definition: UserInterface.cpp:31