#include #include #include #ifdef __cplusplus extern "C" { #endif struct event; /* * Now include all events, which are basically states */ #define DEFINE_EVENT_STATE(_name, ...) \ enum _name##_values{ \ _name##_unknown = 0, \ __VA_ARGS__ _name##_invalid, \ }; \ extern struct event __event_##_name; \ static struct event *const _name = &__event_##_name; #define DEFINE_EVENT(_name, ...) _name, #define DEFINE_EVENT_RAW(_name, ...) \ extern struct event __event_##_name; \ static struct event *const _name = &__event_##_name; #include enum blink { blink_off = 0, blink_on = 1, blink_0_5HZ = 2, blink_1HZ = 3, blink_2HZ = 4, blink_4HZ = 5, blink_hardware_error = 6, blink_2HZ_double = 7, blink_off_on = 8, BLINK_CODE_MAX, blink_invalid = 0xFF, }; struct led_color { uint8_t brightness; union { struct { uint8_t red; uint8_t green; uint8_t blue; }; uint8_t c[3]; }; }; struct blink_code { uint8_t type; uint8_t params[2]; struct led_color color; }; struct led; typedef struct blink_code (*led_overlay_t)(struct led *); // There are predefined colors for used to denote some meanings. The value here // is the index into the color array // // By default these are white (0xFFFFFF) and can be set via dt or // sysfs. // // Note that depending on the platform only some components are present // and they not necessarily are RGB. enum led_color_name { #define COLOR(name) led_color_name_##name, #include "../def/colors.h" LED_NUM_COLOR_NAMES }; #define LED_FLAG_BARE_UPDATE (1 << 1) #define CONNECT_METHODE(x) (1 << (x & 0x7)) #define CONNECT_METHODE_ALL 0xFF struct led_options { // Which connect methods are serviced by this led // used by overlay_connect uint8_t connect_methods; // Which physical location has this led // Is used by rssi and vu overlays // // 0 -> no location uint8_t location; uint32_t flags; }; struct led_type { const char *name; struct led_options options; led_overlay_t *overlays; }; struct led { struct led_color current_color; struct led_options options; }; int _event_get_value(const char *file, int line, const char *func, struct event *event); int _leds_max_location(const char *file, int line, const char *func); void _led_set_current_color(struct led *led, enum led_color_name name); struct event_member_def { const char *name; int event_id; struct { int ms; int next; } timeout; }; struct event { const char *name; int max_state; const struct event_member_def *def; // int raw_event_id; }; extern struct led_type led_types[]; extern unsigned int num_led_types; extern struct event *events_list[]; #ifdef __cplusplus } #endif #ifdef __cplusplus #include #include #include #include #include class EventState { public: int get(const struct event *event) const; void set(struct event *event, int val = 1); void set(const std::string &name, int val = 1); void set_from_line(const std::string &line); private: std::map state; }; struct LEDState { struct blink_code code; std::string overlay_name; std::string str() { std::stringstream s; s << int(code.type) << " (" << int(code.params[0]) << ", " << int(code.params[1]) << ", #"; s << std::hex << std::uppercase << std::setfill('0') << std::setw(2) << int(code.color.c[0]); s << std::hex << std::uppercase << std::setfill('0') << std::setw(2) << int(code.color.c[1]); s << std::hex << std::uppercase << std::setfill('0') << std::setw(2) << int(code.color.c[2]); s << ") by " << this->overlay_name << " [hui]"; return s.str(); } bool operator==(const LEDState &other) const { int i; if (this->code.type != other.code.type) return false; for (i = 0; i < 2; i++) if (this->code.params[i] != other.code.params[i]) return false; for (i = 0; i < 3; i++) if (this->code.color.c[i] != other.code.color.c[i]) return false; return this->overlay_name == other.overlay_name; } bool operator!=(const LEDState &other) const { return !this->operator==(other); } }; class LED { public: LED(const std::string &type); LEDState evaluate(const EventState &eventState); int _event_get_value(const char *file, int line, const char *func, struct event *event); int _leds_max_location(const char *file, int line, const char *func); void _led_set_current_color(struct led *led, enum led_color_name name); private: struct led_type *def; struct led led; const EventState *eventState; }; std::vector all_led_types(); #endif