implement button on/off

pull/46/head
cschwinne 2016-10-30 20:04:39 +01:00
rodzic d01877d32b
commit d190964b95
5 zmienionych plików z 52 dodań i 20 usunięć

Wyświetl plik

@ -1,11 +1,9 @@
color cycle color cycle
sequence sequence
simple slide transition simple slide transition
add toolbar conf in settings
additional color picker field additional color picker field
implement all settings setters implement all settings setters
implement OTA lock / security implement OTA lock / security
implement button
implement HSB slider option implement HSB slider option
implement ranges implement ranges
implement discrete range color setter implement discrete range color setter
@ -15,7 +13,9 @@ svg icons in html
notifier function -> send get request notifier function -> send get request
nightlight function -> turns off after set time (+implement fading) nightlight function -> turns off after set time (+implement fading)
(replace StrContains and num functions) (replace StrContains and num functions)
add preferred colors to settings -> quickly t. UI, button select,
BUGS BUGS
static ip disables mdns static ip disables mdns
XXX authentification for security relevant areas (/edit, /update (!!!), /list, /down, [/settings, /reset, /cleareeprom]) XXX authentification for security relevant areas (/edit, /update (!!!), /list, /down, [/settings, /reset, /cleareeprom])
(Unverified) led_amount does nothing (is always 16) because NeoPixelBus is initiated before EEPROM read

Wyświetl plik

