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

Change min max esp8266 #364

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 7 additions & 6 deletions examples/esp8266_webinterface/esp8266_webinterface.ino
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
2018-01-06 added custom effects list option and auto-cycle feature

*/


// needed for std::max and std::min
#include <algorithm>

#ifdef ARDUINO_ARCH_ESP32
#include <WiFi.h>
#include <WebServer.h>
Expand Down Expand Up @@ -66,10 +71,6 @@ extern const char main_js[];
IPAddress subnet(255,255,255,0);
#endif

// QUICKFIX...See https://github.com/esp8266/Arduino/issues/263
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))

#define LED_PIN 2 // 0 = GPIO0, 2=GPIO2
#define LED_COUNT 24

Expand Down Expand Up @@ -243,7 +244,7 @@ void srv_handle_set() {
if(server.arg(i)[0] == '-') {
ws2812fx.setBrightness(ws2812fx.getBrightness() * 0.8);
} else if(server.arg(i)[0] == ' ') {
ws2812fx.setBrightness(min(max(ws2812fx.getBrightness(), 5) * 1.2, 255));
ws2812fx.setBrightness(std::min(std::max(ws2812fx.getBrightness(), 5) * 1.2, 255));
} else { // set brightness directly
uint8_t tmp = (uint8_t) strtol(server.arg(i).c_str(), NULL, 10);
ws2812fx.setBrightness(tmp);
Expand All @@ -253,7 +254,7 @@ void srv_handle_set() {

if(server.argName(i) == "s") {
if(server.arg(i)[0] == '-') {
ws2812fx.setSpeed(max(ws2812fx.getSpeed(), 5) * 1.2);
ws2812fx.setSpeed(std::max(ws2812fx.getSpeed(), 5) * 1.2);
} else if(server.arg(i)[0] == ' ') {
ws2812fx.setSpeed(ws2812fx.getSpeed() * 0.8);
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/WS2812FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ bool WS2812FX::service() {
SET_FRAME;
doShow = true;
uint16_t delay = (MODE_PTR(_seg->mode))();
_seg_rt->next_time = now + max(delay, SPEED_MIN);
_seg_rt->next_time = now + std::max(delay, SPEED_MIN);
_seg_rt->counter_mode_call++;
}
}
Expand Down Expand Up @@ -585,7 +585,7 @@ uint32_t WS2812FX::color_wheel(uint8_t pos) {
}

/*
* Returns a new, random wheel index with a minimum distance of 42 from pos.
* Returns a new, random wheel index with a histimum distance of 42 from pos.
*/
uint8_t WS2812FX::get_random_wheel_index(uint8_t pos) {
uint8_t r = 0;
Expand All @@ -597,7 +597,7 @@ uint8_t WS2812FX::get_random_wheel_index(uint8_t pos) {
r = random8();
x = abs(pos - r);
y = 255 - x;
d = min(x, y);
d = std::min(x, y);
}

return r;
Expand Down
9 changes: 2 additions & 7 deletions src/WS2812FX.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,8 @@
#include <Adafruit_NeoPixel.h>
#endif

// include max macro for ESP boards
#ifndef max
#define max(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })
#endif
// needed for std::max
#include <algorithm>

#define DEFAULT_BRIGHTNESS (uint8_t)50
#define DEFAULT_MODE (uint8_t)0
Expand Down
4 changes: 2 additions & 2 deletions src/modes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ uint16_t WS2812FX::mode_theater_chase_rainbow(void) {
*/
uint16_t WS2812FX::mode_running_lights(void) {
uint8_t size = 1 << SIZE_OPTION;
uint8_t sineIncr = max((uint8_t)1, (256 / _seg_len) * size);
uint8_t sineIncr = std::max((uint8_t)1, (uint8_t)((256 / _seg_len) * size));
for(uint16_t i=0; i < _seg_len; i++) {
int lum = (int)sine8(((i + _seg_rt->counter_mode_step) * sineIncr));
uint32_t color = color_blend(_seg->colors[0], _seg->colors[1], lum);
Expand Down Expand Up @@ -865,7 +865,7 @@ uint16_t WS2812FX::mode_rainbow_fireworks(void) {

// occasionally create a random red pixel
if(random8(4) == 0) {
uint16_t index = _seg->start + 6 + random16(max((uint8_t)1, _seg_len - 12));
uint16_t index = _seg->start + 6 + random16(std::max((uint8_t)1, (uint8_t)(_seg_len - 12)));
setRawPixelColor(index, RED); // set the raw pixel color (ignore global brightness)
SET_CYCLE;
}
Expand Down
8 changes: 4 additions & 4 deletions src/modes_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,15 @@ uint16_t WS2812FX::fireworks(uint32_t color) {

uint8_t size = 2 << SIZE_OPTION;
if(!_triggered) {
for(uint16_t i=0; i<max((uint8_t)1, _seg_len/20); i++) {
for(uint16_t i=0; i<std::max((uint8_t)1, (uint8_t)(_seg_len/20)); i++) {
if(random8(10) == 0) {
uint16_t index = _seg->start + random16(_seg_len - size + 1);
fill(color, index, size);
SET_CYCLE;
}
}
} else {
for(uint16_t i=0; i<max((uint8_t)1, _seg_len/10); i++) {
for(uint16_t i=0; i<std::max((uint8_t)1, (uint8_t)(_seg_len/10)); i++) {
uint16_t index = _seg->start + random16(_seg_len - size + 1);
fill(color, index, size);
SET_CYCLE;
Expand All @@ -412,10 +412,10 @@ uint16_t WS2812FX::fire_flicker(int rev_intensity) {
byte r = (_seg->colors[0] >> 16) & 0xFF;
byte g = (_seg->colors[0] >> 8) & 0xFF;
byte b = (_seg->colors[0] & 0xFF);
byte lum = max(w, max(r, max(g, b))) / rev_intensity;
byte lum = std::max(w, std::max(r, std::max(g, b))) / rev_intensity;
for(uint16_t i=_seg->start; i <= _seg->stop; i++) {
int flicker = random8(lum);
setPixelColor(i, max(r - flicker, 0), max(g - flicker, 0), max(b - flicker, 0), max(w - flicker, 0));
setPixelColor(i, std::max(r - flicker, 0), std::max(g - flicker, 0), std::max(b - flicker, 0), std::max(w - flicker, 0));
}

SET_CYCLE;
Expand Down