Files
espurna/code/espurna/led.h
Max Prokhorov edb23dbfc4 Convert .ino -> .cpp (#2228)
- general conversion from .ino modules into a separate .cpp files
- clean-up internal headers, place libraries into .h. guard .cpp with _SUPPORT flags 
- fix some instances of shared variables instead of public methods
- tweak build system to still build a single source file via os environment variable ESPURNA_BUILD_SINGLE_SOURCE
2020-04-30 13:55:07 +03:00

84 lines
1.5 KiB
C++

/*
LED MODULE
Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
*/
#pragma once
#include "espurna.h"
#include <vector>
#include <memory>
constexpr size_t LedsMax = 8;
enum class LedMode {
NetworkAutoconfig,
NetworkConnected,
NetworkConnectedInverse,
NetworkConfig,
NetworkConfigInverse,
NetworkIdle,
None
};
enum class led_delay_mode_t {
Finite,
Infinite,
None
};
struct led_delay_t {
led_delay_t() = delete;
led_delay_t(unsigned long on_ms, unsigned long off_ms);
led_delay_t(unsigned long on_ms, unsigned long off_ms, unsigned char repeats);
led_delay_mode_t type;
unsigned long on;
unsigned long off;
unsigned char repeats;
};
struct led_pattern_t {
led_pattern_t() = default;
led_pattern_t(const std::vector<led_delay_t>& delays);
void start();
void stop();
bool started();
bool ready();
std::vector<led_delay_t> delays;
std::vector<led_delay_t> queue;
unsigned long clock_last;
unsigned long clock_delay;
};
struct led_t {
led_t() = delete;
led_t(unsigned char pin, bool inverse, unsigned char mode, unsigned char relayID);
bool status();
bool status(bool new_status);
bool toggle();
unsigned char pin;
bool inverse;
unsigned char mode;
unsigned char relayID;
led_pattern_t pattern;
};
void ledUpdate(bool do_update);
unsigned char ledCount();
bool ledStatus(unsigned char id, bool status);
bool ledStatus(unsigned char id);
void ledSetup();