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

Added support for IPSTUBE clock - Model H401 #77

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .github/workflows/pio-build-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ jobs:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false

# Set up a matrix to run the following 3 configurations:
# 1. <Windows, Release, latest MSVC compiler toolchain on the default runner image, default generator>
# 2. <Linux, Release, latest GCC compiler toolchain on the default runner image, default generator>
# 3. <Linux, Release, latest Clang compiler toolchain on the default runner image, default generator>
#
# Set up a matrix to run the following 2 configurations:
# 1. <Windows, Release, toolchain on the default runner image, default generator>
# 2. <Linux, Release, toolchain on the default runner image, default generator>

# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
matrix:
os: [ubuntu-latest, windows-latest]
Expand Down Expand Up @@ -52,3 +51,7 @@ jobs:
- name: Build PlatformIO Project for 4MB flash
run: pio run --environment esp32dev
working-directory: ./EleksTubeHAX_pio

- name: Build PlatformIO Project for 8MB flash
run: pio run --environment esp32dev8MB
working-directory: ./EleksTubeHAX_pio
37 changes: 37 additions & 0 deletions EleksTubeHAX_pio/boards/esp32dev8MB.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"build": {
"arduino":{
"ldscript": "esp32_out.ld"
},
"core": "esp32",
"extra_flags": "-DARDUINO_ESP32_DEV",
"f_cpu": "240000000L",
"f_flash": "40000000L",
"flash_mode": "dio",
"mcu": "esp32",
"variant": "esp32"
},
"connectivity": [
"wifi",
"bluetooth",
"ethernet",
"can"
],
"debug": {
"openocd_board": "esp-wroom-32.cfg"
},
"frameworks": [
"arduino",
"espidf"
],
"name": "Espressif ESP32 Dev Module 8MB",
"upload": {
"flash_size": "8MB",
"maximum_ram_size": 327680,
"maximum_size": 8388608,
"require_upload_port": true,
"speed": 460800
},
"url": "https://en.wikipedia.org/wiki/ESP32",
"vendor": "Espressif"
}
11 changes: 11 additions & 0 deletions EleksTubeHAX_pio/partition_noOta_1Mapp_7Mspiffs.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# manual: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html
#
# examples: https://github.com/espressif/arduino-esp32/tree/master/tools/partitions
#
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, factory, 0x10000, 0x120000,
spiffs, data, spiffs, 0x130000,0x6C0000,
coredump, data, coredump,0x7F0000,0x10000,
59 changes: 53 additions & 6 deletions EleksTubeHAX_pio/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
platform = espressif32
board = esp32dev
framework = arduino

build_flags =
-DCORE_DEBUG_LEVEL=5 ; Set to 0 for no debug; saves flash memory
; Set to 5 for full debug
Expand All @@ -21,7 +20,7 @@ build_flags =
board_build.partitions = partition_noOta_1Mapp_3Mspiffs.csv
upload_speed = 921600
monitor_speed = 115200
lib_deps =
lib_deps =
arduino-libraries/NTPClient
adafruit/Adafruit NeoPixel
paulstoffregen/Time
Expand All @@ -37,7 +36,7 @@ lib_deps =
OneWire
sparkfun/SparkFun APDS9960 RGB and Gesture Sensor
makuna/RTC

; === Tested and working with following versions. If you have issues, revert to libraries listed below. ===
; arduino-libraries/NTPClient@^3.2.1
; adafruit/Adafruit NeoPixel@^1.12.0
Expand All @@ -50,9 +49,57 @@ lib_deps =
; sparkfun/SparkFun APDS9960 RGB and Gesture Sensor@^1.4.3
; makuna/RTC@^2.4.2

extra_scripts =
extra_scripts =
; copy configuration files into TFT_eSPI library folder
script_configure_tft_lib.py
; modify the library files from the APDS9660 gesture sensor library to match ID if the used sensor
script_adjust_gesture_sensor_lib.py

script_adjust_gesture_sensor_lib.py


; This is for IPSTUBE H401 only!
[env:esp32dev8MB]
platform = espressif32
board = esp32dev8MB
framework = arduino
build_flags =
-DCORE_DEBUG_LEVEL=5 ; Set to 0 for no debug; saves flash memory
; Set to 5 for full debug

; https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html
board_build.partitions = partition_noOta_1Mapp_7Mspiffs.csv
upload_speed = 921600
monitor_speed = 115200
lib_deps =
arduino-libraries/NTPClient
adafruit/Adafruit NeoPixel
paulstoffregen/Time
paulstoffregen/DS1307RTC
bodmer/TFT_eSPI
knolleary/PubSubClient
bblanchon/ArduinoJson
milesburton/DallasTemperature
Wire
SPI
FS
SPIFFS
OneWire
sparkfun/SparkFun APDS9960 RGB and Gesture Sensor
makuna/RTC

