BPLightContraption
 All Classes Namespaces Files Functions Variables Macros Pages
commands-text.h
Go to the documentation of this file.
1 /*! \file
2  * \brief Converts commands, powerunit ids, errors, etc (integers) to text
3  * \author Benjamin Pritchard (ben@bennyp.org)
4  * \copyright 2013 Benjamin Pritchard. Released under the MIT License
5  */
6 
7 
8 #ifndef COMMANDSTEXT_H
9 #define COMMANDSTEXT_H
10 
11 #include "commands.h"
12 
13 //! Returns the name of a PowerUnit given its ID
14 inline const char * ConvertPUID(char id)
15 {
16  switch (id)
17  {
18  case PU_LIGHT1:
19  return "Light 1";
20  case PU_LIGHT2:
21  return "Light 2";
22  case PU_RECEPTACLE:
23  return "Receptacle";
24  }
25 
26  return "Unknown";
27 }
28 
29 //! Returns a description of an error from the microcontroller
30 inline const char * ConvertMCError(char error)
31 {
32  switch (error)
33  {
34  case RES_SUCCESS:
35  return "No error";
36  case RES_INVALID_START:
37  return "Invalid start to command";
38  case RES_INVALID_COM:
39  return "Invalid command";
40  case RES_INVALID_ID:
41  return "Invalid unit id";
42  case RES_NODIMMER:
43  return "No dimmer available";
44  case RES_NOGENCLOCK:
45  return "No general-purpose clock available";
46  case RES_FAILURE:
47  return "Other failure";
48  }
49  return "Unknown error";
50 }
51 
52 //! Returns the text of a command given its ID
53 inline const char * ConvertCommandID(char cmd)
54 {
55  switch (cmd)
56  {
57  case COM_NOTHING:
58  return "Nothing/Ping";
59  case COM_ON:
60  return "Turn on";
61  case COM_OFF:
62  return "Turn off";
63  case COM_LEVEL:
64  return "Change level";
65  case COM_INFO:
66  return "Get info";
67  }
68  return "Unknown";
69 }
70 
71 //! Returns the text of a PowerUnit state
72 inline const char * ConvertPUState(char state)
73 {
74  switch (state)
75  {
76  case PUSTATE_OFF:
77  return "Off";
78  case PUSTATE_ON:
79  return "On";
80  case PUSTATE_DIM:
81  return "Dimming";
82  }
83  return "Unknown";
84 }
85 
86 #endif
87