RAK14001 RGB LED support (#2464)

* WIP

* WIP

* Moved it

* More random strobey behavior

* Guard to RAK4630 devices for now

* Oops

* Ship it
wio-e5
Ben Meadors 2023-05-06 07:17:40 -05:00 zatwierdzone przez GitHub
rodzic 7c9d0a022a
commit 09d48f659e
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
9 zmienionych plików z 56 dodań i 1 usunięć

Wyświetl plik

@ -124,6 +124,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define MPU6050_ADDR 0x68
#define LIS3DH_ADR 0x18
// -----------------------------------------------------------------------------
// LED
// -----------------------------------------------------------------------------
#define NCP5623_ADDR 0x38
// -----------------------------------------------------------------------------
// Security
// -----------------------------------------------------------------------------

Wyświetl plik

@ -33,6 +33,7 @@ class ScanI2C
PMSA0031,
MPU6050,
LIS3DH,
NCP5623,
} DeviceType;
// typedef uint8_t DeviceAddress;

Wyświetl plik

@ -213,6 +213,7 @@ void ScanI2CTwoWire::scanPort(I2CPort port)
break;
SCAN_SIMPLE_CASE(ST7567_ADDRESS, SCREEN_ST7567, "st7567 display found\n")
SCAN_SIMPLE_CASE(NCP5623_ADDR, NCP5623, "NCP5623 RGB LED found\n");
#ifdef HAS_PMU
SCAN_SIMPLE_CASE(XPOWERS_AXP192_AXP2101_ADDRESS, PMU_AXP192_AXP2101, "axp192/axp2101 PMU found\n")

Wyświetl plik

@ -100,6 +100,8 @@ uint8_t kb_model;
ScanI2C::DeviceAddress rtc_found = ScanI2C::ADDRESS_NONE;
// The I2C address of the Accelerometer (if found)
ScanI2C::DeviceAddress accelerometer_found = ScanI2C::ADDRESS_NONE;
// The I2C address of the RGB LED (if found)
ScanI2C::FoundDevice rgb_found = ScanI2C::FoundDevice(ScanI2C::DeviceType::NONE, ScanI2C::ADDRESS_NONE);
#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL)
ATECCX08A atecc;
@ -344,6 +346,8 @@ void setup()
* nodeTelemetrySensorsMap singleton. This wraps that logic in a temporary scope to declare the temporary field
* "found".
*/
// Only one supported RGB LED currently
rgb_found = i2cScanner->find(ScanI2C::DeviceType::NCP5623);
#if !defined(ARCH_PORTDUINO)
auto acc_info = i2cScanner->firstAccelerometer();

Wyświetl plik

@ -26,6 +26,7 @@ extern ScanI2C::DeviceAddress cardkb_found;
extern uint8_t kb_model;
extern ScanI2C::DeviceAddress rtc_found;
extern ScanI2C::DeviceAddress accelerometer_found;
extern ScanI2C::FoundDevice rgb_found;
extern bool eink_found;
extern bool pmu_found;

Wyświetl plik

@ -8,6 +8,17 @@
#include "mesh/generated/meshtastic/rtttl.pb.h"
#include <Arduino.h>
#include "main.h"
#ifdef RAK4630
#include <NCP5623.h>
NCP5623 rgb;
uint8_t red = 0;
uint8_t green = 0;
uint8_t blue = 0;
#endif
#ifndef PIN_BUZZER
#define PIN_BUZZER false
#endif
@ -73,6 +84,15 @@ int32_t ExternalNotificationModule::runOnce()
millis()) {
getExternal(2) ? setExternalOff(2) : setExternalOn(2);
}
#ifdef RAK4630
if (rgb_found.type == ScanI2C::NCP5623) {
green = (green + 50) % 255;
red = abs(red - green) % 255;
blue = abs(blue / red) % 255;
rgb.setColor(red, green, blue);
}
#endif
}
// now let the PWM buzzer play
@ -84,6 +104,7 @@ int32_t ExternalNotificationModule::runOnce()
rtttl::begin(config.device.buzzer_gpio, rtttlConfig.ringtone);
}
}
return 25;
}
}
@ -106,6 +127,11 @@ void ExternalNotificationModule::setExternalOn(uint8_t index)
digitalWrite(output, (moduleConfig.external_notification.active ? true : false));
break;
}
#ifdef RAK4630
if (rgb_found.type == ScanI2C::NCP5623) {
rgb.setColor(red, green, blue);
}
#endif
}
void ExternalNotificationModule::setExternalOff(uint8_t index)
@ -126,6 +152,15 @@ void ExternalNotificationModule::setExternalOff(uint8_t index)
digitalWrite(output, (moduleConfig.external_notification.active ? false : true));
break;
}
#ifdef RAK4630
if (rgb_found.type == ScanI2C::NCP5623) {
red = 0;
green = 0;
blue = 0;
rgb.setColor(red, green, blue);
}
#endif
}
bool ExternalNotificationModule::getExternal(uint8_t index)
@ -200,6 +235,12 @@ ExternalNotificationModule::ExternalNotificationModule()
LOG_INFO("Using Pin %i in PWM mode\n", config.device.buzzer_gpio);
}
}
#ifdef RAK4630
if (rgb_found.type == ScanI2C::NCP5623) {
rgb.begin();
rgb.setCurrent(10);
}
#endif
} else {
LOG_INFO("External Notification Module Disabled\n");
disable();
@ -300,7 +341,6 @@ ProcessMessage ExternalNotificationModule::handleReceived(const meshtastic_MeshP
nagCycleCutoff = millis() + moduleConfig.external_notification.output_ms;
}
}
setIntervalFromNow(0); // run once so we know if we should do something
}

Wyświetl plik

@ -9,6 +9,7 @@ lib_deps =
${networking_base.lib_deps}
melopero/Melopero RV3028@^1.1.0
https://github.com/RAKWireless/RAK13800-W5100S.git#1.0.2
rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2
debug_tool = jlink
; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm)
;upload_protocol = jlink

Wyświetl plik

@ -8,6 +8,7 @@ lib_deps =
${nrf52840_base.lib_deps}
zinggjm/GxEPD2@^1.4.9
melopero/Melopero RV3028@^1.1.0
rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2
debug_tool = jlink
; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm)
;upload_protocol = jlink

Wyświetl plik

@ -10,6 +10,7 @@ lib_deps =
${nrf52840_base.lib_deps}
zinggjm/GxEPD2@^1.5.1
melopero/Melopero RV3028@^1.1.0
rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2
debug_tool = jlink
; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm)
;upload_protocol = jlink