Skip to content

Commit

Permalink
Merge pull request #213 from jasoncoon/utc-offset
Browse files Browse the repository at this point in the history
Added UTC offset to firmware & web app.
  • Loading branch information
henrygab authored Nov 25, 2021
2 parents 0a4b255 + bf5f172 commit b1dd8e9
Show file tree
Hide file tree
Showing 8 changed files with 267 additions and 49 deletions.
42 changes: 36 additions & 6 deletions esp8266-fastled-webserver/Fields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ const String ColorFieldType = "Color";
const String SectionFieldType = "Section";
const String StringFieldType = "String";
const String LabelFieldType = "Label";
const String UtcOffsetIndexFieldType = "UtcOffsetIndex";

uint8_t power = 1;
uint8_t brightness = brightnessMap[brightnessIndex];



//String setPower(String value) {
// power = value.toInt();
// if(power < 0) power = 0;
Expand Down Expand Up @@ -151,6 +150,36 @@ String getCoolLikeIncandescent() {
String getName() {
return nameString;
}
String getUtcOffsetIndex() {
return String(utcOffsetIndex);
}

String setUtcOffsetIndex(uint8_t value)
{
utcOffsetIndex = value;
if (utcOffsetIndex > 104) utcOffsetIndex = 104;

const int32_t UTC_OFFSET_MINIMUM_MINUTES = ((int32_t)-12) * 60; // corresponds to index 0
const int32_t UTC_OFFSET_INCREMENT_MINUTES = 15; // each higher index increments by this amount

// minutes above the minimum
int32_t tmp = utcOffsetIndex * UTC_OFFSET_INCREMENT_MINUTES;
// add that to the minimum value
tmp = UTC_OFFSET_MINIMUM_MINUTES + tmp;
// convert to seconds
utcOffsetInSeconds = tmp * 60;

Serial.print(F("utcOffsetIndex: ")); Serial.println(utcOffsetIndex);
Serial.print(F("utcOffsetInSeconds: ")); Serial.println(utcOffsetInSeconds);
timeClient.setTimeOffset(utcOffsetInSeconds);
writeAndCommitSettings();
return String(utcOffsetIndex);
}

String setUtcOffsetIndexString(String value)
{
return setUtcOffsetIndex(value.toInt());
}

// Pride Playground fields

Expand Down Expand Up @@ -359,7 +388,7 @@ String getFieldsJson(const Field (&fields)[N]) {
}
}

