|
@@ -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,
|
|
|
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
|
|
|
-}
|
|
|
+};
|
|
|
|
|
|
/* 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.
|
|
@@ -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
|
|
|
* 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) {
|
|
|
uint16_t out;
|
|
@@ -158,19 +158,25 @@ uint8_t gammaCorrection(uint8_t input) {
|
|
|
switch(gammaCorrectionType) {
|
|
|
case USE_PHILIP_GAMMA_CORRECTION: return phillip_adafruitGamma8[input];
|
|
|
case USE_BG100_S_CURVE_GAMMA_CORRECTION: return bg100_sCurveGamma8[input];
|
|
|
- case DISABLE_GAMMA_CORRECTION:
|
|
|
- default:
|
|
|
+ case DISABLE_GAMMA_CORRECTION: ;
|
|
|
+ default: ;
|
|
|
}
|
|
|
return input;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
ESP8266WebServer server(80); // Create a webserver object that listens for HTTP request on port 80
|
|
|
|
|
|
void handleRoot(); // function prototypes for HTTP handlers
|
|
|
void handleLogin();
|
|
|
void handleNotFound();
|
|
|
+void handleRGB();
|
|
|
+void handleGetDec();
|
|
|
+void handleEchoHex();
|
|
|
+void handleAnimate();
|
|
|
+void handleGetCfg();
|
|
|
+void handleCfg();
|
|
|
+void handleGetBrightness();
|
|
|
+void handleBrightness();
|
|
|
|
|
|
void setup(void){
|
|
|
Serial.begin(115200); // Start the Serial communication to send messages to the computer
|
|
@@ -203,11 +209,11 @@ void setup(void){
|
|
|
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("/echo", HTTP_GET, handleEchoHex);
|
|
|
- server.on("/animate", HTTP_GET, handleAnimate);
|
|
|
server.on("/cfg", HTTP_GET, handleGetCfg);
|
|
|
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"
|
|
|
|
|
@@ -229,12 +235,15 @@ void setup(void){
|
|
|
//analogWriteFreq(1000);
|
|
|
analogWriteFreq(250);
|
|
|
|
|
|
+ // default range is 0..255
|
|
|
+ analogWriteRange(1023);
|
|
|
+
|
|
|
// lower brightness to minimal value
|
|
|
brightness = 0;
|
|
|
updateBrightness ();
|
|
|
|
|
|
// 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
|
|
|
analogWrite(PIN_5, red);
|
|
@@ -284,7 +293,7 @@ void loop(void){
|
|
|
* not something we want necessarily, but worth mentioning in case one questions
|
|
|
* what the heck is happening
|
|
|
*/
|
|
|
- delay(1);
|
|
|
+ //delay(1);
|
|
|
|
|
|
if(delayCount++ < TEMPORAL_LENGTH) break;
|
|
|
// do we have any subframes to animate?
|
|
@@ -297,7 +306,6 @@ void loop(void){
|
|
|
if(0 == frame) frame = (ANIMATE_BUFFER_LEN - 1) / 8;
|
|
|
frame--;
|
|
|
// get the next animation delay
|
|
|
- frameAnimationDelay = animationDelayCounter =
|
|
|
// is this a stop frame
|
|
|
if(0xff == frameAnimationDelay) { animate = 0; break; }
|
|
|
// is this a loop frame
|
|
@@ -315,7 +323,7 @@ void loop(void){
|
|
|
animationDelayCounter--;
|
|
|
}
|
|
|
// 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
|
|
|
subframe--;
|
|
|
}
|
|
@@ -343,9 +351,8 @@ void handleGetDec() {
|
|
|
}
|
|
|
|
|
|
void handleGetBrightness() {
|
|
|
- String info = "";
|
|
|
+ String info = String("");
|
|
|
server.send(200, "text/html", info + brightness + '\n');
|
|
|
- return;
|
|
|
}
|
|
|
|
|
|
/* we are going to cheat the brightness by adjusting pwm resolution
|
|
@@ -365,17 +372,23 @@ void handleGetBrightness() {
|
|
|
* at 0 brightness mosfets are driven at 25% duty (255/1032). At 100
|
|
|
* brightness they are driven at 60% duty 255/432.
|
|
|
*/
|
|
|
+uint8_t resolution = 0;
|
|
|
void updateBrightness () {
|
|
|
- // default range is 0..255
|
|
|
- analogWriteRange(1023);
|
|
|
// brightness is inverted, technically it is darkness
|
|
|
uint8_t brightnessValue = 6 * (100 - brightness);
|
|
|
// reducing PWM range will increase brightness
|
|
|
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() {
|
|
|
- char buffer[4];
|
|
|
+ uint8_t buffer[4];
|
|
|
if( ! server.hasArg("brightness")) {
|
|
|
server.send(400, "text/plain", "400: Invalid Request"); // The request is invalid, so send HTTP status 400
|
|
|
return;
|
|
@@ -387,12 +400,11 @@ void handleBrightness() {
|
|
|
brightness = 100 < brightness ? 100 : brightness;
|
|
|
updateBrightness();
|
|
|
handleGetBrightness();
|
|
|
- return;
|
|
|
}
|
|
|
|
|
|
void handleCfg() {
|
|
|
uint8_t valid = 0;
|
|
|
- char buf[3];
|
|
|
+ uint8_t buf[3];
|
|
|
if(server.hasArg("quickGamma")) {
|
|
|
server.arg("quickGamma").getBytes(buf, 2);
|
|
|
gammaCorrectionType = '1' == buf[0]
|
|
@@ -419,12 +431,11 @@ void handleCfg() {
|
|
|
}
|
|
|
|
|
|
void handleGetCfg() {
|
|
|
- String info = "cfg [quickGamma:";
|
|
|
+ String info = String("cfg [quickGamma:");
|
|
|
uint8_t fastled = ENABLE_FASTLED_CORRECTION == useFastLedCorrection;
|
|
|
uint8_t sCurve = USE_PHILIP_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
|
|
@@ -440,8 +451,8 @@ void handleRGB() { // If a POST request is made to URI /
|
|
|
/* red */ (nibbler(hexStr[0]) << 4) + nibbler(hexStr[1]),
|
|
|
/* green */ (nibbler(hexStr[2]) << 4) + nibbler(hexStr[3]),
|
|
|
/* 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');
|
|
|
}
|
|
|
|
|
@@ -484,10 +495,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
|
|
|
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
|