RDK Documentation (Open Sourced RDK Components)
frontPanelTextDisplay.cpp
Go to the documentation of this file.
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 
21 /**
22  * @file frontPanelTextDisplay.cpp
23  * @brief Configuration of individual text display sub-panel to display system time or text is managed here.
24  * The scroll speed, time format (12Hour or 24 Hour format) and a string to display can be configured.
25  */
26 
27 
28 
29 /**
30 * @defgroup devicesettings
31 * @{
32 * @defgroup ds
33 * @{
34 **/
35 
36 
37 #include <iostream>
38 #include <sstream>
39 
41 #include "frontPanelConfig.hpp"
42 #include "illegalArgumentException.hpp"
43 #include "host.hpp"
44 
45 #include "dslogger.h"
46 #include "dsError.h"
47 #include "dsTypes.h"
48 
49 using namespace std;
50 
51 std::string numToStr (int number)
52 {
53  stringstream convert;
54  convert << number;
55  return convert.str();
56 }
57 
58 int strToNum (std::string text)
59 {
60  int number;
61  stringstream convert (text);
62 
63  if (!(convert >> number) )
64  number = 0;
65 
66  return number;
67 }
68 
69 
70 namespace {
71  const char *_names[] = {
72  "Text",
73  };
74 
75  inline const bool isValid(int id) {
76  return dsFPDTextDisplay_isValid(id);
77  }
78 }
79 
80 
81 namespace device {
82 
83 const int FrontPanelTextDisplay::kModeClock12Hr = dsFPD_TIME_12_HOUR;
84 const int FrontPanelTextDisplay::kModeClock24Hr = dsFPD_TIME_24_HOUR;
85 const int FrontPanelTextDisplay::kModeString = dsFPD_TIME_STRING;
86 const char * FrontPanelTextDisplay::kPropertyBrightness = ".brightness";
87 
88 /**
89  * @addtogroup dssettingsfptextdisplayapi
90  * @{
91  */
92 
93 /**
94  * @fn FrontPanelTextDisplay::getInstance(int id)
95  * @brief This API gets the FrontPanelIndicator instance corresponding to the specified id, only if the id
96  * passed is valid.
97  *
98  * @param[in] id Indicates the id of the FrontPanelTextDisplay whose instance has to be returned.
99  *
100  * @return Returns an instance of FrontPanelTextDisplay corresponding to the id parameter or else throws an
101  * IllegalArgumentException indicating that the instance corresponding to the id was not found.
102  */
103 FrontPanelTextDisplay & FrontPanelTextDisplay::getInstance(int id)
104 {
105  if (::isValid(id)) {
106  return FrontPanelConfig::getInstance().getTextDisplay(id);
107  }
108  else {
109  throw IllegalArgumentException();
110  }
111 
112 }
113 
114 
115 /**
116  * @fn FrontPanelTextDisplay::getInstance(const std::string &name)
117  * @brief This API gets the FrontPanelTextDisplay instance based on the name parameter passed as input.
118  * <ul>
119  * <li> Text is the valid name for front panel text display.
120  * </ul>
121  *
122  * @param[in] name Indicates the name against which the FrontPanelTextDisplay instance has to be returned.
123  *
124  * @return Returns the FrontPanelTextDisplay instance corresponding to the name parameter else throws
125  * an IllegalArgumentException if the instance corresponding to the name parameter is not found.
126  */
127 FrontPanelTextDisplay & FrontPanelTextDisplay::getInstance(const std::string &name)
128 {
129  for (size_t i = 0; i < dsUTL_DIM(_names); i++) {
130  if (name.compare(_names[i]) == 0) {
131  return FrontPanelConfig::getInstance().getTextDisplay(i);
132  }
133  }
134 
135  throw IllegalArgumentException();
136 }
137 
138 
139 /**
140  * @fn FrontPanelTextDisplay(int id, int maxBrightness, int maxCycleRate, int levels,
141  * int maxHorizontalIterations, int maxVerticalIterations, const string &supportedCharacters,int colorMode)
142  * @brief This function is the default constructor for FrontPanelTextDisplay. It initializes the data members
143  * of FrontPanelTextDisplay instance with the parameters passed.
144  *
145  * @param[in] id Indicates the id for the FrontPanelTextDisplay instance.
146  * @param[in] maxBrightness Indicates maximum brightness value for the text display which is 100.
147  * @param[in] maxCycleRate Indicates maximum cycle rate for the text display which is 2 by default.
148  * @param[in] levels Indicates brightness level for the text display.
149  * @param[in] maxHorizontalIterations Indicates maximum horizontal iterations for scrolling.
150  * @param[in] maxVerticalIterations Indicates maximum vertical iterations for scrolling.
151  * @param[in] supportedCharacters Indicates supported characters for text display. The default supported
152  * supported characters are ABCDEF.
153  * @param[in] colorMode Indicates color mode for the text display.
154  *
155  * @return None
156  */
157 FrontPanelTextDisplay::FrontPanelTextDisplay(int id, int maxBrightness, int maxCycleRate, int levels,
158  int maxHorizontalIterations, int maxVerticalIterations,
159  const string &supportedCharacters,int colorMode):
160  FrontPanelIndicator(id, maxBrightness, maxCycleRate, levels, colorMode)
161 {
162  _TextBrightness = 0; //CID:80988 - Uninit_ctor
164  _scroll = Scroll(maxVerticalIterations, maxHorizontalIterations);
165  if (::isValid(id)) {
166  _id = id;
167  _name = std::string(_names[id]);
168  }
169  else {
170  throw IllegalArgumentException();
171  }
172 }
173 
174 FrontPanelTextDisplay::~FrontPanelTextDisplay()
175 {
176 }
177 
178 
179 /**
180  * @fn FrontPanelTextDisplay::setText(const std::string &text)
181  * @brief This API sets the text LED display, by switching the text display to text mode.
182  *
183  * @param[in] text Indicates the text to be displayed.
184  *
185  * @return None
186  */
187 void FrontPanelTextDisplay::setText(const std::string &text)
188 {
189  dsError_t ret = dsSetFPText(text.c_str());
190  if (ret != dsERR_NONE) {
191  throw Exception(ret);
192  }
193 }
194 
195 
196 /**
197  * @fn FrontPanelTextDisplay::enableDisplay(const int enable)
198  * @brief This function is used to enable or disable the display of clock on front panel.
199  *
200  * @param[in] enable Indicates enable or disable value.
201  *
202  * @return None
203  */
205 {
207  if (ret != dsERR_NONE) {
208  throw Exception(ret);
209  }
210 }
211 
212 
213 /**
214  * @fn FrontPanelTextDisplay::setTextBrightness(const int &brightness)
215  * @brief This API sets the brightness value for the front panel LED.
216  *
217  * @param[in] brightness Indicates the brightness value to be set for text LED.
218  *
219  * @return None
220  */
221 void FrontPanelTextDisplay::setTextBrightness(const int &brightness)
222 {
224  if (ret != dsERR_NONE) {
225  throw Exception(ret);
226  }
227  else
228  {
229  _TextBrightness = brightness;
230  }
231 }
232 
233 
234 /**
235  * @fn FrontPanelTextDisplay::getTextBrightness()
236  * @brief This API gets the text LED brightness value.
237  *
238  * @return _TextBrightness Indicates brightness value for text LED.
239  */
241 {
242  dsFPDBrightness_t brightness;
244  if (ret != dsERR_NONE) {
245  throw Exception(ret);
246  }
247  else
248  {
249  _TextBrightness = brightness;
250  }
251  return _TextBrightness;
252 }
253 
254 
255 /**
256  * @fn FrontPanelTextDisplay::getTextBrightnessLevels(int &levels, int &min, int &max)
257  * @brief This function is used to get maximum brightness, minimum brightness and brightness level
258  * of the front panel LED display.
259  * <ul>
260  * <li> Note:
261  * <li> Brightness level - Indicates the step value at which the brightness could be changed.
262  * <ul/>
263  *
264  * @param[out] max Indicates maximum brightness for the front panel text display.
265  * @param[out] min Indicates minimum brightness for the front panel text display.
266  * @param[out] levels Indicates brightness level of the front panel text display.
267  *
268  * @return None
269  */
270 void FrontPanelTextDisplay::getTextBrightnessLevels(int &levels, int &min, int &max)
271 {
272  max = _maxBrightness;
273  levels = _levels;
274  min = 0;
275 }
276 
277 
278 /**
279  * @fn FrontPanelTextDisplay::getTextColorMode()
280  * @brief This function is used to get the color mode of the front panel text display.
281  *
282  * @return _colorMode Color mode of the front panel text display is returned.
283  */
285 {
286  return _colorMode;
287 }
288 
289 
290 /**
291  * @fn FrontPanelTextDisplay::setScroll(const Scroll & scroll)
292  * @brief This API sets the scroll parameters for text LED display
293  * like hold duration, vertical iterations and horizontal iterations.
294  *
295  * @param[in] scroll Contains scroll parameters to be set.
296  *
297  * @return None
298  */
300 {
302  if (ret != dsERR_NONE) {
303  throw Exception(ret);
304  }
305  else
306  {
307  _scroll = scroll;
308  }
309 }
310 
311 
312 /**
313  * @fn int FrontPanelTextDisplay::getCurrentTimeFormat()
314  * @brief This API Get the time format of the LED display
315  *
316  * @param[in] none
317  * @return Current Persisted /Set Time Zone format
318  */
319 
321 {
322  dsFPDTimeFormat_t timeFormat;
323  dsError_t ret = dsGetFPTimeFormat(&timeFormat);
324  if (ret != dsERR_NONE) {
325  throw Exception(ret);
326  }
327  else
328  {
329  _timeFormat = timeFormat;
330  }
331  return timeFormat;
332 };
333 
334 /**
335  * @fn FrontPanelTextDisplay::setTimeFormat(const int iTimeFormat)
336  * @brief This API sets the time format of the LED display to either 12hr or 24hr format.
337  *
338  * @param[in] iTimeFormat Indicates time format.
339  * <ul>
340  * <li> Zero indicates 12hr format.
341  * <li> 1 indicates 24hr format.
342  * </ul>
343  *
344  * @return None
345  */
346 void FrontPanelTextDisplay::setTimeFormat(const int iTimeFormat)
347 {
348 
349  if ((iTimeFormat == kModeClock24Hr) || (iTimeFormat == kModeClock12Hr))
350  {
351 
352  dsError_t ret = dsSetFPTimeFormat((dsFPDTimeFormat_t)iTimeFormat);
353  if (ret != dsERR_NONE) {
354  throw Exception(ret);
355  }
356  else
357  {
358  _timeFormat = iTimeFormat;
359  }
360  }
361  else
362  {
363  throw IllegalArgumentException();
364  }
365 }
366 
367 
368 /**
369  * @fn FrontPanelTextDisplay::setTime(const int uiHours, const int uiMinutes)
370  * @brief This API sets the time of the LED display by switching the text display to time mode.
371  *
372  * @param[in] uiHours Indicates hour parameter in time.
373  * @param[in] uiMinutes Indicates minutes parameter in time.
374  *
375  * @return None
376  */
377 void FrontPanelTextDisplay::setTime(const int uiHours, const int uiMinutes)
378 {
379  if ((uiHours < 0 ) || (uiHours > 23) || (uiMinutes < 0) || (uiMinutes > 59)) {
380  throw IllegalArgumentException();
381  }
382 
383  dsError_t ret = dsSetFPTime ((dsFPDTimeFormat_t)_timeFormat, uiHours, uiMinutes);
384  if (ret != dsERR_NONE) {
385  throw Exception(ret);
386  }
387 }
388 
389 /**
390  * @fn FrontPanelTextDisplay:setMode(int mode)
391  * @brief This API sets the display mode of the LED display to any, text only or clock only.
392  *
393  * @param[in] mode Indicates display mode.
394  * <ul>
395  * <li> 0 indicates both text and clock are supported (default mode).
396  * <li> 1 indicates only text mode is supported (trying to set clock results in no change).
397  * <li> 2 indicates only clock mode is supported (trying to set text results in no change).
398  * </ul>
399  *
400  * @return None
401  */
403 {
404  if ((mode == 0) || (mode == 1) || (mode == 2)) {
405  dsError_t ret = dsSetFPDMode ((dsFPDMode_t)mode);
406  if (ret != dsERR_NONE) {
407  throw Exception(ret);
408  }
409  }
410  else
411  {
412  throw IllegalArgumentException();
413  }
414 }
415 
416 
417 }
418 
419 /** @} */
420 
421 /** @} */
422 /** @} */
device::DSConstant::_id
int _id
Indicates the id of the instance inheriting this class.
Definition: dsConstant.hpp:57
device::FrontPanelTextDisplay::setTextBrightness
void setTextBrightness(const int &brightness)
This API sets the brightness value for the front panel LED.
Definition: frontPanelTextDisplay.cpp:221
device::FrontPanelTextDisplay::enableDisplay
void enableDisplay(const int enable)
This function is used to enable or disable the display of clock on front panel.
Definition: frontPanelTextDisplay.cpp:204
dsFPEnableCLockDisplay
dsError_t dsFPEnableCLockDisplay(int enable)
Use disable and enable display of clock.
Definition: dsFPD.c:390
device::FrontPanelIndicator::_maxBrightness
int _maxBrightness
Indicates maximum brightness value for the FP indicators.
Definition: frontPanelIndicator.hpp:132
dsSetFPDMode
dsError_t dsSetFPDMode(dsFPDMode_t eMode)
This function sets the display mode of the FPD text display.
Definition: dsFPD.c:504
dsSetFPText
dsError_t dsSetFPText(const char *pText)
Set text on 7-Segment Display.
Definition: dsFPD.c:80
device::FrontPanelTextDisplay::getTextColorMode
int getTextColorMode()
This function is used to get the color mode of the front panel text display.
Definition: frontPanelTextDisplay.cpp:284
dsSetFPTime
dsError_t dsSetFPTime(dsFPDTimeFormat_t eTimeFormat, const unsigned int uHour, const unsigned int uMinutes)
Set time on 7-Segment Display.
Definition: dsFPD.c:110
frontPanelTextDisplay.hpp
Classes and structures for front panel text display are defined here.
dsTypes.h
Device Settings HAL types.
Scroll
To manage front panel text display scrolling.
device::FrontPanelTextDisplay::Scroll::getVerticalIteration
int getVerticalIteration() const
This API gets the vertical iterations for front panel text display scrolling.
Definition: frontPanelTextDisplay.hpp:106
device::FrontPanelTextDisplay::Scroll
Definition: frontPanelTextDisplay.hpp:74
dsGetFPTimeFormat
dsError_t dsGetFPTimeFormat(dsFPDTimeFormat_t *pTimeFormat)
This function get the Current time zone format set on 7-segment display LEDs panel.
Definition: dsFPD.c:435
device::FrontPanelTextDisplay::Scroll::getHorizontalIteration
int getHorizontalIteration() const
This API gets the horizontal iterations for front panel text display scrolling.
Definition: frontPanelTextDisplay.hpp:115
dsFPDTimeFormat_t
enum __dsFPDTimeFormat_t dsFPDTimeFormat_t
dsFPDBrightness_t
uint32_t dsFPDBrightness_t
Definition: dsTypes.h:862
dsSetFPTextBrightness
dsError_t dsSetFPTextBrightness(dsFPDTextDisplay_t eIndicator, dsFPDBrightness_t eBrightness)
Set brightness level of 7-Segment Display.
Definition: dsFPD.c:295
device::DSConstant::isValid
static bool isValid(int min, int max, int val)
This function checks if the given value lies between min and max values provided.
Definition: dsConstant.hpp:72
dsError.h
Device Settings HAL error codes.
device::FrontPanelTextDisplay::setTime
void setTime(const int uiHours, const int uiMinutes)
This API sets the time of the LED display by switching the text display to time mode.
Definition: frontPanelTextDisplay.cpp:377
device::FrontPanelTextDisplay::_TextBrightness
int _TextBrightness
Indicates text brightness.
Definition: frontPanelTextDisplay.hpp:130
device::FrontPanelTextDisplay::kModeClock24Hr
static const int kModeClock24Hr
Indicates 24 hour time format.
Definition: frontPanelTextDisplay.hpp:135
device::DSConstant::enable
void enable()
This function is used to indicate that the port or port attribute calling this function are enabled.
Definition: dsConstant.hpp:164
dsERR_NONE
@ dsERR_NONE
Definition: dsError.h:85
dsFPDTextDisplay_t
enum __dsFPDTextDisplay_t dsFPDTextDisplay_t
device::FrontPanelTextDisplay::setScroll
void setScroll(const Scroll &scroll)
This API sets the scroll parameters for text LED display like hold duration, vertical iterations and ...
Definition: frontPanelTextDisplay.cpp:299
device::FrontPanelTextDisplay::_scroll
Scroll _scroll
Indicates scroll properties.
Definition: frontPanelTextDisplay.hpp:128
frontPanelConfig.hpp
Structures and classes to manage front panel are defined here.
dsGetFPTextBrightness
dsError_t dsGetFPTextBrightness(dsFPDTextDisplay_t eIndicator, dsFPDBrightness_t *eBrightness)
Get the brightness of 7-Segment Display LEDs.
Definition: dsFPD.c:270
dsFPD_TIME_24_HOUR
@ dsFPD_TIME_24_HOUR
Definition: dsTypes.h:848
device::DSConstant::_name
std::string _name
Indicates the name string of the instance inheriting this class.
Definition: dsConstant.hpp:58
device::FrontPanelTextDisplay::Scroll::getHoldDuration
int getHoldDuration() const
This API gets the hold duration for front panel text display scrolling.
Definition: frontPanelTextDisplay.hpp:124
device::FrontPanelTextDisplay::setText
void setText(const std::string &text)
This API sets the text LED display, by switching the text display to text mode.
Definition: frontPanelTextDisplay.cpp:187
dsFPD_TIME_12_HOUR
@ dsFPD_TIME_12_HOUR
Definition: dsTypes.h:847
device::FrontPanelTextDisplay::setMode
void setMode(int mode)
This API sets the display mode of the LED display to any, text only or clock only.
Definition: frontPanelTextDisplay.cpp:402
device::FrontPanelTextDisplay::setTimeFormat
void setTimeFormat(const int iTimeFormat)
This API sets the time format of the LED display to either 12hr or 24hr format.
Definition: frontPanelTextDisplay.cpp:332
device::FrontPanelIndicator::_levels
int _levels
Indicates the brightness level.
Definition: frontPanelIndicator.hpp:135
device::Exception
This class handles exceptions occurring in DS module.
Definition: exception.hpp:52
device::FrontPanelTextDisplay::kModeClock12Hr
static const int kModeClock12Hr
Indicates 12 hour time format.
Definition: frontPanelTextDisplay.hpp:134
dsSetFPScroll
dsError_t dsSetFPScroll(unsigned int uScrollHoldOnDur, unsigned int uHorzScrollIterations, unsigned int uVertScrollIterations)
Scroll text on 7-Segment Display.
Definition: dsFPD.c:135
device::FrontPanelTextDisplay::getCurrentTimeFormat
int getCurrentTimeFormat()
This API Get the time format of the LED display.
Definition: frontPanelTextDisplay.cpp:320
device::FrontPanelTextDisplay
This class extents FrontPanelIndicator to manage front panel text display mode, scrolling and its bri...
Definition: frontPanelTextDisplay.hpp:53
dsFPD_TIME_STRING
@ dsFPD_TIME_STRING
Definition: dsTypes.h:849
dsFPDMode_t
enum __dsFPDMode_t dsFPDMode_t
device::FrontPanelIndicator::_colorMode
int _colorMode
Indicates the color mode of the LED indicator (single or multicolor mode).
Definition: frontPanelIndicator.hpp:136
device::IllegalArgumentException
This class extends Exception class to manage the expections caused due to illegal arguments.
Definition: illegalArgumentException.hpp:51
dsFPDTextDisplay_isValid
#define dsFPDTextDisplay_isValid(t)
Definition: dsTypes.h:812
device::FrontPanelTextDisplay::getTextBrightness
int getTextBrightness()
This API gets the text LED brightness value.
Definition: frontPanelTextDisplay.cpp:240
dsUTL_DIM
#define dsUTL_DIM(arr)
Device Settings general Array dimension calculation inline definition.
Definition: dsUtl.h:85
dsSetFPTimeFormat
dsError_t dsSetFPTimeFormat(dsFPDTimeFormat_t eTimeFormat)
This function sets the 7-segment display LEDs to show the specified time in specified format.
Definition: dsFPD.c:458
device::FrontPanelTextDisplay::getTextBrightnessLevels
void getTextBrightnessLevels(int &levels, int &min, int &max)
This function is used to get maximum brightness, minimum brightness and brightness level of the front...
Definition: frontPanelTextDisplay.cpp:270
dsError_t
dsError_t
Device Settings API Error return codes.
Definition: dsError.h:84
device::FrontPanelTextDisplay::_timeFormat
int _timeFormat
Indicates time format for the clock display.
Definition: frontPanelTextDisplay.hpp:129