You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
960B

  1. #if!defined LIGHTCONTROL_HPP
  2. #define LIGHTCONTROL_HPP
  3. #include <memory>
  4. class LightControl
  5. {
  6. public:
  7. class AState
  8. {
  9. public:
  10. virtual ~AState() = default;
  11. virtual float step() = 0;
  12. };
  13. class StateOff;
  14. class StateOn;
  15. class StateBlink;
  16. LightControl();
  17. void step();
  18. float lightValue()const;
  19. template <class T, class ... A>
  20. void setState(A&& ... args)
  21. {
  22. m_currentState.reset(new T(std::forward<A>(args)...));
  23. }
  24. private:
  25. std::unique_ptr<AState> m_currentState;
  26. float m_currentValue = 0.f;
  27. };
  28. class LightControl::StateOff : public LightControl::AState
  29. {
  30. public:
  31. float step() override;
  32. };
  33. class LightControl::StateOn : public LightControl::AState
  34. {
  35. public:
  36. float step() override;
  37. };
  38. class LightControl::StateBlink : public LightControl::AState
  39. {
  40. public:
  41. explicit StateBlink(float blinkTime, bool initialLightState = true);
  42. float step() override;
  43. private:
  44. float const m_blinkTime;
  45. float m_timeCounter;
  46. bool m_lightState;
  47. };
  48. #endif