Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All the useful updates #21

Merged
merged 25 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
659816c
Cleanup original files and updated with my project
aly-fly Feb 12, 2022
9510bd2
Credentials cleanup
aly-fly Feb 12, 2022
a984b3c
Update .gitignore
aly-fly Feb 12, 2022
ca2b604
Update .gitignore
aly-fly Feb 12, 2022
18a4756
Update README.md
aly-fly Feb 12, 2022
36e0933
github if f*ing me
aly-fly Feb 12, 2022
43dce28
added config without credentials
aly-fly Feb 12, 2022
c3acaa8
Added all sorts of compatible graphics
aly-fly Feb 12, 2022
85a2e03
Merge branch 'main' of https://github.com/aly-fly/EleksTubeHAX
aly-fly Feb 12, 2022
d58f2d8
Preloading images, faster update, shows NoMqtt
aly-fly Feb 12, 2022
4fa9d70
Compressed files, faster loading of images
aly-fly Feb 14, 2022
0d4e608
Added a note about hardware fix
aly-fly Feb 14, 2022
0ac651e
Added GeoLocation and automatic Timezone; fixed NTP query
aly-fly Feb 15, 2022
91d2915
Update GLOBAL_DEFINES.h
aly-fly Feb 15, 2022
4022d26
Modified NTP libraries, added error checking
aly-fly Feb 16, 2022
bbde378
Merge branch 'main' of https://github.com/aly-fly/EleksTubeHAX
aly-fly Feb 16, 2022
6ce64bc
Added more error-checking for NTP time
aly-fly Feb 16, 2022
e2d3f6c
Further improvements of NTP library
aly-fly Feb 16, 2022
7b529c0
Updated and enlarged images
aly-fly Feb 24, 2022
6543f55
Support for "SI HAI" branded copy of the clock
aly-fly Feb 24, 2022
148321b
Updated Readme to follow recent changes
aly-fly Feb 24, 2022
8bfd0e3
Update README.md
aly-fly Feb 24, 2022
c4f1f64
Skip the DS1302 check on startup
aly-fly Feb 24, 2022
760f257
Update README.md
aly-fly Feb 24, 2022
261d1ac
Added pre-built files
aly-fly Feb 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
wifi_creds.h
*.swp
build/
EleksTubeHAX/global_defines.h
EleksTubeHAX/GLOBAL_DEFINES.h
EleksTubeHAX/global_defines.h
22 changes: 19 additions & 3 deletions EleksTubeHAX/Backlights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void Backlights::begin(StoredConfig::Config::Backlights *config_) {
// Config is invalid, probably a new device never had its config written.
// Load some reasonable defaults.
Serial.println("Loaded Backlights config is invalid, using default. This is normal on first boot.");
setPattern(dark);
setPattern(rainbow);
setColorPhase(0);
setIntensity(max_intensity-1);
setPulseRate(72);
Expand Down Expand Up @@ -65,7 +65,11 @@ void Backlights::loop() {
}
else if (config->pattern == constant) {
if (pattern_needs_init) {
setBrightness(0xFF >> max_intensity - config->intensity - 1);
if (dimming) {
setBrightness(0xFF >> max_intensity - (BACKLIGHT_DIMMED_INTENSITY) - 1);
} else {
setBrightness(0xFF >> max_intensity - config->intensity - 1);
}
fill(phaseToColor(config->color_phase));
show();
}
Expand All @@ -90,6 +94,9 @@ void Backlights::pulsePattern() {

float pulse_length_millis = (60.0f * 1000) / config->breath_per_min;
float val = 1 + abs(sin(2 * M_PI * millis() / pulse_length_millis)) * 254;
if (dimming) {
val = val * BACKLIGHT_DIMMED_INTENSITY / 7;
}
setBrightness((uint8_t)val);

show();
Expand All @@ -106,6 +113,10 @@ void Backlights::breathPattern() {
float pulse_length_millis = (60.0f * 1000) / config->breath_per_min;
float val = (exp(sin(2 * M_PI * millis() / pulse_length_millis)) - 0.36787944f) * 108.0f;

if (dimming) {
val = val * BACKLIGHT_DIMMED_INTENSITY / 7;
}

uint8_t brightness = (uint8_t)val;
if (brightness < 1) { brightness = 1; }
setBrightness(brightness);
Expand Down Expand Up @@ -161,13 +172,18 @@ void Backlights::rainbowPattern() {

// Divide by 10 to slow down the rainbow rotation rate.
// TODO Make this /10 a parameter
uint16_t phase = millis()/10 % max_phase;
uint16_t phase = millis()/16 % max_phase;

for (uint8_t digit=0; digit < NUM_DIGITS; digit++) {
// Shift the phase for this LED.
uint16_t my_phase = (phase + digit*phase_per_digit) % max_phase;
setPixelColor(digit, phaseToColor(my_phase));
}
if (dimming) {
setBrightness((uint8_t) BACKLIGHT_DIMMED_INTENSITY);
} else {
setBrightness(0xFF >> max_intensity - config->intensity - 1);
}
show();
}

Expand Down
8 changes: 6 additions & 2 deletions EleksTubeHAX/Backlights.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef BACKLIGHTS_H
#define BACKLIGHTS_H

#include "GLOBAL_DEFINES.h"

/*
* A simple sub-class of the Adafruit_NeoPixel class, to configure it for
* the EleksTube-IPS clock, and to add a little functionality.
Expand All @@ -12,7 +14,6 @@
* Otherwise, class Backlights behaves exactly as Adafruit_NeoPixel does.
*/
#include <stdint.h>
#include "Hardware.h"
#include "StoredConfig.h"
#include <Adafruit_NeoPixel.h>

Expand All @@ -29,6 +30,8 @@ class Backlights: public Adafruit_NeoPixel {
void loop();

void togglePower() { off = !off; pattern_needs_init = true; }
void PowerOn() { off = false; pattern_needs_init = true; }
void PowerOff() { off = true; pattern_needs_init = true; }

void setPattern(patterns p) { config->pattern = uint8_t(p); pattern_needs_init = true; }
patterns getPattern() { return patterns(config->pattern); }
Expand All @@ -50,7 +53,8 @@ class Backlights: public Adafruit_NeoPixel {
void setIntensity(uint8_t intensity);
void adjustIntensity(int16_t adj);
uint8_t getIntensity() { return config->intensity; }


bool dimming = false;

private:
bool pattern_needs_init;
Expand Down
2 changes: 1 addition & 1 deletion EleksTubeHAX/Button.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "Button.h"
#include "Buttons.h"

void Button::begin() {
millis_at_last_transition = millis();
Expand Down
71 changes: 0 additions & 71 deletions EleksTubeHAX/Button.h

This file was deleted.

73 changes: 71 additions & 2 deletions EleksTubeHAX/Buttons.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,80 @@
#ifndef BUTTONS_H
#define BUTTONS_H

#include "GLOBAL_DEFINES.h"

/*
* A simple class to keep track of button states. It's asynchronous, only checking
* for changes between calls to .loop(). If a button changes states multiple times
* between calls to .loop(), only the state when .loop() is called is registered.
*/

// For HIGH and LOW
#include <Arduino.h>

class Button {
public:
Button(uint8_t pin, uint8_t active_state=LOW, uint32_t long_press_ms=500)
: pin(pin), active_state(active_state), long_press_ms(long_press_ms),
down_last_time(false), state_changed(false), millis_at_last_transition(0), button_state(idle) {}

/*
* States:
* idle: button was up (not pressed) last time, and is still up now.
* down_edge: button was up last time, but is down now. ie: it has just been pressed.
* down: button was down last time, and is still down, but for less than long_press_ms.
* down_long_edge: button has been down for at least long_press_ms, the first time.
* down_long: button has been down for at least long_press_ms, after the first time.
* up_edge: button was down last time, but is up now. ie: it has just been released from a short press.
* up_long_edge: button was down_long last time, but is up now. ie: just released from a long press.
*
* Note: There is no up_long state, that's just idle and it goes into idle immediately
* after up_edge.
*/
enum state {idle, down_edge, down, down_long_edge, down_long, up_edge, up_long_edge, num_states};
const static String state_str[num_states];

void begin();
void loop();

// These are only updated when loop() is called, not when the getters are called.
state getState() { return button_state; }
String getStateStr() { return state_str[button_state]; }
bool stateChanged() { return state_changed; }
uint32_t millisInState() { return millis_at_last_loop-millis_at_last_transition; }

bool isIdle() { return button_state == idle; }
bool isDownEdge() { return button_state == down_edge; }
bool isDown() { return button_state == down; }
bool isDownLongEdge() { return button_state == down_long_edge; }
bool isDownLong() { return button_state == down_long; }
bool isUpEdge() { return button_state == up_edge; }
bool isUpLongEdge() { return button_state == up_long_edge; }
bool isDownLongy() { return button_state == down_long_edge || button_state == down_long; }
bool isDowny() { return button_state == down_edge || button_state == down || isDownLongy(); }
bool isUpy() { return button_state == idle || button_state == up_edge || button_state == up_long_edge; }

private:
// Config
const uint8_t pin;
const uint8_t active_state;
const uint32_t long_press_ms;

// Internal state
bool down_last_time;
bool state_changed;
uint32_t millis_at_last_transition;
uint32_t millis_at_last_loop;
state button_state;

bool isButtonDown() { return digitalRead(pin) == active_state; }
};


/*
* A simple helper class to call common functions on all buttons at once.
*/

#include "Button.h"
#include "Hardware.h"

class Buttons {
public:
Expand Down
2 changes: 1 addition & 1 deletion EleksTubeHAX/ChipSelect.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef CHIP_SELECT_H
#define CHIP_SELECT_H

#include "Hardware.h"
#include "GLOBAL_DEFINES.h"

/*
* `digit`s are as defined in Hardware.h, 0 == seconds ones, 5 == hours tens.
Expand Down
Loading