; === Tested and working with following versions. If you have issues, revert to libraries listed below. ===
; arduino-libraries/NTPClient@^3.2.1
; adafruit/Adafruit NeoPixel@^1.12.0
; paulstoffregen/Time@^1.6.1
; paulstoffregen/DS1307RTC
; bodmer/TFT_eSPI@^2.5.43
; knolleary/PubSubClient@^2.8
; bblanchon/ArduinoJson@^7.0.3
; milesburton/DallasTemperature@^3.11.0
; sparkfun/SparkFun APDS9960 RGB and Gesture Sensor@^1.4.3
; makuna/RTC@^2.4.2

extra_scripts =
; copy configuration files into TFT_eSPI library folder
script_configure_tft_lib_8MB.py
; modify the library files from the APDS9660 gesture sensor library to match ID if the used sensor
script_adjust_gesture_sensor_lib_8MB.py
31 changes: 31 additions & 0 deletions EleksTubeHAX_pio/script_adjust_gesture_sensor_lib_8MB.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
def inplace_change(filename, old_string, new_string):
# Safely read the input filename using 'with'
with open(filename) as f:
s = f.read()
if old_string not in s:
print('"{old_string}" not found in {filename}.'.format(**locals()))
return
else:
print('Found "{old_string}" in {filename}. Trying to change now to the new value!'.format(**locals()))

# Safely write the changed content, if found in the file
with open(filename, 'w') as f:
#print('Found Changing "{old_string}" to "{new_string}" in {filename}'.format(**locals()))
s = s.replace(old_string, new_string)
f.write(s)

print("===== adjusting APDS sensor libs ===== ")

new_string_to_check = "#define APDS9960_ID_3"

filename1 = "./.pio/libdeps/esp32dev8MB/SparkFun APDS9960 RGB and Gesture Sensor/src/SparkFun_APDS9960.h"
filename2 = "./.pio/libdeps/esp32dev8MB/SparkFun APDS9960 RGB and Gesture Sensor/src/SparkFun_APDS9960.cpp"
with open(filename1) as f:
s = f.read()
if new_string_to_check not in s:
#do replacements
inplace_change(filename1,"#define APDS9960_ID_2 0x9C ","#define APDS9960_ID_2 0x9C\r#define APDS9960_ID_3 0xA8")
inplace_change(filename2,"if( !(id == APDS9960_ID_1 || id == APDS9960_ID_2) ) {","if( !(id == APDS9960_ID_1 || id == APDS9960_ID_2 || id == APDS9960_ID_3) ) {")
else:
print("Lib files seems to be adjusted already! Doing nothing.")
print("Done adjusting APDS sensor libs!")
27 changes: 27 additions & 0 deletions EleksTubeHAX_pio/script_configure_tft_lib_8MB.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Import("env") # should not be required; un-comment if you have issues
import shutil

# print("Current CLI targets", COMMAND_LINE_TARGETS)
# print("Current Build targets", BUILD_TARGETS)

print("===== copying TFT config files ===== ")

# https://stackoverflow.com/questions/123198/how-to-copy-files

# source file location: EleksTubeHAX_pio\src\GLOBAL_DEFINES.h & _USER_DEFINES.h
# target file location: EleksTubeHAX_pio\.pio\libdeps\esp32dev8MB\TFT_eSPI\User_Setup.h

# copy using Python libraries
# "copy" changes file timestamp -> lib is always recompiled.
# "copy2" keeps file timestamp -> lib is compiled once
ret = shutil.copy2('./src/_USER_DEFINES.h', './.pio/libdeps/esp32dev8MB/TFT_eSPI')
print("Copied {ret}".format(**locals()))
ret2 = shutil.copy2('./src/GLOBAL_DEFINES.h', './.pio/libdeps/esp32dev8MB/TFT_eSPI/User_Setup.h')
print("Copied {ret2}".format(**locals()))

# copy using Windows command line
# native "copy" command keeps file timestamp -> lib is compiled once
# env.Execute("copy .\\src\\_USER_DEFINES.h .\\.pio\\libdeps\\esp32dev8MB\\TFT_eSPI")
# env.Execute("copy .\\src\\GLOBAL_DEFINES.h .\\.pio\\libdeps\\esp32dev8MB\\TFT_eSPI\\User_Setup.h")

