BPLightContraption
 All Classes Namespaces Files Functions Variables Macros Pages
powerunit.h
Go to the documentation of this file.
1 /*! \file
2  * \brief A class describing individual, controllable power units
3  * \author Benjamin Pritchard (ben@bennyp.org)
4  * \copyright 2013 Benjamin Pritchard. Released under the MIT License
5  */
6 
7 #ifndef POWERUNIT_H
8 #define POWERUNIT_H
9 
10 #include <QString>
11 #include <QSharedPointer>
12 #include <QtSerialPort/QSerialPort>
13 #include <QtSerialPort/QSerialPortInfo>
14 #include <microcont.h>
15 
16 using namespace std;
17 
18 //! A general interface to a power unit
19 /*!
20  * In general, if any operation goes wrong, this
21  * class will throw a MCInterfaceException
22  */
23 class PUInterface : public QObject
24 {
25  Q_OBJECT;
26 
27 public:
28  //! Constructor
29  /*!
30  * Creates an interface to a power unit given an id, description, and
31  * an pointer to the micrcontroller it's connected to
32  */
33  PUInterface(char id, const QString &desc, QSharedPointer<MCInterface> mc);
34 
35  ~PUInterface();
36 
37  //! Returns the current dimmer level
38  quint8 GetLevel(void);
39 
40  //! Returns the description of the power unit
41  QString GetDescription(void);
42 
43  //! Returns the ID of the power unit
44  char GetID(void);
45 
46  //! Returns the state of the power unit (see commands.h)
47  quint8 GetState(void);
48 
49  //! Syncs the state of the class with the given state and dimmer level
50  void SyncState(char state, quint8 level);
51 
52  //! Toggles the power unit between on and off
53  /*!
54  *
55  * This has no effect if the state is not PUSTATE_ON or PUSTATE_OFF
56  *
57  * \throw MCInterfaceException There is a problem communicating this command
58  * to the microcontroller
59  */
60  bool Toggle(void);
61 
62  //! Dims the powerunit to the given level
63  /*!
64  * \return The level to which it was actually set
65  * \throw MCInterfaceException There is a problem communicating this command
66  * to the microcontroller
67  */
68  quint8 SetLevel(quint8 level);
69 
70  //! Turns off the power unit
71  /*!
72  * \throw MCInterfaceException There is a problem communicating this command
73  * to the microcontroller
74  */
75  void TurnOff(void);
76 
77  //! Turns on the power unit
78  /*!
79  * \throw MCInterfaceException There is a problem communicating this command
80  * to the microcontroller
81  */
82  void TurnOn(void);
83 
84 
85  //! Resets the power unit state
86  /*!
87  * This does not actually communicate with the microcontroller
88  */
89  void Reset(void);
90 
91 
92  //! Returns true if the microcontroller controlling this power unit is open
93  bool MCIsOpen(void);
94 
95 
96  private:
97  char _id; //!< The ID given to this power unit
98  QString _desc; //!< A text description of the power unit
99  quint8 _state; //!< The current state of the power unit (PUSTATE_XXX)
100  quint8 _level; //!< The current dimmer level
101 
102  QSharedPointer<MCInterface> _mc; //!< The microcontroller interface controlling this power unit
103 
104  Q_DISABLE_COPY(PUInterface)
105 };
106 
107 #endif
108