cViewSwitch.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //////////////////////////////////////////////////////////////////////////////////////
  2. //////////////////////////////////////////
  3. /////////////////
  4. //
  5. // Global Include Files
  6. //
  7. //
  8. //
  9. //////////////////////////////////////////////////////////////////////////////////////
  10. //////////////////////////////////////////
  11. /////////////////
  12. //
  13. // Include Files from local modules
  14. //
  15. //
  16. #include "cViewSwitch.h"
  17. #include "views/cViewHdl.h"
  18. //////////////////////////////////////////////////////////////////////////////////////
  19. //////////////////////////////////////////
  20. /////////////////
  21. //
  22. // Class instanciation, external declarations and defines
  23. //
  24. //
  25. void cSwitchView::addView(cViewHdl* vw) {
  26. m_view.push_back(vw);
  27. };
  28. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  29. *
  30. */
  31. void cSwitchView::setView(const char * name) {
  32. for(std::vector<cViewHdl*>::size_type i = 0; i < m_view.size(); i++)
  33. {
  34. if (0 == strcmp(m_view[i]->getViewName(), name)) {
  35. // LOGMSG(INFO, m_view[i]->getViewName() ," at index position: ", i);
  36. m_viewNbr = (uint8_t) i; // Set View
  37. return;
  38. }
  39. }
  40. LOGMSG(INFO, "[ERROR] setView name not found ");
  41. };
  42. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  43. *
  44. */
  45. cViewHdl * cSwitchView::getView() {
  46. if (m_view.empty()) {
  47. LOGMSG(INFO,"[ERROR] getView vector is empty ", __FILE__, ":", __LINE__);
  48. return nullptr;
  49. }
  50. return m_view[m_viewNbr];
  51. };
  52. cViewHdl * cSwitchView::getView(uint8_t nb) {
  53. return m_view[nb];
  54. };
  55. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  56. *
  57. */
  58. cViewHdl * cSwitchView::getView(const char * name) {
  59. for (auto& _vw : m_view) {
  60. if (0 == strcmp(_vw->getViewName(), name)) {
  61. return _vw;
  62. }
  63. }
  64. LOGMSG(INFO, "[ERROR]: View not found");
  65. return nullptr;
  66. }
  67. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  68. *
  69. */
  70. void cSwitchView::run() {
  71. if (activeScreen != getView()) { // counterpart to setView (Name)
  72. activeScreen = getView();
  73. LOGMSG(INFO, "[INFO]: Active Screen: ", activeScreen->getViewName());
  74. activeScreen->init(); // initialize new view
  75. activeScreen->updateView(); // update view
  76. activeScreen->showConfiguration(); // show configuration of the view
  77. delay(600);
  78. }
  79. activeScreen->run(); // excute new view (Event Handler)
  80. }
  81. cSwitchView* cSwitchView::_Instance = nullptr;