@ -64,6 +64,10 @@
{ {
window.open("/settings","_self"); window.open("/settings","_self");
} }
function ToggleNightMode()
{
}
</script> </script>
<style> <style>
.ctrl_box { .ctrl_box {
@ -118,9 +122,9 @@
.tool_box { .tool_box {
} }
.settingsbutton { input[type=image] {
width: 1.5cm; width: 10vmin;
height: 1.5cm; height: 10vmin;
margin-top: 4px; margin-top: 4px;
margin-right: 4px; margin-right: 4px;
} }
@ -184,6 +188,7 @@
<body onload="Startup()" class=" __plain_text_READY__"> <body onload="Startup()" class=" __plain_text_READY__">
<div id="tbB" class="tool_box"> <div id="tbB" class="tool_box">
<input type="image" class="settingsbutton" src="/button.png" onclick="OpenSettings()"id="tool"> <input type="image" class="settingsbutton" src="/button.png" onclick="OpenSettings()"id="tool">
<input type="image" class="nightbutton" src="/moon.png" onclick="ToggleNightMode()"id="night">
</div> </div>
<div id="cdB" class="ctrl_box"> <div id="cdB" class="ctrl_box">
<form id="form_c" name="Ctrl_form"> <form id="form_c" name="Ctrl_form">

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 3.6 KiB

Wyświetl plik

@ -32,7 +32,7 @@
document.S_form.APPASS.value = this.responseXML.getElementsByTagName('appass')[0].innerHTML; //fake pass like ****** document.S_form.APPASS.value = this.responseXML.getElementsByTagName('appass')[0].innerHTML; //fake pass like ******
document.S_form.APCHAN.value = this.responseXML.getElementsByTagName('apchan')[0].innerHTML; document.S_form.APCHAN.value = this.responseXML.getElementsByTagName('apchan')[0].innerHTML;
document.S_form.LEDS.value = this.responseXML.getElementsByTagName('leds')[0].innerHTML; document.S_form.LEDS.value = this.responseXML.getElementsByTagName('leds')[0].innerHTML;
document.S_form.BTNP.value = this.responseXML.getElementsByTagName('btnp')[0].innerHTML; document.S_form.BTNON.checked = (this.responseXML.getElementsByTagName('btnon')[0].innerHTML)!=0?true:false;
document.S_form.TFADE.checked = (this.responseXML.getElementsByTagName('tfade')[0].innerHTML)!=0?true:false; document.S_form.TFADE.checked = (this.responseXML.getElementsByTagName('tfade')[0].innerHTML)!=0?true:false;
document.S_form.TDLAY.value = this.responseXML.getElementsByTagName('tdlay')[0].innerHTML; document.S_form.TDLAY.value = this.responseXML.getElementsByTagName('tdlay')[0].innerHTML;
document.S_form.NOOTA.checked = (this.responseXML.getElementsByTagName('noota')[0].innerHTML)!=0?true:false; document.S_form.NOOTA.checked = (this.responseXML.getElementsByTagName('noota')[0].innerHTML)!=0?true:false;
@ -100,8 +100,7 @@
The default boot LED color is the current color when settings are saved. <br> The default boot LED color is the current color when settings are saved. <br>
LED amount: <input type="text" name="LEDS" maxlength="3" size="2"> <br> LED amount: <input type="text" name="LEDS" maxlength="3" size="2"> <br>
<h3>Button setup</h3> <h3>Button setup</h3>
Button pin: <input type="text" name="BTNP" maxlength="2" size="2"> <br> On/Off button enabled: <input type="checkbox" name="BTNON" value="0"> <br>
Button function: Toggle on/off <br>
<h3>Transitions</h3> <h3>Transitions</h3>
Fade: <input type="checkbox" name="TFADE" value="0"> <br> Fade: <input type="checkbox" name="TFADE" value="0"> <br>
Transition Delay: <input type="text" name="TDLAY" maxlength="5" size="2"> ms <br> Transition Delay: <input type="text" name="TDLAY" maxlength="5" size="2"> ms <br>

Wyświetl plik

@ -32,6 +32,8 @@ uint16_t transitionDelay = 1500;
boolean ota_lock = false; boolean ota_lock = false;
boolean only_ap = false; boolean only_ap = false;
int led_amount = 16; int led_amount = 16;
int buttonPin = 3; //needs pull-up
boolean buttonEnabled = true;
//Internal vars //Internal vars
byte col_old[]{0, 0, 0}; byte col_old[]{0, 0, 0};
@ -40,7 +42,9 @@ long transitionStartTime;
byte bri = 127; byte bri = 127;
byte bri_old = 0; byte bri_old = 0;
byte bri_t = 0; byte bri_t = 0;
byte bri_last = 127;
boolean transitionActive = false; boolean transitionActive = false;
boolean buttonPressedBefore = false;
NeoPixelBus<NeoGrbFeature, NeoEsp8266Uart800KbpsMethod> strip(led_amount, 1); NeoPixelBus<NeoGrbFeature, NeoEsp8266Uart800KbpsMethod> strip(led_amount, 1);
@ -106,6 +110,7 @@ void saveSettingsToEEPROM()
EEPROM.write(228, aphide); EEPROM.write(228, aphide);
EEPROM.write(227, apchannel); EEPROM.write(227, apchannel);
EEPROM.write(229, led_amount); EEPROM.write(229, led_amount);
EEPROM.write(232, buttonEnabled);
EEPROM.write(234, staticip[0]); EEPROM.write(234, staticip[0]);
EEPROM.write(235, staticip[1]); EEPROM.write(235, staticip[1]);
EEPROM.write(236, staticip[2]); EEPROM.write(236, staticip[2]);
@ -170,6 +175,7 @@ void loadSettingsFromEEPROM()
apchannel = EEPROM.read(227); apchannel = EEPROM.read(227);
if (apchannel > 13 || apchannel < 1) apchannel = 1; if (apchannel > 13 || apchannel < 1) apchannel = 1;
led_amount = EEPROM.read(229); led_amount = EEPROM.read(229);
buttonEnabled = EEPROM.read(232);
staticip[0] = EEPROM.read(234); staticip[0] = EEPROM.read(234);
staticip[1] = EEPROM.read(235); staticip[1] = EEPROM.read(235);
staticip[2] = EEPROM.read(236); staticip[2] = EEPROM.read(236);
@ -269,13 +275,14 @@ void XML_response_settings()
resp = resp + "</apchan>"; resp = resp + "</apchan>";
resp = resp + "<leds>"; resp = resp + "<leds>";
resp = resp + led_amount; resp = resp + led_amount;
resp = resp + "</leds>"; resp = resp + "</leds><tfade>";
resp = resp + "<btnp>0</btnp>"; //NI
resp = resp + "<tfade>";
resp = resp + bool2int(fadeTransition); resp = resp + bool2int(fadeTransition);
resp = resp + "</tfade><tdlay>"; resp = resp + "</tfade><tdlay>";
resp = resp + transitionDelay; resp = resp + transitionDelay;
resp = resp + "</tdlay><noota>0</noota>"; //NI resp = resp + "</tdlay>";
resp = resp + "<btnon>";
resp = resp + bool2int(buttonEnabled);
resp = resp + "</btnon><noota>0</noota>"; //NI
resp = resp + "<norap>0</norap>"; //NI resp = resp + "<norap>0</norap>"; //NI
resp = resp + "<sip>"; resp = resp + "<sip>";
if (!WiFi.localIP()[0] == 0) if (!WiFi.localIP()[0] == 0)
@ -454,6 +461,7 @@ void handleSettingsSet()
int i = server.arg("LEDS").toInt(); int i = server.arg("LEDS").toInt();
if (i > 0) led_amount = i; if (i > 0) led_amount = i;
} }
buttonEnabled = server.hasArg("BTNON");
fadeTransition = server.hasArg("TFADE"); fadeTransition = server.hasArg("TFADE");
if (server.hasArg("TDLAY")) if (server.hasArg("TDLAY"))
{ {
@ -652,6 +660,7 @@ void colorUpdated()
{ {
return; //no change return; //no change
} }
if (bri > 0) bri_last = bri;
notify(); notify();
if (fadeTransition || seqTransition) if (fadeTransition || seqTransition)
{ {
@ -697,6 +706,31 @@ void handleTransitions()
void handleAnimations(){}; void handleAnimations(){};
void handleButton()
{
if (digitalRead(buttonPin) == LOW && !buttonPressedBefore)
{
buttonPressedBefore = true;
if (bri == 0)
{
bri = bri_last;
} else
{
bri_last = bri;
bri = 0;
}
colorUpdated();
}
else if (digitalRead(buttonPin) == HIGH && buttonPressedBefore)
{
delay(15);
if (digitalRead(buttonPin) == HIGH)
{
buttonPressedBefore = false;
}
}
}
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
Serial.println(); Serial.println();
@ -779,22 +813,14 @@ void setup() {
reset(); reset();
}); });
if (!ota_lock){ if (!ota_lock){
//load editor
server.on("/edit", HTTP_GET, [](){ server.on("/edit", HTTP_GET, [](){
if(!handleFileRead("/edit.htm")) server.send(404, "text/plain", "FileNotFound"); if(!handleFileRead("/edit.htm")) server.send(404, "text/plain", "FileNotFound");
}); });
//create file
server.on("/edit", HTTP_PUT, handleFileCreate); server.on("/edit", HTTP_PUT, handleFileCreate);
//delete file
server.on("/edit", HTTP_DELETE, handleFileDelete); server.on("/edit", HTTP_DELETE, handleFileDelete);
//first callback is called after the request has ended with all parsed arguments
//second callback handles file uploads at that location
server.on("/edit", HTTP_POST, [](){ server.send(200, "text/plain", ""); }, handleFileUpload); server.on("/edit", HTTP_POST, [](){ server.send(200, "text/plain", ""); }, handleFileUpload);
//list directory
server.on("/list", HTTP_GET, handleFileList); server.on("/list", HTTP_GET, handleFileList);
//kill module
server.on("/down", HTTP_GET, down); server.on("/down", HTTP_GET, down);
//clear eeprom
server.on("/cleareeprom", HTTP_GET, clearEEPROM); server.on("/cleareeprom", HTTP_GET, clearEEPROM);
//init ota page //init ota page
httpUpdater.setup(&server); httpUpdater.setup(&server);
@ -814,12 +840,14 @@ void setup() {
// Initialize NeoPixel Strip // Initialize NeoPixel Strip
strip.Begin(); strip.Begin();
colorUpdated(); colorUpdated();
pinMode(buttonPin, INPUT_PULLUP);
} }
void loop() { void loop() {
server.handleClient(); server.handleClient();
handleTransitions(); handleTransitions();
handleAnimations(); handleAnimations();
handleButton();
} }
void initAP(){ void initAP(){