diff --git a/src/AmbientLightingThread.h b/src/AmbientLightingThread.h index 98ccedde4..fd3c66cda 100644 --- a/src/AmbientLightingThread.h +++ b/src/AmbientLightingThread.h @@ -5,6 +5,11 @@ NCP5623 rgb; #endif +#ifdef UNPHONE +#include "unPhone.h" +extern unPhone unphone; +#endif + namespace concurrency { class AmbientLightingThread : public concurrency::OSThread @@ -20,8 +25,8 @@ class AmbientLightingThread : public concurrency::OSThread // moduleConfig.ambient_lighting.green = (myNodeInfo.my_node_num & 0x00FF00) >> 8; // moduleConfig.ambient_lighting.blue = myNodeInfo.my_node_num & 0x0000FF; -#ifdef HAS_NCP5623 _type = type; +#ifdef HAS_NCP5623 if (_type == ScanI2C::DeviceType::NONE) { LOG_DEBUG("AmbientLightingThread disabling due to no RGB leds found on I2C bus\n"); disable(); @@ -37,14 +42,23 @@ class AmbientLightingThread : public concurrency::OSThread rgb.begin(); setLighting(); } +#endif +#ifdef UNPHONE + if (!moduleConfig.ambient_lighting.led_state) { + LOG_DEBUG("AmbientLightingThread disabling due to moduleConfig.ambient_lighting.led_state OFF\n"); + disable(); + return; + } + LOG_DEBUG("AmbientLightingThread initializing\n"); + setLighting(); #endif } protected: int32_t runOnce() override { -#ifdef HAS_NCP5623 - if (_type == ScanI2C::NCP5623 && moduleConfig.ambient_lighting.led_state) { +#if defined(HAS_NCP5623) || defined(UNPHONE) + if ((_type == ScanI2C::NCP5623 || _type == ScanI2C::RGBLED_CA) && moduleConfig.ambient_lighting.led_state) { setLighting(); return 30000; // 30 seconds to reset from any animations that may have been running from Ext. Notification } else { @@ -68,6 +82,11 @@ class AmbientLightingThread : public concurrency::OSThread LOG_DEBUG("Initializing Ambient lighting w/ current=%d, red=%d, green=%d, blue=%d\n", moduleConfig.ambient_lighting.current, moduleConfig.ambient_lighting.red, moduleConfig.ambient_lighting.green, moduleConfig.ambient_lighting.blue); +#endif +#ifdef UNPHONE + unphone.rgb(moduleConfig.ambient_lighting.red, moduleConfig.ambient_lighting.green, moduleConfig.ambient_lighting.blue); + LOG_DEBUG("Initializing Ambient lighting w/ red=%d, green=%d, blue=%d\n", moduleConfig.ambient_lighting.red, + moduleConfig.ambient_lighting.green, moduleConfig.ambient_lighting.blue); #endif } }; diff --git a/src/detect/ScanI2C.h b/src/detect/ScanI2C.h index c8fcfee10..b4341bcc0 100644 --- a/src/detect/ScanI2C.h +++ b/src/detect/ScanI2C.h @@ -41,9 +41,8 @@ class ScanI2C BQ24295, LSM6DS3, TCA9555, -#ifdef HAS_NCP5623 + RGBLED_CA, NCP5623, -#endif } DeviceType; // typedef uint8_t DeviceAddress; diff --git a/src/main.cpp b/src/main.cpp index 744fda4de..4b3212f5f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -494,11 +494,15 @@ void setup() * "found". */ -// Only one supported RGB LED currently +// Only one supported I2C RGB LED currently (plus common anode RGB LED used by the unPhone) #ifdef HAS_NCP5623 rgb_found = i2cScanner->find(ScanI2C::DeviceType::NCP5623); #endif +#ifdef UNPHONE + rgb_found.type = ScanI2C::DeviceType::RGBLED_CA; +#endif + #if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) auto acc_info = i2cScanner->firstAccelerometer(); accelerometer_found = acc_info.type != ScanI2C::DeviceType::NONE ? acc_info.address : accelerometer_found; @@ -590,6 +594,20 @@ void setup() if (config.display.oled != meshtastic_Config_DisplayConfig_OledType_OLED_AUTO) screen_model = config.display.oled; +#ifdef UNPHONE + // initialise IO expander with pinmodes + Wire.beginTransmission(0x26); + Wire.write(0x06); + Wire.write(0x7A); + Wire.write(0xDD); + Wire.endTransmission(); + Wire.beginTransmission(0x26); + Wire.write(0x02); + Wire.write(0x04); // Backlight on + Wire.write(0x22); // G&B LEDs off + Wire.endTransmission(); +#endif + #if defined(USE_SH1107) screen_model = meshtastic_Config_DisplayConfig_OledType_OLED_SH1107; // set dimension of 128x128 display_geometry = GEOMETRY_128_128; diff --git a/src/modules/ExternalNotificationModule.cpp b/src/modules/ExternalNotificationModule.cpp index a38b231af..be8fd2be2 100644 --- a/src/modules/ExternalNotificationModule.cpp +++ b/src/modules/ExternalNotificationModule.cpp @@ -36,6 +36,18 @@ uint8_t brightnessValues[] = {0, 10, 20, 30, 50, 90, 160, 170}; // blue gets mul bool ascending = true; #endif +#ifdef UNPHONE +#include "unPhone.h" +extern unPhone unphone; + +uint8_t red = 0; +uint8_t green = 0; +uint8_t blue = 0; +uint8_t colorState = 1; +const uint8_t duration = 15; +uint8_t counter = 0; +#endif + #ifndef PIN_BUZZER #define PIN_BUZZER false #endif @@ -72,7 +84,6 @@ int32_t ExternalNotificationModule::runOnce() if (!moduleConfig.external_notification.enabled) { return INT32_MAX; // we don't need this thread here... } else { - bool isPlaying = rtttl::isPlaying(); #ifdef HAS_I2S isPlaying = rtttl::isPlaying() || audioThread->isPlaying(); @@ -133,6 +144,25 @@ int32_t ExternalNotificationModule::runOnce() } #endif +#ifdef UNPHONE + if (rgb_found.type == ScanI2C::RGBLED_CA) { + red = colorState & 4; // Red enabled on colorState = 4,5,6,7 + green = colorState & 2; // Green enabled on colorState = 2,3,6,7 + blue = colorState & 1; // Blue enabled on colorState = 1,3,5,7 + unphone.rgb(red, green, blue); + LOG_DEBUG("RGB runOnce: %i, %i, %i\n", red, green, blue); + + counter++; // tick on + if (counter > duration) { + counter = 0; + colorState++; // next color + if (colorState > 7) { + colorState = 1; + } + } + } +#endif + #ifdef T_WATCH_S3 drv.go(); #endif @@ -197,6 +227,11 @@ void ExternalNotificationModule::setExternalOn(uint8_t index) rgb.setColor(red, green, blue); } #endif +#ifdef UNPHONE + if (rgb_found.type == ScanI2C::RGBLED_CA) { + unphone.rgb(red, green, blue); + } +#endif #ifdef T_WATCH_S3 drv.go(); #endif @@ -230,6 +265,14 @@ void ExternalNotificationModule::setExternalOff(uint8_t index) rgb.setColor(red, green, blue); } #endif +#ifdef UNPHONE + if (rgb_found.type == ScanI2C::RGBLED_CA) { + red = 0; + green = 0; + blue = 0; + unphone.rgb(red, green, blue); + } +#endif #ifdef T_WATCH_S3 drv.stop(); #endif