rgb led support for unPhone

pull/3647/head
Gareth Coleman 2024-04-16 21:28:12 +01:00
rodzic 385d7296fe
commit 8a3322fbcb
4 zmienionych plików z 86 dodań i 7 usunięć

Wyświetl plik

@ -5,6 +5,11 @@
NCP5623 rgb; NCP5623 rgb;
#endif #endif
#ifdef UNPHONE
#include "unPhone.h"
extern unPhone unphone;
#endif
namespace concurrency namespace concurrency
{ {
class AmbientLightingThread : public concurrency::OSThread 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.green = (myNodeInfo.my_node_num & 0x00FF00) >> 8;
// moduleConfig.ambient_lighting.blue = myNodeInfo.my_node_num & 0x0000FF; // moduleConfig.ambient_lighting.blue = myNodeInfo.my_node_num & 0x0000FF;
#ifdef HAS_NCP5623
_type = type; _type = type;
#ifdef HAS_NCP5623
if (_type == ScanI2C::DeviceType::NONE) { if (_type == ScanI2C::DeviceType::NONE) {
LOG_DEBUG("AmbientLightingThread disabling due to no RGB leds found on I2C bus\n"); LOG_DEBUG("AmbientLightingThread disabling due to no RGB leds found on I2C bus\n");
disable(); disable();
@ -37,14 +42,23 @@ class AmbientLightingThread : public concurrency::OSThread
rgb.begin(); rgb.begin();
setLighting(); 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 #endif
} }
protected: protected:
int32_t runOnce() override int32_t runOnce() override
{ {
#ifdef HAS_NCP5623 #if defined(HAS_NCP5623) || defined(UNPHONE)
if (_type == ScanI2C::NCP5623 && moduleConfig.ambient_lighting.led_state) { if ((_type == ScanI2C::NCP5623 || _type == ScanI2C::RGBLED_CA) && moduleConfig.ambient_lighting.led_state) {
setLighting(); setLighting();
return 30000; // 30 seconds to reset from any animations that may have been running from Ext. Notification return 30000; // 30 seconds to reset from any animations that may have been running from Ext. Notification
} else { } 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", 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.current, moduleConfig.ambient_lighting.red, moduleConfig.ambient_lighting.green,
moduleConfig.ambient_lighting.blue); 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 #endif
} }
}; };

Wyświetl plik

@ -41,9 +41,8 @@ class ScanI2C
BQ24295, BQ24295,
LSM6DS3, LSM6DS3,
TCA9555, TCA9555,
#ifdef HAS_NCP5623 RGBLED_CA,
NCP5623, NCP5623,
#endif
} DeviceType; } DeviceType;
// typedef uint8_t DeviceAddress; // typedef uint8_t DeviceAddress;

Wyświetl plik

@ -494,11 +494,15 @@ void setup()
* "found". * "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 #ifdef HAS_NCP5623
rgb_found = i2cScanner->find(ScanI2C::DeviceType::NCP5623); rgb_found = i2cScanner->find(ScanI2C::DeviceType::NCP5623);
#endif #endif
#ifdef UNPHONE
rgb_found.type = ScanI2C::DeviceType::RGBLED_CA;
#endif
#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) #if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL)
auto acc_info = i2cScanner->firstAccelerometer(); auto acc_info = i2cScanner->firstAccelerometer();
accelerometer_found = acc_info.type != ScanI2C::DeviceType::NONE ? acc_info.address : accelerometer_found; 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) if (config.display.oled != meshtastic_Config_DisplayConfig_OledType_OLED_AUTO)
screen_model = config.display.oled; 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) #if defined(USE_SH1107)
screen_model = meshtastic_Config_DisplayConfig_OledType_OLED_SH1107; // set dimension of 128x128 screen_model = meshtastic_Config_DisplayConfig_OledType_OLED_SH1107; // set dimension of 128x128
display_geometry = GEOMETRY_128_128; display_geometry = GEOMETRY_128_128;

Wyświetl plik

@ -36,6 +36,18 @@ uint8_t brightnessValues[] = {0, 10, 20, 30, 50, 90, 160, 170}; // blue gets mul
bool ascending = true; bool ascending = true;
#endif #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 #ifndef PIN_BUZZER
#define PIN_BUZZER false #define PIN_BUZZER false
#endif #endif
@ -72,7 +84,6 @@ int32_t ExternalNotificationModule::runOnce()
if (!moduleConfig.external_notification.enabled) { if (!moduleConfig.external_notification.enabled) {
return INT32_MAX; // we don't need this thread here... return INT32_MAX; // we don't need this thread here...
} else { } else {
bool isPlaying = rtttl::isPlaying(); bool isPlaying = rtttl::isPlaying();
#ifdef HAS_I2S #ifdef HAS_I2S
isPlaying = rtttl::isPlaying() || audioThread->isPlaying(); isPlaying = rtttl::isPlaying() || audioThread->isPlaying();
@ -133,6 +144,25 @@ int32_t ExternalNotificationModule::runOnce()
} }
#endif #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 #ifdef T_WATCH_S3
drv.go(); drv.go();
#endif #endif
@ -197,6 +227,11 @@ void ExternalNotificationModule::setExternalOn(uint8_t index)
rgb.setColor(red, green, blue); rgb.setColor(red, green, blue);
} }
#endif #endif
#ifdef UNPHONE
if (rgb_found.type == ScanI2C::RGBLED_CA) {
unphone.rgb(red, green, blue);
}
#endif
#ifdef T_WATCH_S3 #ifdef T_WATCH_S3
drv.go(); drv.go();
#endif #endif
@ -230,6 +265,14 @@ void ExternalNotificationModule::setExternalOff(uint8_t index)
rgb.setColor(red, green, blue); rgb.setColor(red, green, blue);
} }
#endif #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 #ifdef T_WATCH_S3
drv.stop(); drv.stop();
#endif #endif