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 H401 #74

Closed
wants to merge 10 commits into from
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
Martinius79 marked this conversation as resolved.
Show resolved Hide resolved
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, 0x100000,
spiffs, data, spiffs, 0x110000,0x6E0000,
coredump, data, coredump,0x7F0000,0x10000,
55 changes: 50 additions & 5 deletions EleksTubeHAX_pio/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ board = esp32dev
framework = arduino

build_flags =
-DCORE_DEBUG_LEVEL=5 ; Set to 0 for no debug; saves flash memory
-DCORE_DEBUG_LEVEL=0 ; 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_3Mspiffs.csv
upload_speed = 921600
monitor_speed = 115200
build_type = release
lib_deps =
arduino-libraries/NTPClient
adafruit/Adafruit NeoPixel
Expand All @@ -37,12 +38,11 @@ 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
; paulstoffregen/Time@^1.6.1
; paulstoffregen/DS1307RTC
; bodmer/TFT_eSPI@^2.5.43
; knolleary/PubSubClient@^2.8
; bblanchon/ArduinoJson@^7.0.3
Expand All @@ -54,5 +54,50 @@ 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=0 ; Set to 0 for no debug; saves flash memory
; Set to 5 for full debug
board_build.partitions = partition_noOta_1Mapp_7Mspiffs.csv
upload_speed = 921600
monitor_speed = 115200
build_type = release
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
; 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
Martinius79 marked this conversation as resolved.
Show resolved Hide resolved
; 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!")
47 changes: 44 additions & 3 deletions EleksTubeHAX_pio/src/Backlights.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "Backlights.h"

void Backlights::begin(StoredConfig::Config::Backlights *config_) {
#ifdef DEBUG_OUTPUT_BACKLIGHTS
Serial.println("Backlights::begin!");
#endif
config=config_;

if (config->is_valid != StoredConfig::valid) {
Expand All @@ -22,6 +25,9 @@ void Backlights::begin(StoredConfig::Config::Backlights *config_) {
// These feel like they should be generalizable into a helper function.
// https://stackoverflow.com/questions/11720656/modulo-operation-with-negative-numbers
void Backlights::setNextPattern(int8_t i) {
#ifdef DEBUG_OUTPUT_BACKLIGHTS
Serial.println("Backlights::setNextPattern!");
#endif
int8_t next_pattern = (config->pattern + i) % num_patterns;
while (next_pattern < 0) {
next_pattern += num_patterns;
Expand All @@ -30,6 +36,9 @@ void Backlights::setNextPattern(int8_t i) {
}

void Backlights::adjustColorPhase(int16_t adj) {
#ifdef DEBUG_OUTPUT_BACKLIGHTS
Serial.println("Backlights::adjustColorPhase!");
#endif
int16_t new_phase = (int16_t(config->color_phase % max_phase) + adj) % max_phase;
while (new_phase < 0) {
new_phase += max_phase;
Expand All @@ -38,6 +47,9 @@ void Backlights::adjustColorPhase(int16_t adj) {
}

void Backlights::adjustIntensity(int16_t adj) {
#ifdef DEBUG_OUTPUT_BACKLIGHTS
Serial.println("Backlights::adjustIntensity!");
#endif
int16_t new_intensity = (int16_t(config->intensity) + adj) % max_intensity;
while (new_intensity < 0) {
new_intensity += max_intensity;
Expand All @@ -46,13 +58,18 @@ void Backlights::adjustIntensity(int16_t adj) {
}

void Backlights::setIntensity(uint8_t intensity) {
#ifdef DEBUG_OUTPUT_BACKLIGHTS
Serial.println("Backlights::setIntesity!");
#endif
config->intensity = intensity;
setBrightness(0xFF >> max_intensity - config->intensity - 1);
pattern_needs_init = true;
}

void Backlights::loop() {
// enum patterns { dark, test, constant, rainbow, pulse, breath, num_patterns };
#ifdef DEBUG_OUTPUT_BACKLIGHTS
Serial.println("Backlights::loop!");
#endif
if (off || config->pattern == dark) {
if (pattern_needs_init) {
clear();
Expand Down Expand Up @@ -87,6 +104,9 @@ void Backlights::loop() {
}

void Backlights::pulsePattern() {
#ifdef DEBUG_OUTPUT_BACKLIGHTS
Serial.println("Backlights::pulsePattern!");
#endif
if (pattern_needs_init) {
fill(phaseToColor(config->color_phase));
}
Expand All @@ -103,6 +123,9 @@ void Backlights::pulsePattern() {
}

void Backlights::breathPattern() {
#ifdef DEBUG_OUTPUT_BACKLIGHTS
Serial.println("Backlights::breathPattern!");
#endif
if (pattern_needs_init) {
fill(phaseToColor(config->color_phase));
}
Expand All @@ -124,6 +147,9 @@ void Backlights::breathPattern() {
}

void Backlights::testPattern() {
#ifdef DEBUG_OUTPUT_BACKLIGHTS
Serial.println("Backlights::testPattern!");
#endif
const uint8_t num_colors = 4; // or 3 if you don't want black
uint8_t num_states = NUM_DIGITS * num_colors;
uint8_t state = (millis()/test_ms_delay) % num_states;
Expand All @@ -138,6 +164,9 @@ void Backlights::testPattern() {
}

uint8_t Backlights::phaseToIntensity(uint16_t phase) {
#ifdef DEBUG_OUTPUT_BACKLIGHTS
Serial.println("Backlights::phaseToIntensity!");
#endif
uint16_t color = 0;
if (phase <= 255) {
// Ramping up
Expand All @@ -158,13 +187,19 @@ uint8_t Backlights::phaseToIntensity(uint16_t phase) {
}

uint32_t Backlights::phaseToColor(uint16_t phase) {
#ifdef DEBUG_OUTPUT_BACKLIGHTS
Serial.println("Backlights::phaseToColor!");
#endif
uint8_t red = phaseToIntensity(phase);
uint8_t green = phaseToIntensity((phase + 256)%max_phase);
uint8_t blue = phaseToIntensity((phase + 512)%max_phase);
return(uint32_t(red) << 16 | uint32_t(green) << 8 | uint32_t(blue));
}

void Backlights::rainbowPattern() {
#ifdef DEBUG_OUTPUT_BACKLIGHTS
Serial.println("Backlights::rainbowPattern!");
#endif
// 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;
Expand All @@ -186,5 +221,11 @@ void Backlights::rainbowPattern() {
show();
}

const String Backlights::patterns_str[Backlights::num_patterns] =
{ "Dark", "Test", "Constant", "Rainbow", "Pulse", "Breath" };
const String Backlights::patterns_str[Backlights::num_patterns] = {
"Dark",
"Test",
"Constant",
"Rainbow",
"Pulse",
"Breath"
};
Loading