if (field.type == NumberFieldType) {
if (field.type == NumberFieldType || field.type == UtcOffsetIndexFieldType) {
json += ",\"min\":" + String(field.min);
json += ",\"max\":" + String(field.max);
}
Expand Down Expand Up @@ -399,9 +428,10 @@ const Field fields[] = {
{"autoplayDuration", "Autoplay Duration", NumberFieldType, 0, 255, getAutoplayDuration, nullptr, nullptr},

//--------------------------------------------------------------------------------------------------------
{"clock", "Clock", SectionFieldType, 0, 0, nullptr, nullptr, nullptr},
{"showClock", "Show Clock", BooleanFieldType, 0, 1, getShowClock, nullptr, nullptr},
{"clockBackgroundFade", "Background Fade", NumberFieldType, 0, 255, getClockBackgroundFade, nullptr, nullptr},
{"clock", "Clock", SectionFieldType, 0, 0, nullptr, nullptr, nullptr},
{"showClock", "Show Clock", BooleanFieldType, 0, 1, getShowClock, nullptr, nullptr},
{"clockBackgroundFade", "Background Fade", NumberFieldType, 0, 255, getClockBackgroundFade, nullptr, nullptr},
{"utcOffsetIndex", "UTC Offset", UtcOffsetIndexFieldType, 0, 104, getUtcOffsetIndex, nullptr, setUtcOffsetIndexString},

//--------------------------------------------------------------------------------------------------------
{"solidColorSection", "Solid Color", SectionFieldType, 0, 0, nullptr, nullptr, nullptr},
Expand Down
32 changes: 16 additions & 16 deletions esp8266-fastled-webserver/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,9 @@ void drawAnalogClock() {
float minute = timeClient.getMinutes() + (second / 60.0);
float hour = timeClient.getHours() + (minute / 60.0);

hourAngle = 256u - hour * degreesPerHour;
minuteAngle = 256u - minute * degreesPerMinute;
secondAngle = 256u - second * degreesPerSecond;
hourAngle = 64u - hour * degreesPerHour;
minuteAngle = 64u - minute * degreesPerMinute;
secondAngle = 64u - second * degreesPerSecond;
}

// although can update angles once every 100ms, have to perform fade & overlay with each cycle
Expand Down Expand Up @@ -473,42 +473,42 @@ void drawSpiralAnalogClock(uint8_t step_h, uint8_t step_m, uint8_t step_s) {
float minute = timeClient.getMinutes() + (second / 60.0);
float hour = timeClient.getHours() + (minute / 60.0);

hourAngle = 256u - hour * degreesPerHour;
minuteAngle = 256u - minute * degreesPerMinute;
secondAngle = 256u - second * degreesPerSecond;
hourAngle = 64u - hour * degreesPerHour;
minuteAngle = 64u - minute * degreesPerMinute;
secondAngle = 64u - second * degreesPerSecond;
}

drawSpiralLine(secondAngle, step_s, CRGB(0, 0, 2));
drawSpiralLine(minuteAngle, step_m, CRGB(0, 2, 0));
drawSpiralLine(hourAngle, step_h, CRGB(2, 0, 0));
drawSpiralLine(secondAngle, step_s, CRGB::Blue );
drawSpiralLine(minuteAngle, step_m, CRGB::Green);
drawSpiralLine(hourAngle, step_h, CRGB::Red );
}
void drawSpiralAnalogClock(uint8_t step) {
drawSpiralAnalogClock(step, step, step);
}
void drawSpiralAnalogClock13() {
fadeToBlackBy(leds, NUM_PIXELS, clockBackgroundFade);
drawSpiralAnalogClock(13, 13, 13);
drawSpiralAnalogClock(13);
}
void drawSpiralAnalogClock21() {
fadeToBlackBy(leds, NUM_PIXELS, clockBackgroundFade);
drawSpiralAnalogClock(21, 21, 21);
drawSpiralAnalogClock(21);
}
void drawSpiralAnalogClock34() {
fadeToBlackBy(leds, NUM_PIXELS, clockBackgroundFade);
drawSpiralAnalogClock(34, 34, 34);
drawSpiralAnalogClock(34);
}
void drawSpiralAnalogClock55() {
fadeToBlackBy(leds, NUM_PIXELS, clockBackgroundFade);
drawSpiralAnalogClock(55, 55, 55);
drawSpiralAnalogClock(55);
}
void drawSpiralAnalogClock89() {
fadeToBlackBy(leds, NUM_PIXELS, clockBackgroundFade);
drawSpiralAnalogClock(89, 89, 89);
drawSpiralAnalogClock(89);
}
void drawSpiralAnalogClock21and34() {
fadeToBlackBy(leds, NUM_PIXELS, clockBackgroundFade);
drawSpiralAnalogClock(21, 21, 21);
drawSpiralAnalogClock(34, 34, 34);
drawSpiralAnalogClock(21);
drawSpiralAnalogClock(34);
}
void drawSpiralAnalogClock13_21_and_34() {
fadeToBlackBy(leds, NUM_PIXELS, clockBackgroundFade);
Expand Down
3 changes: 3 additions & 0 deletions esp8266-fastled-webserver/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ extern WiFiManager wifiManager;
extern ESP8266WebServer webServer;
extern NTPClient timeClient;
extern String nameString;
extern int utcOffsetInSeconds;
extern uint8_t utcOffsetIndex;
extern String setUtcOffsetIndex(uint8_t value);

extern CRGB leds[NUM_PIXELS];

Expand Down
3 changes: 0 additions & 3 deletions esp8266-fastled-webserver/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@
// Set defaults for optional values
// ////////////////////////////////////////////////////////////////////////////////////////////////////
#if 1 // just for collapsing
#if !defined(UTC_OFFSET_IN_SECONDS)
#define UTC_OFFSET_IN_SECONDS (-6L * 60L * 60L) // UTC-6 (East-coast US ... no DST support)
#endif
#if !defined(NTP_UPDATE_THROTTLE_MILLLISECONDS)
#define NTP_UPDATE_THROTTLE_MILLLISECONDS (5UL * 60UL * 60UL * 1000UL) // Ping NTP server no more than every 5 minutes
#endif
Expand Down
129 changes: 129 additions & 0 deletions esp8266-fastled-webserver/data/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,135 @@ <h4 class="panel-title">
</div>
</div>

<div id="utcOffsetIndexTemplate" class="form-group">
<label class="col-sm-2 control-label"></label>
<div class="col-sm-8">
<select class="form-control">
<option value="0">-12:00</option>
<option value="1">-11:45</option>
<option value="2">-11:30</option>
<option value="3">-11:15</option>
<option value="4">-11:00</option>
<option value="5">-10:45</option>
<option value="6">-10:30</option>
<option value="7">-10:15</option>
<option value="8">-10:00</option>
<option value="9">-9:45</option>
<option value="10">-9:30</option>
<option value="11">-9:15</option>
<option value="12">-9:00</option>
<option value="13">-8:45</option>
<option value="14">-8:30</option>
<option value="15">-8:15</option>
<option value="16">-8:00</option>
<option value="17">-7:45</option>
<option value="18">-7:30</option>
<option value="19">-7:15</option>
<option value="20">-7:00</option>
<option value="21">-6:45</option>
<option value="22">-6:30</option>
<option value="23">-6:15</option>
<option value="24">-6:00</option>
<option value="25">-5:45</option>
<option value="26">-5:30</option>
<option value="27">-5:15</option>
<option value="28">-5:00</option>
<option value="29">-4:45</option>
<option value="30">-4:30</option>
<option value="31">-4:15</option>
<option value="32">-4:00</option>
<option value="33">-3:45</option>
<option value="34">-3:30</option>
<option value="35">-3:15</option>
<option value="36">-3:00</option>
<option value="37">-2:45</option>
<option value="38">-2:30</option>
<option value="39">-2:15</option>
<option value="40">-2:00</option>
<option value="41">-1:45</option>
<option value="42">-1:30</option>
<option value="43">-1:15</option>
<option value="44">-1:00</option>
<option value="45">0:45</option>
<option value="46">0:30</option>
<option value="47">0:15</option>
<option value="48">0:00</option>
<option value="49">0:45</option>
<option value="50">0:30</option>
<option value="51">0:15</option>
<option value="52">1:00</option>
<option value="53">1:45</option>
<option value="54">1:30</option>
<option value="55">1:15</option>
<option value="56">2:00</option>
<option value="57">2:45</option>
<option value="58">2:30</option>
<option value="59">2:15</option>
<option value="60">3:00</option>
<option value="61">3:45</option>
<option value="62">3:30</option>
<option value="63">3:15</option>
<option value="64">4:00</option>
<option value="65">4:45</option>
<option value="66">4:30</option>
<option value="67">4:15</option>
<option value="68">5:00</option>
<option value="69">5:45</option>
<option value="70">5:30</option>
<option value="71">5:15</option>
<option value="72">6:00</option>
<option value="73">6:45</option>
<option value="74">6:30</option>
<option value="75">6:15</option>
<option value="76">7:00</option>
<option value="77">7:45</option>
<option value="78">7:30</option>
<option value="79">7:15</option>
<option value="80">8:00</option>
<option value="81">8:45</option>
<option value="82">8:30</option>
<option value="83">8:15</option>
<option value="84">9:00</option>
<option value="85">9:45</option>
<option value="86">9:30</option>
<option value="87">9:15</option>
<option value="88">10:00</option>
<option value="89">10:45</option>
<option value="90">10:30</option>
<option value="91">10:15</option>
<option value="92">11:00</option>
<option value="93">11:45</option>
<option value="94">11:30</option>
<option value="95">11:15</option>
<option value="96">12:00</option>
<option value="97">12:45</option>
<option value="98">12:30</option>
<option value="99">12:15</option>
<option value="100">13:00</option>
<option value="101">13:45</option>
<option value="102">13:30</option>
<option value="103">13:15</option>
<option value="104">14:00</option>
</select>
</div>
<div class="col-sm-2">
<div class="btn-group" role="group" aria-label="...">
<button type="button" class="btn btn-default btn-previous"
aria-label="Previous" title="Previous">
<span class="glyphicon glyphicon-chevron-left"></span>
</button>
<button type="button" class="btn btn-default btn-next"
aria-label="Next" title="Next">
<span class="glyphicon glyphicon-chevron-right"></span>
</button>
<a class="btn btn-default" href="https://en.wikipedia.org/wiki/List_of_UTC_time_offsets" role="button"
title="List of UTC time offsets" target="_blank" rel="noopener noreferrer">
<span class="glyphicon glyphicon-question-sign"></span>
</a>
</div>
</div>
</div>

<div id="colorPaletteTemplate" class="form-group">
<label class="col-sm-2 control-label color-label"></label>
<div class="col-sm-10">
Expand Down
48 changes: 48 additions & 0 deletions esp8266-fastled-webserver/data/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ $(document).ready(function() {
addStringField(field, false);
} else if (field.type == "Label") {
addStringField(field, true);
} else if (field.type == "UtcOffsetIndex") {
addUtcOffsetIndexField(field, true);
}
});

Expand Down Expand Up @@ -300,6 +302,52 @@ function addSelectField(field) {
$("#form").append(template);
}

function addUtcOffsetIndexField(field) {
var template = $("#utcOffsetIndexTemplate").clone();

template.attr("id", "form-group-" + field.name);
template.attr("data-field-type", field.type);

var id = "input-" + field.name;

var label = template.find(".control-label");
label.attr("for", id);
label.text(field.label);

var select = template.find(".form-control");
select.attr("id", id);

select.val(field.value);

select.change(function () {
var value = template.find("#" + id + " option:selected").index();
postValue(field.name, value);
});

var previousButton = template.find(".btn-previous");
var nextButton = template.find(".btn-next");

previousButton.click(function () {
var value = template.find("#" + id + " option:selected").index();
var count = select.find("option").length;
value--;
if (value < 0) value = count - 1;
select.val(value);
postValue(field.name, value);
});

nextButton.click(function () {
var value = template.find("#" + id + " option:selected").index();
var count = select.find("option").length;
value++;
if (value >= count) value = 0;
select.val(value);
postValue(field.name, value);
});

$("#form").append(template);
}

function addColorFieldPicker(field) {
var template = $("#colorTemplate").clone();

Expand Down
Loading

0 comments on commit b1dd8e9

Please sign in to comment.