blob: afc3529ec716f697d00a8541045bb851e819f8ae [file] [log] [blame]
Tomáš Peckaddf04a32020-06-17 15:32:01 +02001/*
2 * Copyright (C) 2020 CESNET, https://photonics.cesnet.cz/
3 *
4 * Written by Tomáš Pecka <tomas.pecka@fit.cvut.cz>
5 *
6*/
7
8#include "callables.h"
Tomáš Pecka261c8862020-11-05 11:23:08 +01009#include "health/outputs/LedSysfsDriver.h"
Tomáš Peckaddf04a32020-06-17 15:32:01 +020010
Tomáš Pecka261c8862020-11-05 11:23:08 +010011namespace velia::health {
Tomáš Peckaddf04a32020-06-17 15:32:01 +020012
13LedOutputCallback::LedOutputCallback(std::shared_ptr<LedSysfsDriver> red, std::shared_ptr<LedSysfsDriver> green, std::shared_ptr<LedSysfsDriver> blue)
14 : m_redLed(std::move(red))
15 , m_greenLed(std::move(green))
16 , m_blueLed(std::move(blue))
17{
Tomáš Pecka7ff533b2020-07-17 15:01:16 +020018 reset();
19}
20
21LedOutputCallback::~LedOutputCallback()
22{
23 reset();
24}
25
26void LedOutputCallback::reset()
27{
Tomáš Peckaddf04a32020-06-17 15:32:01 +020028 m_redLed->set(0);
29 m_greenLed->set(0);
30 m_blueLed->set(0);
31}
32
33void LedOutputCallback::operator()(State state)
34{
35 switch (state) {
36 case State::ERROR:
37 m_redLed->set(255);
38 m_greenLed->set(0);
39 m_blueLed->set(0);
40 break;
41 case State::WARNING:
42 m_redLed->set(255);
43 m_greenLed->set(160);
44 m_blueLed->set(0);
45 break;
46 case State::OK:
47 m_redLed->set(0);
48 m_greenLed->set(255);
49 m_blueLed->set(0);
50 break;
51 }
52}
Tomáš Pecka261c8862020-11-05 11:23:08 +010053}