|
@@ -77,7 +77,7 @@ uint8_t animate = 0;
|
|
uint8_t red = 1;
|
|
uint8_t red = 1;
|
|
uint8_t green = 1;
|
|
uint8_t green = 1;
|
|
uint8_t blue = 1;
|
|
uint8_t blue = 1;
|
|
-uint8_t brightness = 50;
|
|
|
|
|
|
+uint8_t brightness = 0x07;
|
|
|
|
|
|
#define DISABLE_FASTLED_CORRECTION 0
|
|
#define DISABLE_FASTLED_CORRECTION 0
|
|
#define ENABLE_FASTLED_CORRECTION 1
|
|
#define ENABLE_FASTLED_CORRECTION 1
|
|
@@ -125,7 +125,7 @@ static uint8_t bg100_sCurveGamma8[] = {
|
|
0xF9, 0xF9, 0xF9, 0xF9, 0xFA, 0xFA, 0xFA, 0xFA, 0xFA, 0xFB, 0xFB, 0xFB, 0xFB, 0xFB, 0xFB, 0xFC,
|
|
0xF9, 0xF9, 0xF9, 0xF9, 0xFA, 0xFA, 0xFA, 0xFA, 0xFA, 0xFB, 0xFB, 0xFB, 0xFB, 0xFB, 0xFB, 0xFC,
|
|
0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD,
|
|
0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD,
|
|
0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF
|
|
0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF
|
|
-}
|
|
|
|
|
|
+};
|
|
|
|
|
|
/* Fast-Led typical smd5050 led RGB color correction (0xFFB0F0 red 255, green 176, blue 240)
|
|
/* Fast-Led typical smd5050 led RGB color correction (0xFFB0F0 red 255, green 176, blue 240)
|
|
* measured brightness from typical LED vary by pn junction semiconductor material.
|
|
* measured brightness from typical LED vary by pn junction semiconductor material.
|
|
@@ -139,9 +139,9 @@ static uint8_t bg100_sCurveGamma8[] = {
|
|
* I believe that this color correction has to do with mechanical measurements as they are linear
|
|
* I believe that this color correction has to do with mechanical measurements as they are linear
|
|
* and I know that the human eye sensitivities are anything but. Otherwise this is very crude.
|
|
* and I know that the human eye sensitivities are anything but. Otherwise this is very crude.
|
|
*/
|
|
*/
|
|
-#define FASTLED_RED_CORRECTION = 0x00FF;
|
|
|
|
-#define FASTLED_GREEN_CORRECTION = 0x00B0;
|
|
|
|
-#define FASTLED_BLUE_CORRECTION = 0x00F0;
|
|
|
|
|
|
+#define FASTLED_RED_CORRECTION 0x00FF
|
|
|
|
+#define FASTLED_GREEN_CORRECTION 0x00B0
|
|
|
|
+#define FASTLED_BLUE_CORRECTION 0x00F0
|
|
|
|
|
|
uint8_t correctColor(uint8_t input, uint16_t factor) {
|
|
uint8_t correctColor(uint8_t input, uint16_t factor) {
|
|
uint16_t out;
|
|
uint16_t out;
|
|
@@ -158,19 +158,42 @@ uint8_t gammaCorrection(uint8_t input) {
|
|
switch(gammaCorrectionType) {
|
|
switch(gammaCorrectionType) {
|
|
case USE_PHILIP_GAMMA_CORRECTION: return phillip_adafruitGamma8[input];
|
|
case USE_PHILIP_GAMMA_CORRECTION: return phillip_adafruitGamma8[input];
|
|
case USE_BG100_S_CURVE_GAMMA_CORRECTION: return bg100_sCurveGamma8[input];
|
|
case USE_BG100_S_CURVE_GAMMA_CORRECTION: return bg100_sCurveGamma8[input];
|
|
- case DISABLE_GAMMA_CORRECTION:
|
|
|
|
- default:
|
|
|
|
|
|
+ case DISABLE_GAMMA_CORRECTION: ;
|
|
|
|
+ default: ;
|
|
}
|
|
}
|
|
return input;
|
|
return input;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
ESP8266WebServer server(80); // Create a webserver object that listens for HTTP request on port 80
|
|
ESP8266WebServer server(80); // Create a webserver object that listens for HTTP request on port 80
|
|
|
|
|
|
void handleRoot(); // function prototypes for HTTP handlers
|
|
void handleRoot(); // function prototypes for HTTP handlers
|
|
void handleLogin();
|
|
void handleLogin();
|
|
void handleNotFound();
|
|
void handleNotFound();
|
|
|
|
+void handleRGB();
|
|
|
|
+void handleGetDec();
|
|
|
|
+void handleEchoHex();
|
|
|
|
+void handleAnimate();
|
|
|
|
+void handleGetCfg();
|
|
|
|
+void handleCfg();
|
|
|
|
+void handleGetBrightness();
|
|
|
|
+void handleBrightness();
|
|
|
|
+
|
|
|
|
+// pwm.h - https://github.com/StefanBruens/ESP8266_new_pwm
|
|
|
|
+extern "C" void pwm_start();
|
|
|
|
+extern "C" void pwm_init(uint32_t period, uint32_t *duty, uint32_t pwm_channel_num, uint32_t (*pin_info_list)[3]);
|
|
|
|
+extern "C" void pwm_set_duty(uint32_t duty, uint8_t channel);
|
|
|
|
+
|
|
|
|
+/* esp8266 12-f breakout board has pins mapped a bit odd, and arduino esp8266 libs use GPIO pin number */
|
|
|
|
+#define PIN_5 14 /* GPIO_14 */
|
|
|
|
+#define PIN_6 12 /* GPIO_12 */
|
|
|
|
+#define PIN_7 13 /* GPIO_13 */
|
|
|
|
+#define PIN_LED 2 /* GPIO_2 active low */
|
|
|
|
+
|
|
|
|
+// new pwm
|
|
|
|
+#define PWM_RED 0
|
|
|
|
+#define PWM_GREEN 1
|
|
|
|
+#define PWM_BLUE 2
|
|
|
|
+#define PWM_LED 3
|
|
|
|
|
|
void setup(void){
|
|
void setup(void){
|
|
Serial.begin(115200); // Start the Serial communication to send messages to the computer
|
|
Serial.begin(115200); // Start the Serial communication to send messages to the computer
|
|
@@ -203,21 +226,17 @@ void setup(void){
|
|
server.on("/rgb", HTTP_POST, handleRGB); // Call the 'handleRGB' function when a POST request is made to URI "/login"
|
|
server.on("/rgb", HTTP_POST, handleRGB); // Call the 'handleRGB' function when a POST request is made to URI "/login"
|
|
server.on("/dec", HTTP_GET, handleGetDec);
|
|
server.on("/dec", HTTP_GET, handleGetDec);
|
|
server.on("/echo", HTTP_GET, handleEchoHex);
|
|
server.on("/echo", HTTP_GET, handleEchoHex);
|
|
- server.on("/animate", HTTP_GET, handleAnimate);
|
|
|
|
server.on("/cfg", HTTP_GET, handleGetCfg);
|
|
server.on("/cfg", HTTP_GET, handleGetCfg);
|
|
server.on("/cfg", HTTP_POST, handleCfg);
|
|
server.on("/cfg", HTTP_POST, handleCfg);
|
|
- server.on("/brightness", HTTP_POST, handleGetBrightness);
|
|
|
|
- server.on("/brightness", HTTP_POST, handleBrightness
|
|
|
|
|
|
+ server.on("/brightness", HTTP_GET, handleGetBrightness);
|
|
|
|
+ server.on("/brightness", HTTP_POST, handleBrightness);
|
|
|
|
+ //server.on("/animate", HTTP_GET, handleAnimate);
|
|
|
|
|
|
server.onNotFound(handleNotFound); // When a client requests an unknown URI (i.e. something other than "/"), call function "handleNotFound"
|
|
server.onNotFound(handleNotFound); // When a client requests an unknown URI (i.e. something other than "/"), call function "handleNotFound"
|
|
|
|
|
|
server.begin(); // Actually start the server
|
|
server.begin(); // Actually start the server
|
|
Serial.println("HTTP server started");
|
|
Serial.println("HTTP server started");
|
|
|
|
|
|
- /* esp8266 12-f breakout board has pins mapped a bit odd, and arduino esp8266 libs use GPIO pin number */
|
|
|
|
- #define PIN_5 14 /* GPIO_14 */
|
|
|
|
- #define PIN_6 12 /* GPIO_12 */
|
|
|
|
- #define PIN_7 13 /* GPIO_13 */
|
|
|
|
|
|
|
|
/* slowing the PWM frequency decreases the error caused by the power mosfets
|
|
/* slowing the PWM frequency decreases the error caused by the power mosfets
|
|
* having a slow turn-off
|
|
* having a slow turn-off
|
|
@@ -227,19 +246,39 @@ void setup(void){
|
|
* can tell.
|
|
* can tell.
|
|
*/
|
|
*/
|
|
//analogWriteFreq(1000);
|
|
//analogWriteFreq(1000);
|
|
- analogWriteFreq(250);
|
|
|
|
|
|
+ //analogWriteFreq(250);
|
|
|
|
|
|
- // lower brightness to minimal value
|
|
|
|
- brightness = 0;
|
|
|
|
- updateBrightness ();
|
|
|
|
|
|
+ // default range is 0..255
|
|
|
|
+ //analogWriteRange(1023);
|
|
|
|
|
|
|
|
+ // start code from StefanBruens/ESP8266_new_pwm
|
|
|
|
+ #define PWM_CHANNELS 4
|
|
|
|
+ const uint32_t period = 5000; // * 200ns ^= 1 kHz
|
|
|
|
+ uint32_t io_info[PWM_CHANNELS][3] = {
|
|
|
|
+ // MUX, FUNC, PIN
|
|
|
|
+ {PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12, PIN_6},
|
|
|
|
+ {PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13, PIN_7},
|
|
|
|
+ {PERIPHS_IO_MUX_MTMS_U, FUNC_GPIO14, PIN_5},
|
|
|
|
+ {PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2 , PIN_LED}
|
|
|
|
+ };
|
|
|
|
+ // initial duty: all at 1%
|
|
|
|
+ uint32_t pwm_duty_init[PWM_CHANNELS] = {50, 50, 50, 50};
|
|
|
|
+ pwm_init(period, pwm_duty_init, PWM_CHANNELS, io_info);
|
|
|
|
+ pwm_start();
|
|
|
|
+ pinMode(PIN_5, OUTPUT);
|
|
|
|
+ pinMode(PIN_6, OUTPUT);
|
|
|
|
+ pinMode(PIN_7, OUTPUT);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if(false) {
|
|
// turn on the onboard led for testing brightness
|
|
// turn on the onboard led for testing brightness
|
|
- analogWrite(/* esp12f onboard led */ 2, 255);
|
|
|
|
|
|
+ analogWrite(/* esp12f onboard led */ 2, 0);
|
|
|
|
|
|
// setup pins with a test pwm
|
|
// setup pins with a test pwm
|
|
analogWrite(PIN_5, red);
|
|
analogWrite(PIN_5, red);
|
|
analogWrite(PIN_6, green);
|
|
analogWrite(PIN_6, green);
|
|
analogWrite(PIN_7, blue);
|
|
analogWrite(PIN_7, blue);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
void loop(void){
|
|
void loop(void){
|
|
@@ -284,7 +323,7 @@ void loop(void){
|
|
* not something we want necessarily, but worth mentioning in case one questions
|
|
* not something we want necessarily, but worth mentioning in case one questions
|
|
* what the heck is happening
|
|
* what the heck is happening
|
|
*/
|
|
*/
|
|
- delay(1);
|
|
|
|
|
|
+ //delay(1);
|
|
|
|
|
|
if(delayCount++ < TEMPORAL_LENGTH) break;
|
|
if(delayCount++ < TEMPORAL_LENGTH) break;
|
|
// do we have any subframes to animate?
|
|
// do we have any subframes to animate?
|
|
@@ -297,7 +336,6 @@ void loop(void){
|
|
if(0 == frame) frame = (ANIMATE_BUFFER_LEN - 1) / 8;
|
|
if(0 == frame) frame = (ANIMATE_BUFFER_LEN - 1) / 8;
|
|
frame--;
|
|
frame--;
|
|
// get the next animation delay
|
|
// get the next animation delay
|
|
- frameAnimationDelay = animationDelayCounter =
|
|
|
|
// is this a stop frame
|
|
// is this a stop frame
|
|
if(0xff == frameAnimationDelay) { animate = 0; break; }
|
|
if(0xff == frameAnimationDelay) { animate = 0; break; }
|
|
// is this a loop frame
|
|
// is this a loop frame
|
|
@@ -315,7 +353,7 @@ void loop(void){
|
|
animationDelayCounter--;
|
|
animationDelayCounter--;
|
|
}
|
|
}
|
|
// set color
|
|
// set color
|
|
- setColor(redSubFrames[subframe -1], greeenSubFrames[subframe -1], blueSubFrames[subframe -1])
|
|
|
|
|
|
+ setColor(redSubFrames[subframe -1], greenSubFrames[subframe -1], blueSubFrames[subframe -1]);
|
|
// track progress through subframes
|
|
// track progress through subframes
|
|
subframe--;
|
|
subframe--;
|
|
}
|
|
}
|
|
@@ -343,9 +381,8 @@ void handleGetDec() {
|
|
}
|
|
}
|
|
|
|
|
|
void handleGetBrightness() {
|
|
void handleGetBrightness() {
|
|
- String info = "";
|
|
|
|
|
|
+ String info = String("");
|
|
server.send(200, "text/html", info + brightness + '\n');
|
|
server.send(200, "text/html", info + brightness + '\n');
|
|
- return;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/* we are going to cheat the brightness by adjusting pwm resolution
|
|
/* we are going to cheat the brightness by adjusting pwm resolution
|
|
@@ -366,16 +403,23 @@ void handleGetBrightness() {
|
|
* brightness they are driven at 60% duty 255/432.
|
|
* brightness they are driven at 60% duty 255/432.
|
|
*/
|
|
*/
|
|
void updateBrightness () {
|
|
void updateBrightness () {
|
|
- // default range is 0..255
|
|
|
|
- analogWriteRange(1023);
|
|
|
|
|
|
+ setColor(red, green, blue);
|
|
|
|
+ return;
|
|
// brightness is inverted, technically it is darkness
|
|
// brightness is inverted, technically it is darkness
|
|
uint8_t brightnessValue = 6 * (100 - brightness);
|
|
uint8_t brightnessValue = 6 * (100 - brightness);
|
|
// reducing PWM range will increase brightness
|
|
// reducing PWM range will increase brightness
|
|
- analogWriteRange(1023 - brightnessValue);
|
|
|
|
|
|
+ //analogWriteRange(1023 - brightnessValue);
|
|
|
|
+ // this works, but only gives 3 levels, 8,9,10
|
|
|
|
+ //if(false) analogWriteResolution(resolution++ % 2 ?10 :8);
|
|
|
|
+ //analogWriteFreq(250);
|
|
|
|
+ // all colors need to be re-written after adjusting brightness
|
|
|
|
+ //setColor(red, green, blue);
|
|
|
|
+ // turn on the onboard led for testing brightness
|
|
|
|
+ //analogWrite(/* esp12f onboard led */ 2, 100);
|
|
}
|
|
}
|
|
|
|
|
|
void handleBrightness() {
|
|
void handleBrightness() {
|
|
- char buffer[4];
|
|
|
|
|
|
+ uint8_t buffer[4];
|
|
if( ! server.hasArg("brightness")) {
|
|
if( ! server.hasArg("brightness")) {
|
|
server.send(400, "text/plain", "400: Invalid Request"); // The request is invalid, so send HTTP status 400
|
|
server.send(400, "text/plain", "400: Invalid Request"); // The request is invalid, so send HTTP status 400
|
|
return;
|
|
return;
|
|
@@ -383,16 +427,15 @@ void handleBrightness() {
|
|
// else
|
|
// else
|
|
server.arg("brightness").getBytes(buffer, 3);
|
|
server.arg("brightness").getBytes(buffer, 3);
|
|
brightness = (nibbler(buffer[0]) << 4) + nibbler(buffer[1]);
|
|
brightness = (nibbler(buffer[0]) << 4) + nibbler(buffer[1]);
|
|
- // limit brightness to 100
|
|
|
|
- brightness = 100 < brightness ? 100 : brightness;
|
|
|
|
|
|
+ // limit brightness to 15
|
|
|
|
+ brightness = 0x0f < brightness ? 0x0f : brightness;
|
|
updateBrightness();
|
|
updateBrightness();
|
|
handleGetBrightness();
|
|
handleGetBrightness();
|
|
- return;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void handleCfg() {
|
|
void handleCfg() {
|
|
uint8_t valid = 0;
|
|
uint8_t valid = 0;
|
|
- char buf[3];
|
|
|
|
|
|
+ uint8_t buf[3];
|
|
if(server.hasArg("quickGamma")) {
|
|
if(server.hasArg("quickGamma")) {
|
|
server.arg("quickGamma").getBytes(buf, 2);
|
|
server.arg("quickGamma").getBytes(buf, 2);
|
|
gammaCorrectionType = '1' == buf[0]
|
|
gammaCorrectionType = '1' == buf[0]
|
|
@@ -409,7 +452,7 @@ void handleCfg() {
|
|
}
|
|
}
|
|
if(server.hasArg("colorCorrection")) {
|
|
if(server.hasArg("colorCorrection")) {
|
|
server.arg("colorCorrection").getBytes(buf, 2);
|
|
server.arg("colorCorrection").getBytes(buf, 2);
|
|
- gammaCorrectionType = '1' == buf[0]
|
|
|
|
|
|
+ useFastLedCorrection = '1' == buf[0]
|
|
? ENABLE_FASTLED_CORRECTION
|
|
? ENABLE_FASTLED_CORRECTION
|
|
: DISABLE_FASTLED_CORRECTION;
|
|
: DISABLE_FASTLED_CORRECTION;
|
|
valid += 1;
|
|
valid += 1;
|
|
@@ -419,12 +462,11 @@ void handleCfg() {
|
|
}
|
|
}
|
|
|
|
|
|
void handleGetCfg() {
|
|
void handleGetCfg() {
|
|
- String info = "cfg [quickGamma:";
|
|
|
|
|
|
+ String info = String("cfg [quickGamma:");
|
|
uint8_t fastled = ENABLE_FASTLED_CORRECTION == useFastLedCorrection;
|
|
uint8_t fastled = ENABLE_FASTLED_CORRECTION == useFastLedCorrection;
|
|
uint8_t sCurve = USE_PHILIP_GAMMA_CORRECTION == gammaCorrectionType;
|
|
uint8_t sCurve = USE_PHILIP_GAMMA_CORRECTION == gammaCorrectionType;
|
|
uint8_t quick = USE_BG100_S_CURVE_GAMMA_CORRECTION == gammaCorrectionType;
|
|
uint8_t quick = USE_BG100_S_CURVE_GAMMA_CORRECTION == gammaCorrectionType;
|
|
- if(valid) server.send(200, "text/html", info + quick + " sCurveGamma:" + sCurve + " colorCorrection:" + fastled + ']' + '\n');
|
|
|
|
- return;
|
|
|
|
|
|
+ server.send(200, "text/html", info + quick + " sCurveGamma:" + sCurve + " colorCorrection:" + fastled + ']' + '\n');
|
|
}
|
|
}
|
|
|
|
|
|
void handleRGB() { // If a POST request is made to URI /login
|
|
void handleRGB() { // If a POST request is made to URI /login
|
|
@@ -440,8 +482,8 @@ void handleRGB() { // If a POST request is made to URI /
|
|
/* red */ (nibbler(hexStr[0]) << 4) + nibbler(hexStr[1]),
|
|
/* red */ (nibbler(hexStr[0]) << 4) + nibbler(hexStr[1]),
|
|
/* green */ (nibbler(hexStr[2]) << 4) + nibbler(hexStr[3]),
|
|
/* green */ (nibbler(hexStr[2]) << 4) + nibbler(hexStr[3]),
|
|
/* blue */ (nibbler(hexStr[4]) << 4) + nibbler(hexStr[5])
|
|
/* blue */ (nibbler(hexStr[4]) << 4) + nibbler(hexStr[5])
|
|
- )
|
|
|
|
- String info = "degub r:";
|
|
|
|
|
|
+ );
|
|
|
|
+ String info = String("degub r:");
|
|
server.send(200, "text/html", info + red + " g:" + green + " b:" + blue + '\n');
|
|
server.send(200, "text/html", info + red + " g:" + green + " b:" + blue + '\n');
|
|
}
|
|
}
|
|
|
|
|
|
@@ -450,6 +492,12 @@ void setColor(uint8_t r, uint8_t g, uint8_t b) {
|
|
red = r;
|
|
red = r;
|
|
green = g;
|
|
green = g;
|
|
blue = b;
|
|
blue = b;
|
|
|
|
+ pwm_set_duty((uint16_t) brightness * correctColor(red, FASTLED_RED_CORRECTION), PWM_RED);
|
|
|
|
+ pwm_set_duty((uint16_t) brightness * correctColor(green, FASTLED_RED_CORRECTION), PWM_GREEN);
|
|
|
|
+ pwm_set_duty((uint16_t) brightness * correctColor(blue, FASTLED_RED_CORRECTION), PWM_BLUE);
|
|
|
|
+ pwm_set_duty((uint16_t) brightness * 255, PWM_LED);
|
|
|
|
+ pwm_start();
|
|
|
|
+ return;
|
|
/* [!] it looks like we always correct color, this is not the case
|
|
/* [!] it looks like we always correct color, this is not the case
|
|
* the correctColor() routine, and the chained gammaCorrection() routine
|
|
* the correctColor() routine, and the chained gammaCorrection() routine
|
|
* check configuration settings before setting the LED color.
|
|
* check configuration settings before setting the LED color.
|
|
@@ -484,10 +532,6 @@ uint8_t nibbler(uint8_t v) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-uint8_t hexStrToInt(char buf[]) {
|
|
|
|
- return (int) strtol(buf, 0, 16);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
void handleLogin() { // If a POST request is made to URI /login
|
|
void handleLogin() { // If a POST request is made to URI /login
|
|
if( ! server.hasArg("username") || ! server.hasArg("password")
|
|
if( ! server.hasArg("username") || ! server.hasArg("password")
|
|
|| server.arg("username") == NULL || server.arg("password") == NULL) { // If the POST request doesn't have username and password data
|
|
|| server.arg("username") == NULL || server.arg("password") == NULL) { // If the POST request doesn't have username and password data
|