Browse Source

Merge branch 'pwm-dimmer' of https://github.com/wysiwyng/espurna into wysiwyng-pwm-dimmer

Conflicts:
	code/espurna/data/index.html.gz
	code/espurna/static/index.html.gz.h
	code/html/custom.js
rfm69
Xose Pérez 6 years ago
parent
commit
8777d29f7c
10 changed files with 3326 additions and 3254 deletions
  1. +3
    -3
      README.md
  2. +6
    -3
      code/espurna/config/general.h
  3. BIN
      code/espurna/data/index.html.gz
  4. +9
    -5
      code/espurna/debug.ino
  5. +30
    -10
      code/espurna/scheduler.ino
  6. +3217
    -3202
      code/espurna/static/index.html.gz.h
  7. +3
    -14
      code/espurna/ws.ino
  8. +6
    -1
      code/html/custom.css
  9. +27
    -4
      code/html/custom.js
  10. +25
    -12
      code/html/index.html

+ 3
- 3
README.md View File

@ -4,9 +4,9 @@ ESPurna ("spark" in Catalan) is a custom firmware for ESP8285/ESP8266 based smar
It uses the Arduino Core for ESP8266 framework and a number of 3rd party libraries.
[![version](https://img.shields.io/badge/version-1.12.5a-brightgreen.svg)](CHANGELOG.md)
![branch](https://img.shields.io/badge/branch-a-tom-s-ResetRelay-orange.svg)
[![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=a-tom-s-ResetRelay)](https://travis-ci.org/xoseperez/espurna)
[![codacy](https://img.shields.io/codacy/grade/c9496e25cf07434cba786b462cb15f49/a-tom-s-ResetRelay.svg)](https://www.codacy.com/app/xoseperez/espurna/dashboard)
![branch](https://img.shields.io/badge/branch-wysiwyng-pwm-dimmer-orange.svg)
[![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=wysiwyng-pwm-dimmer)](https://travis-ci.org/xoseperez/espurna)
[![codacy](https://img.shields.io/codacy/grade/c9496e25cf07434cba786b462cb15f49/wysiwyng-pwm-dimmer.svg)](https://www.codacy.com/app/xoseperez/espurna/dashboard)
[![donate](https://img.shields.io/badge/donate-PayPal-blue.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=xose%2eperez%40gmail%2ecom&lc=US&no_note=0&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHostedGuest)
[![twitter](https://img.shields.io/twitter/follow/xoseperez.svg?style=social)](https://twitter.com/intent/follow?screen_name=xoseperez)


+ 6
- 3
code/espurna/config/general.h View File

@ -811,16 +811,19 @@ PROGMEM const char* const custom_reset_string[] = {
// SCHEDULER
// -----------------------------------------------------------------------------
#define SCHEDULER_TYPE_SWITCH 1
#define SCHEDULER_TYPE_DIM 2
#ifndef SCHEDULER_SUPPORT
#define SCHEDULER_SUPPORT 1 // Enable scheduler (1.77Kb)
#define SCHEDULER_SUPPORT 1 // Enable scheduler (1.77Kb)
#endif
#if SCHEDULER_SUPPORT
#undef NTP_SUPPORT
#define NTP_SUPPORT 1 // Scheduler needs NTP
#define NTP_SUPPORT 1 // Scheduler needs NTP
#endif
#define SCHEDULER_MAX_SCHEDULES 10 // Max schedules alowed
#define SCHEDULER_MAX_SCHEDULES 10 // Max schedules alowed
// -----------------------------------------------------------------------------
// NTP


BIN
code/espurna/data/index.html.gz View File


+ 9
- 5
code/espurna/debug.ino View File

@ -61,11 +61,15 @@ void _debugSend(char * message) {
#endif
#if DEBUG_WEB_SUPPORT
#if DEBUG_ADD_TIMESTAMP
wsSend_P(PSTR("{\"weblog\": \"%s%s\"}"), timestamp, message);
#else
wsSend_P(PSTR("{\"weblog\": \"%s\"}"), message);
#endif
if (wsConnected()) {
char buffer[strlen(message) + 24];
#if DEBUG_ADD_TIMESTAMP
snprintf_P(buffer, sizeof(buffer), PSTR("{\"weblog\": \"%s%s\"}"), timestamp, message);
#else
snprintf_P(buffer, sizeof(buffer), PSTR("{\"weblog\": \"%s\"}"), message);
#endif
wsSend(buffer);
}
#endif
}


+ 30
- 10
code/espurna/scheduler.ino View File

@ -18,7 +18,7 @@ Adapted by Xose Pérez <xose dot perez at gmail dot com>
void _schWebSocketOnSend(JsonObject &root){
root["schVisible"] = 1;
root["maxScheduled"] = SCHEDULER_MAX_SCHEDULES;
root["maxSchedules"] = SCHEDULER_MAX_SCHEDULES;
JsonArray &sch = root.createNestedArray("schedule");
for (byte i = 0; i < SCHEDULER_MAX_SCHEDULES; i++) {
if (!hasSetting("schSwitch", i)) break;
@ -26,6 +26,7 @@ void _schWebSocketOnSend(JsonObject &root){
scheduler["schEnabled"] = getSetting("schEnabled", i, 1).toInt() == 1;
scheduler["schSwitch"] = getSetting("schSwitch", i, 0).toInt();
scheduler["schAction"] = getSetting("schAction", i, 0).toInt();
scheduler["schType"] = getSetting("schType", i, 0);
scheduler["schHour"] = getSetting("schHour", i, 0).toInt();
scheduler["schMinute"] = getSetting("schMinute", i, 0).toInt();
scheduler["schWDs"] = getSetting("schWDs", i, "");
@ -53,6 +54,7 @@ void _schConfigure() {
delSetting("schHour", i);
delSetting("schMinute", i);
delSetting("schWDs", i);
delSetting("schType", i);
} else {
@ -63,10 +65,12 @@ void _schConfigure() {
int sch_hour = getSetting("schHour", i, 0).toInt();
int sch_minute = getSetting("schMinute", i, 0).toInt();
String sch_weekdays = getSetting("schWDs", i, "");
unsigned char sch_type = getSetting("schType", i, SCHEDULER_TYPE_SWITCH).toInt();
DEBUG_MSG_P(
PSTR("[SCH] Schedule #%d: %s switch #%d at %02d:%02d on %s%s\n"),
i, sch_action == 0 ? "turn OFF" : sch_action == 1 ? "turn ON" : "toggle", sch_switch,
sch_hour, sch_minute, (char *) sch_weekdays.c_str(),
PSTR("[SCH] Schedule #%d: %s #%d to %d at %02d:%02d on %s%s\n"),
i, SCHEDULER_TYPE_SWITCH == sch_type ? "switch" : "channel", sch_switch,
sch_action, sch_hour, sch_minute, (char *) sch_weekdays.c_str(),
sch_enabled ? "" : " (disabled)"
);
@ -120,13 +124,29 @@ void _schCheck() {
int minutes_to_trigger = _schMinutesLeft(sch_hour, sch_minute);
if (minutes_to_trigger == 0) {
int sch_action = getSetting("schAction", i, 0).toInt();
if (sch_action == 2) {
relayToggle(sch_switch);
} else {
relayStatus(sch_switch, sch_action);
unsigned char sch_type = getSetting("schType", i, SCHEDULER_TYPE_SWITCH).toInt();
if (SCHEDULER_TYPE_SWITCH == sch_type) {
int sch_action = getSetting("schAction", i, 0).toInt();
DEBUG_MSG_P(PSTR("[SCH] Switching switch %d to %d\n"), sch_switch, sch_action);
if (sch_action == 2) {
relayToggle(sch_switch);
} else {
relayStatus(sch_switch, sch_action);
}
}
DEBUG_MSG_P(PSTR("[SCH] Schedule #%d TRIGGERED!!\n"), sch_switch);
#if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
if (SCHEDULER_TYPE_DIM == sch_type) {
int sch_brightness = getSetting("schAction", i, -1).toInt();
DEBUG_MSG_P(PSTR("[SCH] Set channel %d value to %d\n"), sch_switch, sch_brightness);
lightChannel(sch_switch, sch_brightness);
lightUpdate(true, true);
}
#endif
DEBUG_MSG_P(PSTR("[SCH] Schedule #%d TRIGGERED!!\n"), i);
// Show minutes to trigger every 15 minutes
// or every minute if less than 15 minutes to scheduled time.


+ 3217
- 3202
code/espurna/static/index.html.gz.h
File diff suppressed because it is too large
View File


+ 3
- 14
code/espurna/ws.ino View File

@ -363,22 +363,11 @@ void wsSend(const char * payload) {
}
}
void wsSend_P(PGM_P format_P, ...) {
void wsSend_P(PGM_P payload) {
if (_ws.count() > 0) {
char format[strlen_P(format_P)+1];
memcpy_P(format, format_P, sizeof(format));
va_list args;
va_start(args, format_P);
char test[1];
int len = ets_vsnprintf(test, 1, format, args) + 1;
char * buffer = new char[len];
ets_vsnprintf(buffer, len, format, args);
va_end(args);
char buffer[strlen_P(payload)];
strcpy_P(buffer, payload);
_ws.textAll(buffer);
delete[] buffer;
}
}


+ 6
- 1
code/html/custom.css View File

@ -164,7 +164,6 @@ div.state {
.button-update,
.button-update-password,
.button-add-network,
.button-add-schedule,
.button-rfb-learn,
.button-upgrade-browse,
.button-ha-add,
@ -176,6 +175,12 @@ div.state {
background: rgb(0, 192, 0); /* green */
}
.button-add-switch-schedule,
.button-add-light-schedule {
background: rgb(0, 192, 0); /* green */
display: none;
}
.button-more-network,
.button-more-schedule,
.button-wifi-scan,


+ 27
- 4
code/html/custom.js View File

@ -177,7 +177,7 @@ function addValue(data, name, value) {
// These fields will always be a list of values
var is_group = [
"ssid", "pass", "gw", "mask", "ip", "dns",
"schEnabled", "schSwitch","schAction","schHour","schMinute","schWDs",
"schEnabled", "schSwitch","schAction","schType","schHour","schMinute","schWDs",
"relayBoot", "relayPulse", "relayTime",
"mqttGroup", "mqttGroupInv", "relayOnDisc",
"dczRelayIdx", "dczMagnitude",
@ -647,7 +647,7 @@ function moreSchedule() {
$("div.more", parent).toggle();
}
function addSchedule() {
function addSchedule(event) {
var numSchedules = $("#schedules > div").length;
if (numSchedules >= maxSchedules) {
alert("Max number of schedules reached");
@ -656,12 +656,21 @@ function addSchedule() {
var tabindex = 200 + numSchedules * 10;
var template = $("#scheduleTemplate").children();
var line = $(template).clone();
var type = (1 === event.data.schType) ? "switch" : "light";
template = $("#" + type + "ActionTemplate").children();
var actionLine = template.clone();
$(line).find("#schActionDiv").append(actionLine);
$(line).find("input").each(function() {
$(this).attr("tabindex", tabindex);
tabindex++;
});
$(line).find(".button-del-schedule").on("click", delSchedule);
$(line).find(".button-more-schedule").on("click", moreSchedule);
var ena = $(line).find(":checkbox");
ena.prop("checked", false).iphoneStyle("refresh");
line.appendTo("#schedules");
return line;
}
@ -839,6 +848,9 @@ function initChannels(num) {
line.appendTo("#channels");
$("select.islight").append(
$("<option></option>").attr("value",i).text("Channel #" + i));
}
}
@ -994,6 +1006,14 @@ function processData(data) {
useWhite = value;
}
if ("colorVisible" === key) {
$(".button-add-light-schedule").show();
}
if ("relayVisible" === key) {
$(".button-add-switch-schedule").show();
}
// ---------------------------------------------------------------------
// Sensors & Magnitudes
// ---------------------------------------------------------------------
@ -1056,7 +1076,8 @@ function processData(data) {
if ("schedule" === key) {
for (i in value) {
var schedule = value[i];
var sch_line = addSchedule();
var sch_line = addSchedule({ data: {schType: schedule["schType"] }});
Object.keys(schedule).forEach(function(key) {
var sch_value = schedule[key];
$("input[name='" + key + "']", sch_line).val(sch_value);
@ -1134,6 +1155,7 @@ function processData(data) {
return;
}
// Web log
if ("weblog" === key) {
$("#weblog").append(value);
$("#weblog").scrollTop($("#weblog")[0].scrollHeight - $("#weblog").height());
@ -1325,7 +1347,8 @@ $(function() {
$(".button-add-network").on("click", function() {
$(".more", addNetwork()).toggle();
});
$(".button-add-schedule").on("click", addSchedule);
$(".button-add-switch-schedule").on("click", { schType: "1" }, addSchedule);
$(".button-add-light-schedule").on("click", { schType: "2" }, addSchedule);
$(document).on("change", "input", hasChanged);
$(document).on("change", "select", hasChanged);


+ 25
- 12
code/html/index.html View File

@ -605,7 +605,8 @@
<div id="schedules"></div>
<button type="button" class="pure-button button-add-schedule">Add schedule</button>
<button type="button" class="pure-button button-add-switch-schedule">Add switch schedule</button>
<button type="button" class="pure-button button-add-light-schedule">Add channel schedule</button>
</fieldset>
@ -1207,11 +1208,11 @@
<label class="pure-u-1 pure-u-lg-1-4">When time is</label>
<div class="pure-u-1-4 pure-u-lg-1-5">
<input class="pure-u-2-3" name="schHour" type="number" min="0" step="1" max="23" />
<input class="pure-u-2-3" name="schHour" type="number" min="0" step="1" max="23" value="0" />
<div class="pure-u-1-4 hint center">&nbsp;h</div>
</div>
<div class="pure-u-1-4 pure-u-lg-1-5">
<input class="pure-u-2-3" name="schMinute" type="number" min="0" step="1" max="59" />
<input class="pure-u-2-3" name="schMinute" type="number" min="0" step="1" max="59" value="0" />
<div class="pure-u-1-4 hint center">&nbsp;m</div>
</div>
<div class="pure-u-0 pure-u-lg-1-3"></div>
@ -1222,25 +1223,37 @@
</div>
<div class="pure-u-3-5 pure-u-lg-1-2 hint center">&nbsp;1 for Monday, 2 for Tuesday...</div>
<label class="pure-u-1 pure-u-lg-1-4">Action</label>
<div class="pure-u-1 pure-u-lg-1-5">
<select class="pure-u-1 pure-u-lg-23-24" name="schAction">
<option value="0">Turn OFF</option>
<option value="1">Turn ON</option>
<option value="2">Toggle</option>
</select>
<div id="schActionDiv" class="pure-u-1">
</div>
<select class="pure-u-1 pure-u-lg-1-5 isrelay" name="schSwitch"></select>
<div class="pure-u-0 pure-u-lg-1-5"></div>
<label class="pure-u-1 pure-u-lg-1-4">Enabled</label>
<div class="pure-u-1 pure-u-lg-3-4"><input type="checkbox" name="schEnabled" /></div>
<div class="pure-u-0 pure-u-lg-1-4"></div>
<button class="pure-button button-del-schedule" type="button">Delete schedule</button>
</div>
</div>
<div id="switchActionTemplate" class="template">
<label class="pure-u-1 pure-u-lg-1-4">Action</label>
<div class="pure-u-1 pure-u-lg-1-5">
<select class="pure-u-1 pure-u-lg-23-24" name="schAction">
<option value="0">Turn OFF</option>
<option value="1">Turn ON</option>
<option value="2">Toggle</option>
</select>
</div>
<select class="pure-u-1 pure-u-lg-1-5 isrelay" name="schSwitch"></select>
<input type="hidden" name="schType" value="1">
</div>
<div id="lightActionTemplate" class="template">
<label class="pure-u-1 pure-u-lg-1-4">Brightness</label>
<div class="pure-u-1 pure-u-lg-1-5">
<input class="pure-u-2-3" name="schAction" type="number" min="0" step="1" max="255" value="0" />
</div>
<select class="pure-u-1 pure-u-lg-1-5 islight" name="schSwitch"></select>
<input type="hidden" name="schType" value="2">
</div>
<div id="relayTemplate" class="template">


Loading…
Cancel
Save