Tomáš Pecka | ddf04a3 | 2020-06-17 15:32:01 +0200 | [diff] [blame] | 1 | /* |
| 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" |
| 9 | #include "outputs/LedSysfsDriver.h" |
| 10 | |
| 11 | namespace velia { |
| 12 | |
| 13 | LedOutputCallback::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áš Pecka | 7ff533b | 2020-07-17 15:01:16 +0200 | [diff] [blame^] | 18 | reset(); |
| 19 | } |
| 20 | |
| 21 | LedOutputCallback::~LedOutputCallback() |
| 22 | { |
| 23 | reset(); |
| 24 | } |
| 25 | |
| 26 | void LedOutputCallback::reset() |
| 27 | { |
Tomáš Pecka | ddf04a3 | 2020-06-17 15:32:01 +0200 | [diff] [blame] | 28 | m_redLed->set(0); |
| 29 | m_greenLed->set(0); |
| 30 | m_blueLed->set(0); |
| 31 | } |
| 32 | |
| 33 | void 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 | } |
| 53 | } |