mirror of
https://github.com/meshtastic/firmware.git
synced 2026-01-04 09:02:21 +00:00
Initial support for RadioMaster Bandit. (#4523)
* Initial support for RadioMaster Bandit. * Different lighting can be made for Button 1 & 2 on the Bandit. Changes to AmbientLighting will turn off af shutdown(). * Trunk * Trunk again.
This commit is contained in:
committed by
Kevin Hester
parent
9b2ef971c2
commit
de41a054b0
@@ -1,3 +1,4 @@
|
||||
#include "Observer.h"
|
||||
#include "configuration.h"
|
||||
|
||||
#ifdef HAS_NCP5623
|
||||
@@ -22,10 +23,18 @@ class AmbientLightingThread : public concurrency::OSThread
|
||||
public:
|
||||
explicit AmbientLightingThread(ScanI2C::DeviceType type) : OSThread("AmbientLightingThread")
|
||||
{
|
||||
notifyDeepSleepObserver.observe(¬ifyDeepSleep); // Let us know when shutdown() is issued.
|
||||
|
||||
// Enables Ambient Lighting by default if conditions are meet.
|
||||
#if defined(HAS_NCP5623) || defined(RGBLED_RED) || defined(HAS_NEOPIXEL) || defined(UNPHONE)
|
||||
#ifdef ENABLE_AMBIENTLIGHTING
|
||||
moduleConfig.ambient_lighting.led_state = true;
|
||||
#endif
|
||||
#endif
|
||||
// Uncomment to test module
|
||||
// moduleConfig.ambient_lighting.led_state = true;
|
||||
// moduleConfig.ambient_lighting.current = 10;
|
||||
// // Default to a color based on our node number
|
||||
// Default to a color based on our node number
|
||||
// moduleConfig.ambient_lighting.red = (myNodeInfo.my_node_num & 0xFF0000) >> 16;
|
||||
// moduleConfig.ambient_lighting.green = (myNodeInfo.my_node_num & 0x00FF00) >> 8;
|
||||
// moduleConfig.ambient_lighting.blue = myNodeInfo.my_node_num & 0x0000FF;
|
||||
@@ -82,9 +91,46 @@ class AmbientLightingThread : public concurrency::OSThread
|
||||
return disable();
|
||||
}
|
||||
|
||||
// When shutdown() is issued, setLightingOff will be called.
|
||||
CallbackObserver<AmbientLightingThread, void *> notifyDeepSleepObserver =
|
||||
CallbackObserver<AmbientLightingThread, void *>(this, &AmbientLightingThread::setLightingOff);
|
||||
|
||||
private:
|
||||
ScanI2C::DeviceType _type = ScanI2C::DeviceType::NONE;
|
||||
|
||||
// Turn RGB lighting off, is used in junction to shutdown()
|
||||
int setLightingOff(void *unused)
|
||||
{
|
||||
#ifdef HAS_NCP5623
|
||||
rgb.setCurrent(0);
|
||||
rgb.setRed(0);
|
||||
rgb.setGreen(0);
|
||||
rgb.setBlue(0);
|
||||
LOG_INFO("Turn Off NCP5623 Ambient lighting.\n");
|
||||
#endif
|
||||
#ifdef HAS_NEOPIXEL
|
||||
pixels.clear();
|
||||
pixels.show();
|
||||
LOG_INFO("Turn Off NeoPixel Ambient lighting.\n");
|
||||
#endif
|
||||
#ifdef RGBLED_CA
|
||||
analogWrite(RGBLED_RED, 255 - 0);
|
||||
analogWrite(RGBLED_GREEN, 255 - 0);
|
||||
analogWrite(RGBLED_BLUE, 255 - 0);
|
||||
LOG_INFO("Turn Off Ambient lighting RGB Common Anode.\n");
|
||||
#elif defined(RGBLED_RED)
|
||||
analogWrite(RGBLED_RED, 0);
|
||||
analogWrite(RGBLED_GREEN, 0);
|
||||
analogWrite(RGBLED_BLUE, 0);
|
||||
LOG_INFO("Turn Off Ambient lighting RGB Common Cathode.\n");
|
||||
#endif
|
||||
#ifdef UNPHONE
|
||||
unphone.rgb(0, 0, 0);
|
||||
LOG_INFO("Turn Off unPhone Ambient lighting.\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
void setLighting()
|
||||
{
|
||||
#ifdef HAS_NCP5623
|
||||
@@ -100,6 +146,17 @@ class AmbientLightingThread : public concurrency::OSThread
|
||||
pixels.fill(pixels.Color(moduleConfig.ambient_lighting.red, moduleConfig.ambient_lighting.green,
|
||||
moduleConfig.ambient_lighting.blue),
|
||||
0, NEOPIXEL_COUNT);
|
||||
|
||||
// RadioMaster Bandit has addressable LED at the two buttons
|
||||
// this allow us to set different lighting for them in variant.h file.
|
||||
#ifdef RADIOMASTER_900_BANDIT
|
||||
#if defined(BUTTON1_COLOR) && defined(BUTTON1_COLOR_INDEX)
|
||||
pixels.fill(BUTTON1_COLOR, BUTTON1_COLOR_INDEX, 1);
|
||||
#endif
|
||||
#if defined(BUTTON2_COLOR) && defined(BUTTON2_COLOR_INDEX)
|
||||
pixels.fill(BUTTON2_COLOR, BUTTON1_COLOR_INDEX, 1);
|
||||
#endif
|
||||
#endif
|
||||
pixels.show();
|
||||
LOG_DEBUG("Initializing NeoPixel Ambient lighting w/ brightness(current)=%d, red=%d, green=%d, blue=%d\n",
|
||||
moduleConfig.ambient_lighting.current, moduleConfig.ambient_lighting.red, moduleConfig.ambient_lighting.green,
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
// In theory up to 27 dBm is possible, but the modules installed in most radios can cope with a max of 20. So BIG WARNING
|
||||
// if you set power to something higher than 17 or 20 you might fry your board.
|
||||
|
||||
#ifdef RADIOMASTER_900_BANDIT_NANO
|
||||
#if defined(RADIOMASTER_900_BANDIT_NANO) || defined(RADIOMASTER_900_BANDIT)
|
||||
// Structure to hold DAC and DB values
|
||||
typedef struct {
|
||||
uint8_t dac;
|
||||
@@ -40,12 +40,23 @@ DACDB getDACandDB(uint8_t dbm)
|
||||
static const struct {
|
||||
uint8_t dbm;
|
||||
DACDB values;
|
||||
} dbmToDACDB[] = {
|
||||
}
|
||||
#ifdef RADIOMASTER_900_BANDIT_NANO
|
||||
dbmToDACDB[] = {
|
||||
{20, {168, 2}}, // 100mW
|
||||
{24, {148, 6}}, // 250mW
|
||||
{27, {128, 9}}, // 500mW
|
||||
{30, {90, 12}} // 1000mW
|
||||
};
|
||||
#endif
|
||||
#ifdef RADIOMASTER_900_BANDIT
|
||||
dbmToDACDB[] = {
|
||||
{20, {165, 2}}, // 100mW
|
||||
{24, {155, 6}}, // 250mW
|
||||
{27, {142, 9}}, // 500mW
|
||||
{30, {110, 10}} // 1000mW
|
||||
};
|
||||
#endif
|
||||
const int numValues = sizeof(dbmToDACDB) / sizeof(dbmToDACDB[0]);
|
||||
|
||||
// Find the interval dbm falls within and interpolate
|
||||
@@ -56,7 +67,12 @@ DACDB getDACandDB(uint8_t dbm)
|
||||
}
|
||||
|
||||
// Return a default value if no match is found and default to 100mW
|
||||
#ifdef RADIOMASTER_900_BANDIT_NANO
|
||||
DACDB defaultValue = {168, 2};
|
||||
#endif
|
||||
#ifdef RADIOMASTER_900_BANDIT
|
||||
DACDB defaultValue = {165, 2};
|
||||
#endif
|
||||
return defaultValue;
|
||||
}
|
||||
#endif
|
||||
@@ -95,7 +111,7 @@ bool RF95Interface::init()
|
||||
{
|
||||
RadioLibInterface::init();
|
||||
|
||||
#ifdef RADIOMASTER_900_BANDIT_NANO
|
||||
#if defined(RADIOMASTER_900_BANDIT_NANO) || defined(RADIOMASTER_900_BANDIT)
|
||||
// DAC and DB values based on dBm using interpolation
|
||||
DACDB dacDbValues = getDACandDB(power);
|
||||
int8_t powerDAC = dacDbValues.dac;
|
||||
@@ -117,7 +133,7 @@ bool RF95Interface::init()
|
||||
// enable PA
|
||||
#ifdef RF95_PA_EN
|
||||
#if defined(RF95_PA_DAC_EN)
|
||||
#ifdef RADIOMASTER_900_BANDIT_NANO
|
||||
#if defined(RADIOMASTER_900_BANDIT_NANO) || defined(RADIOMASTER_900_BANDIT)
|
||||
// Use calculated DAC value
|
||||
dacWrite(RF95_PA_EN, powerDAC);
|
||||
#else
|
||||
@@ -163,7 +179,7 @@ bool RF95Interface::init()
|
||||
LOG_INFO("Frequency set to %f\n", getFreq());
|
||||
LOG_INFO("Bandwidth set to %f\n", bw);
|
||||
LOG_INFO("Power output set to %d\n", power);
|
||||
#ifdef RADIOMASTER_900_BANDIT_NANO
|
||||
#if defined(RADIOMASTER_900_BANDIT_NANO) || defined(RADIOMASTER_900_BANDIT)
|
||||
LOG_INFO("DAC output set to %d\n", powerDAC);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -152,6 +152,8 @@
|
||||
#define HW_VENDOR meshtastic_HardwareModel_WIPHONE
|
||||
#elif defined(RADIOMASTER_900_BANDIT_NANO)
|
||||
#define HW_VENDOR meshtastic_HardwareModel_RADIOMASTER_900_BANDIT_NANO
|
||||
#elif defined(RADIOMASTER_900_BANDIT)
|
||||
#define HW_VENDOR meshtastic_HardwareModel_RADIOMASTER_900_BANDIT
|
||||
#elif defined(HELTEC_CAPSULE_SENSOR_V3)
|
||||
#define HW_VENDOR meshtastic_HardwareModel_HELTEC_CAPSULE_SENSOR_V3
|
||||
#elif defined(HELTEC_VISION_MASTER_T190)
|
||||
|
||||
Reference in New Issue
Block a user