print("Done copying TFT config files!")
6 changes: 3 additions & 3 deletions EleksTubeHAX_pio/src/Backlights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void Backlights::breathPattern() {

void Backlights::testPattern() {
const uint8_t num_colors = 4; // or 3 if you don't want black
uint8_t num_states = NUM_DIGITS * num_colors;
uint8_t num_states = NUM_BACKLIGHT_LEDS * num_colors;
uint8_t state = (millis()/test_ms_delay) % num_states;

uint8_t digit = state/num_colors;
Expand Down Expand Up @@ -167,13 +167,13 @@ uint32_t Backlights::phaseToColor(uint16_t phase) {
void Backlights::rainbowPattern() {
// Divide by 3 to spread it out some, so the whole rainbow isn't displayed at once.
// TODO Make this /3 a parameter
const uint16_t phase_per_digit = (max_phase/NUM_DIGITS)/3;
const uint16_t phase_per_digit = (max_phase/NUM_BACKLIGHT_LEDS)/3;

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

for (uint8_t digit=0; digit < NUM_DIGITS; digit++) {
for (uint8_t digit=0; digit < NUM_BACKLIGHT_LEDS; digit++) {
// Shift the phase for this LED.
uint16_t my_phase = (phase + digit*phase_per_digit) % max_phase;
setPixelColor(digit, phaseToColor(my_phase));
Expand Down
2 changes: 1 addition & 1 deletion EleksTubeHAX_pio/src/Backlights.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class Backlights: public Adafruit_NeoPixel {
public:
Backlights() : config(NULL), pattern_needs_init(true), off(true),
Adafruit_NeoPixel(NUM_DIGITS, BACKLIGHTS_PIN, NEO_GRB + NEO_KHZ800)
Adafruit_NeoPixel(NUM_BACKLIGHT_LEDS, BACKLIGHTS_PIN, NEO_GRB + NEO_KHZ800)
{}

enum patterns { dark, test, constant, rainbow, pulse, breath, num_patterns };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ void Button::begin() {
millis_at_last_loop = millis_at_last_transition;

#ifdef DEBUG_OUTPUT
Serial.print("init button ");
Serial.println(bpin);
Serial.print("init button: ");Serial.println(bpin);
#endif

pinMode(bpin, INPUT);

pinMode(bpin, INPUT);
down_last_time = isButtonDown();
if (down_last_time) {
button_state = down_edge;
Expand All @@ -22,14 +19,11 @@ void Button::begin() {
void Button::loop() {
millis_at_last_loop = millis();
bool down_now = isButtonDown();

#ifdef DEBUG_OUTPUT
#ifdef DEBUG_OUTPUT
if (down_now) {
Serial.print("[B ");
Serial.print(bpin);
Serial.print("]");
}
#endif
Serial.print("[B ");Serial.print(bpin);Serial.println("]");
}
#endif

state previous_state = button_state;

Expand All @@ -43,33 +37,33 @@ void Button::loop() {
millis_at_last_transition = millis_at_last_loop;
}
else if (down_last_time == true && down_now == true) {
// Been pressed. For how long?
// Been pressed. For how long?
if (millis_at_last_loop - millis_at_last_transition >= long_press_ms) {
// Long pressed. Did we just transition?
// Long pressed. Did we just transition?
if (previous_state == down_long_edge || previous_state == down_long) {
// No, we already detected the edge.
// No, we already detected the edge.
button_state = down_long;
}
else {
// Previous state was something else, so this is the transition.
// down -> down_long_edge does NOT update millis_at_last_transition.
// We'd rather know how long it's been down than been down_long.
// We'd rather know how long it's been down than been down_long.
button_state = down_long_edge;
}
}
else {
// Not yet long pressed
// Not yet long pressed
button_state = down;
}
}
else if (down_last_time == true && down_now == false) {
// Just released. From how long?
if (previous_state == down_long_edge || previous_state == down_long) {
// Just released. From how long?
if (previous_state == down_long_edge || previous_state == down_long) {
// Just released from a long press.
button_state = up_long_edge;
}
else {
// Just released from a short press.
// Just released from a short press.
button_state = up_edge;
}
millis_at_last_transition = millis_at_last_loop;
Expand All @@ -88,4 +82,46 @@ const String Button::state_str[Button::num_states] =
"up_edge",
"up_long_edge"
};


//--------------------------------------------

#ifdef ONE_BUTTON_ONLY_MENU
//One Button in Buttons only
void Buttons::begin() {
mode.begin();
}

void Buttons::loop() {
mode.loop();
}

bool Buttons::stateChanged() {
return mode.stateChanged();
}

#endif

#ifndef ONE_BUTTON_ONLY_MENU
//Buttons
void Buttons::begin() {
left.begin();
mode.begin();
right.begin();
power.begin();
}

void Buttons::loop() {
left.loop();
mode.loop();
right.loop();
power.loop();
}

bool Buttons::stateChanged() {
return
left.stateChanged() ||
mode.stateChanged() ||
right.stateChanged() ||
power.stateChanged();
}
#endif
Loading