Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format fixes in light module #1874

Merged
merged 5 commits into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions code/espurna/config/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -1112,15 +1112,18 @@
#define LIGHT_SAVE_DELAY 5 // Persist color after 5 seconds to avoid wearing out
#endif

#ifndef LIGHT_MIN_PWM
#define LIGHT_MIN_PWM 0
#endif

#ifndef LIGHT_MAX_PWM

#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX
#define LIGHT_MAX_PWM 255
#endif

#if LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER
#elif LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER
#define LIGHT_MAX_PWM 10000 // 10000 * 200ns => 2 kHz
#else
#define LIGHT_MAX_PWM 0
#endif

#endif // LIGHT_MAX_PWM
Expand All @@ -1129,14 +1132,25 @@
#define LIGHT_LIMIT_PWM LIGHT_MAX_PWM // Limit PWM to this value (prevent 100% power)
#endif

#ifndef LIGHT_MIN_VALUE
#define LIGHT_MIN_VALUE 0 // Minimum light value
#endif

#ifndef LIGHT_MAX_VALUE
#define LIGHT_MAX_VALUE 255 // Maximum light value
#endif

#ifndef LIGHT_MIN_BRIGHTNESS
#define LIGHT_MIN_BRIGHTNESS 0 // Minimum brightness value
#endif

#ifndef LIGHT_MAX_BRIGHTNESS
#define LIGHT_MAX_BRIGHTNESS 255 // Maximun brightness value
#define LIGHT_MAX_BRIGHTNESS 255 // Maximum brightness value
#endif

#define LIGHT_MIN_KELVIN 1000
#define LIGHT_MAX_KELVIN 40000

#define LIGHT_MIN_MIREDS 153 // Default to the Philips Hue value that HA also use.
#define LIGHT_MAX_MIREDS 500 // https://developers.meethue.com/documentation/core-concepts

Expand Down
11 changes: 11 additions & 0 deletions code/espurna/config/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,17 @@ using thermostat_callback_f = std::function<void(bool)>;
// -----------------------------------------------------------------------------
#include "rtcmem.h"

// -----------------------------------------------------------------------------
// Warn about broken Arduino functions
// -----------------------------------------------------------------------------

// Division by zero bug
// https://github.com/esp8266/Arduino/pull/2397
// https://github.com/esp8266/Arduino/pull/2408
#if defined(ARDUINO_ESP8266_RELEASE_2_3_0)
long __attribute__((deprecated("Please avoid using map() with Core 2.3.0"))) map(long x, long in_min, long in_max, long out_min, long out_max);
#endif

// -----------------------------------------------------------------------------
// std::make_unique backport for C++11
// -----------------------------------------------------------------------------
Expand Down
6 changes: 4 additions & 2 deletions code/espurna/domoticz.ino
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ void _domoticzStatus(unsigned char id, bool status) {

#if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE

#include "light.h"

void _domoticzLight(unsigned int idx, const JsonObject& root) {

if (!lightHasColor()) return;
Expand All @@ -74,8 +76,8 @@ void _domoticzLight(unsigned int idx, const JsonObject& root) {
lightChannel(4, color["cw"]);
}

// domoticz uses 100 as maximum value while we're using LIGHT_MAX_BRIGHTNESS
unsigned int brightness = (root["Level"].as<uint8_t>() / 100.0) * LIGHT_MAX_BRIGHTNESS;
// domoticz uses 100 as maximum value while we're using Light::BRIGHTNESS_MAX (unsigned char)
unsigned char brightness = (root["Level"].as<uint8_t>() / 100.0) * Light::BRIGHTNESS_MAX;
lightBrightness(brightness);

DEBUG_MSG_P(PSTR("[DOMOTICZ] Received rgb:%u,%u,%u ww:%u,cw:%u brightness:%u for IDX %u\n"),
Expand Down
26 changes: 26 additions & 0 deletions code/espurna/light.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// -----------------------------------------------------------------------------
// Light
// -----------------------------------------------------------------------------

#pragma once

namespace Light {
constexpr const unsigned char VALUE_MIN = LIGHT_MIN_VALUE;
constexpr const unsigned char VALUE_MAX = LIGHT_MAX_VALUE;

constexpr const unsigned int BRIGHTNESS_MIN = LIGHT_MIN_BRIGHTNESS;
constexpr const unsigned int BRIGHTNESS_MAX = LIGHT_MAX_BRIGHTNESS;

// Default to the Philips Hue value that HA also use.
// https://developers.meethue.com/documentation/core-concepts
constexpr const unsigned int MIREDS_MIN = LIGHT_MIN_MIREDS;
constexpr const unsigned int MIREDS_MAX = LIGHT_MAX_MIREDS;

constexpr const unsigned int KELVIN_MIN = LIGHT_MIN_KELVIN;
constexpr const unsigned int KELVIN_MAX = LIGHT_MAX_KELVIN;

constexpr const unsigned int PWM_MIN = LIGHT_MIN_PWM;
constexpr const unsigned int PWM_MAX = LIGHT_MAX_PWM;
constexpr const unsigned int PWM_LIMIT = LIGHT_LIMIT_PWM;
}

Loading