Merge remote-tracking branch 'origin/ac_main' into mdev
This commit is contained in:
@@ -55,8 +55,8 @@ Also, while in the `platformio.ini` file, you must change the environment setup
|
||||
|
||||
Comment out the line described below:
|
||||
```ini
|
||||
# Travis CI binaries (comment this out when building for single board)
|
||||
; default_envs = travis_esp8266, esp01, esp01_1m_ota, travis_esp32
|
||||
# Release binaries
|
||||
; default_envs = nodemcuv2, esp8266_2m, esp01_1m_full, esp32dev, esp32_eth, esp32s2_saola, esp32c3
|
||||
```
|
||||
and UNCOMMENT the following line in the 'Single binaries' section:
|
||||
```ini
|
||||
|
||||
@@ -1921,16 +1921,16 @@ class AudioReactive : public Usermod {
|
||||
oappend(SET_F("addOption(dd,'Send',1);"));
|
||||
oappend(SET_F("addOption(dd,'Receive',2);"));
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:type',1,'<i>requires reboot!</i>');")); // 0 is field type, 1 is actual field
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',0,'I2S Serial Data', '<i><span class=\"h\">sd/data/dout</span></i>');"));
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',1,'I2S L/R Clock','<i><span class=\"h\">ws/clk/lrck</span></i>');"));
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',2,'I2S Serial Clock','<i>sck/bclk</i>');"));
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',0,'<i>sd/data/dout</i>','I2S SD');"));
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',1,'<i>ws/clk/lrck</i>','I2S WS');"));
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',2,'<i>sck/bclk</i>','I2S SCK');"));
|
||||
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',3,'I2S Master CLK','<i>only use -1, 0, 1 or 3</i>');"));
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',3,'<i>only use -1, 0, 1 or 3</i>','I2S MCLK');"));
|
||||
#else
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',3,'', 'I2S Master CLK');"));
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',3,'<i>master clock</i>','I2S MCLK');"));
|
||||
#endif
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',4,'', 'I2C SDA');"));
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',5,'', 'I2C SCL');"));
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',4,'','I2C SDA');"));
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',5,'','I2C SCL');"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
27
usermods/pwm_outputs/readme.md
Normal file
27
usermods/pwm_outputs/readme.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# PWM outputs
|
||||
|
||||
v2 Usermod to add generic PWM outputs to WLED. Usermode could be used to control servo motors, LED brightness or any other device controlled by PWM signal.
|
||||
|
||||
## Installation
|
||||
|
||||
Add the compile-time option `-D USERMOD_PWM_OUTPUTS` to your `platformio.ini` (or `platformio_override.ini`). By default upt to 3 PWM outputs could be configured, to increase that limit add build argument `-D USERMOD_PWM_OUTPUT_PINS=10` (replace 10 by desired amount).
|
||||
|
||||
Currently only ESP32 is supported.
|
||||
|
||||
## Configuration
|
||||
|
||||
By default PWM outputs are disabled, navigate to Usermods settings and configure desired PWM pins and frequencies.
|
||||
|
||||
## Usage
|
||||
|
||||
If PWM output is configured, it starts to publish its duty cycle value (0-1) both to state JSON and to info JSON (visible in UI info panel). To set PWM duty cycle, use JSON api (over HTTP or over Serial)
|
||||
|
||||
```json
|
||||
{
|
||||
"pwm": {
|
||||
"0": {"duty": 0.1},
|
||||
"1": {"duty": 0.2},
|
||||
...
|
||||
}
|
||||
}
|
||||
```
|
||||
221
usermods/pwm_outputs/usermod_pwm_outputs.h
Normal file
221
usermods/pwm_outputs/usermod_pwm_outputs.h
Normal file
@@ -0,0 +1,221 @@
|
||||
#pragma once
|
||||
#include "wled.h"
|
||||
|
||||
#ifndef ESP32
|
||||
#error This usermod does not support the ESP8266.
|
||||
#endif
|
||||
|
||||
#ifndef USERMOD_PWM_OUTPUT_PINS
|
||||
#define USERMOD_PWM_OUTPUT_PINS 3
|
||||
#endif
|
||||
|
||||
|
||||
class PwmOutput {
|
||||
public:
|
||||
|
||||
void open(int8_t pin, uint32_t freq) {
|
||||
|
||||
if (enabled_) {
|
||||
if (pin == pin_ && freq == freq_) {
|
||||
return; // PWM output is already open
|
||||
} else {
|
||||
close(); // Config has changed, close and reopen
|
||||
}
|
||||
}
|
||||
|
||||
pin_ = pin;
|
||||
freq_ = freq;
|
||||
if (pin_ < 0)
|
||||
return;
|
||||
|
||||
DEBUG_PRINTF("pwm_output[%d]: setup to freq %d\n", pin_, freq_);
|
||||
if (!pinManager.allocatePin(pin_, true, PinOwner::UM_PWM_OUTPUTS))
|
||||
return;
|
||||
|
||||
channel_ = pinManager.allocateLedc(1);
|
||||
if (channel_ == 255) {
|
||||
DEBUG_PRINTF("pwm_output[%d]: failed to quire ledc\n", pin_);
|
||||
pinManager.deallocatePin(pin_, PinOwner::UM_PWM_OUTPUTS);
|
||||
return;
|
||||
}
|
||||
|
||||
ledcSetup(channel_, freq_, bit_depth_);
|
||||
ledcAttachPin(pin_, channel_);
|
||||
DEBUG_PRINTF("pwm_output[%d]: init successful\n", pin_);
|
||||
enabled_ = true;
|
||||
}
|
||||
|
||||
void close() {
|
||||
DEBUG_PRINTF("pwm_output[%d]: close\n", pin_);
|
||||
if (!enabled_)
|
||||
return;
|
||||
pinManager.deallocatePin(pin_, PinOwner::UM_PWM_OUTPUTS);
|
||||
if (channel_ != 255)
|
||||
pinManager.deallocateLedc(channel_, 1);
|
||||
channel_ = 255;
|
||||
duty_ = 0.0f;
|
||||
enabled_ = false;
|
||||
}
|
||||
|
||||
void setDuty(const float duty) {
|
||||
DEBUG_PRINTF("pwm_output[%d]: set duty %f\n", pin_, duty);
|
||||
if (!enabled_)
|
||||
return;
|
||||
duty_ = min(1.0f, max(0.0f, duty));
|
||||
const uint32_t value = static_cast<uint32_t>((1 << bit_depth_) * duty_);
|
||||
ledcWrite(channel_, value);
|
||||
}
|
||||
|
||||
void setDuty(const uint16_t duty) {
|
||||
setDuty(static_cast<float>(duty) / 65535.0f);
|
||||
}
|
||||
|
||||
bool isEnabled() const {
|
||||
return enabled_;
|
||||
}
|
||||
|
||||
void addToJsonState(JsonObject& pwmState) const {
|
||||
pwmState[F("duty")] = duty_;
|
||||
}
|
||||
|
||||
void readFromJsonState(JsonObject& pwmState) {
|
||||
if (pwmState.isNull()) {
|
||||
return;
|
||||
}
|
||||
float duty;
|
||||
if (getJsonValue(pwmState[F("duty")], duty)) {
|
||||
setDuty(duty);
|
||||
}
|
||||
}
|
||||
|
||||
void addToJsonInfo(JsonObject& user) const {
|
||||
if (!enabled_)
|
||||
return;
|
||||
char buffer[12];
|
||||
sprintf_P(buffer, PSTR("PWM pin %d"), pin_);
|
||||
JsonArray data = user.createNestedArray(buffer);
|
||||
data.add(1e2f * duty_);
|
||||
data.add(F("%"));
|
||||
}
|
||||
|
||||
void addToConfig(JsonObject& pwmConfig) const {
|
||||
pwmConfig[F("pin")] = pin_;
|
||||
pwmConfig[F("freq")] = freq_;
|
||||
}
|
||||
|
||||
bool readFromConfig(JsonObject& pwmConfig) {
|
||||
if (pwmConfig.isNull())
|
||||
return false;
|
||||
|
||||
bool configComplete = true;
|
||||
int8_t newPin = pin_;
|
||||
uint32_t newFreq = freq_;
|
||||
configComplete &= getJsonValue(pwmConfig[F("pin")], newPin);
|
||||
configComplete &= getJsonValue(pwmConfig[F("freq")], newFreq);
|
||||
|
||||
open(newPin, newFreq);
|
||||
|
||||
return configComplete;
|
||||
}
|
||||
|
||||
private:
|
||||
int8_t pin_ {-1};
|
||||
uint32_t freq_ {50};
|
||||
static const uint8_t bit_depth_ {12};
|
||||
uint8_t channel_ {255};
|
||||
float duty_ {0.0f};
|
||||
bool enabled_ {false};
|
||||
};
|
||||
|
||||
|
||||
class PwmOutputsUsermod : public Usermod {
|
||||
public:
|
||||
|
||||
static const char USERMOD_NAME[];
|
||||
static const char PWM_STATE_NAME[];
|
||||
|
||||
void setup() {
|
||||
// By default all PWM outputs are disabled, no setup do be done
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
||||
|
||||
void addToJsonState(JsonObject& root) {
|
||||
JsonObject pwmStates = root.createNestedObject(PWM_STATE_NAME);
|
||||
for (int i = 0; i < USERMOD_PWM_OUTPUT_PINS; i++) {
|
||||
const PwmOutput& pwm = pwms_[i];
|
||||
if (!pwm.isEnabled())
|
||||
continue;
|
||||
char buffer[4];
|
||||
sprintf_P(buffer, PSTR("%d"), i);
|
||||
JsonObject pwmState = pwmStates.createNestedObject(buffer);
|
||||
pwm.addToJsonState(pwmState);
|
||||
}
|
||||
}
|
||||
|
||||
void readFromJsonState(JsonObject& root) {
|
||||
JsonObject pwmStates = root[PWM_STATE_NAME];
|
||||
if (pwmStates.isNull())
|
||||
return;
|
||||
|
||||
for (int i = 0; i < USERMOD_PWM_OUTPUT_PINS; i++) {
|
||||
PwmOutput& pwm = pwms_[i];
|
||||
if (!pwm.isEnabled())
|
||||
continue;
|
||||
char buffer[4];
|
||||
sprintf_P(buffer, PSTR("%d"), i);
|
||||
JsonObject pwmState = pwmStates[buffer];
|
||||
pwm.readFromJsonState(pwmState);
|
||||
}
|
||||
}
|
||||
|
||||
void addToJsonInfo(JsonObject& root) {
|
||||
JsonObject user = root[F("u")];
|
||||
if (user.isNull())
|
||||
user = root.createNestedObject(F("u"));
|
||||
|
||||
for (int i = 0; i < USERMOD_PWM_OUTPUT_PINS; i++) {
|
||||
const PwmOutput& pwm = pwms_[i];
|
||||
pwm.addToJsonInfo(user);
|
||||
}
|
||||
}
|
||||
|
||||
void addToConfig(JsonObject& root) {
|
||||
JsonObject top = root.createNestedObject(USERMOD_NAME);
|
||||
for (int i = 0; i < USERMOD_PWM_OUTPUT_PINS; i++) {
|
||||
const PwmOutput& pwm = pwms_[i];
|
||||
char buffer[8];
|
||||
sprintf_P(buffer, PSTR("PWM %d"), i);
|
||||
JsonObject pwmConfig = top.createNestedObject(buffer);
|
||||
pwm.addToConfig(pwmConfig);
|
||||
}
|
||||
}
|
||||
|
||||
bool readFromConfig(JsonObject& root) {
|
||||
JsonObject top = root[USERMOD_NAME];
|
||||
if (top.isNull())
|
||||
return false;
|
||||
|
||||
bool configComplete = true;
|
||||
for (int i = 0; i < USERMOD_PWM_OUTPUT_PINS; i++) {
|
||||
PwmOutput& pwm = pwms_[i];
|
||||
char buffer[8];
|
||||
sprintf_P(buffer, PSTR("PWM %d"), i);
|
||||
JsonObject pwmConfig = top[buffer];
|
||||
configComplete &= pwm.readFromConfig(pwmConfig);
|
||||
}
|
||||
return configComplete;
|
||||
}
|
||||
|
||||
uint16_t getId() {
|
||||
return USERMOD_ID_PWM_OUTPUTS;
|
||||
}
|
||||
|
||||
private:
|
||||
PwmOutput pwms_[USERMOD_PWM_OUTPUT_PINS];
|
||||
|
||||
};
|
||||
|
||||
const char PwmOutputsUsermod::USERMOD_NAME[] PROGMEM = "PwmOutputs";
|
||||
const char PwmOutputsUsermod::PWM_STATE_NAME[] PROGMEM = "pwm";
|
||||
@@ -1036,11 +1036,11 @@ class FourLineDisplayUsermod : public Usermod {
|
||||
oappend(SET_F("addOption(dd,'SSD1305 128x64',5);"));
|
||||
oappend(SET_F("addOption(dd,'SSD1306 SPI',6);"));
|
||||
oappend(SET_F("addOption(dd,'SSD1306 SPI 128x64',7);"));
|
||||
oappend(SET_F("addInfo('4LineDisplay:pin[]',0,'I2C/SPI CLK','<i>-1 use global</i>');"));
|
||||
oappend(SET_F("addInfo('4LineDisplay:pin[]',1,'I2C/SPI DTA','<i>-1 use global</i>');"));
|
||||
oappend(SET_F("addInfo('4LineDisplay:pin[]',2,'SPI CS',' ');"));
|
||||
oappend(SET_F("addInfo('4LineDisplay:pin[]',3,'SPI DC',' ');"));
|
||||
oappend(SET_F("addInfo('4LineDisplay:pin[]',4,'SPI RST',' ');"));
|
||||
oappend(SET_F("addInfo('4LineDisplay:pin[]',0,'<i>-1 use global</i>','I2C/SPI CLK');"));
|
||||
oappend(SET_F("addInfo('4LineDisplay:pin[]',1,'<i>-1 use global</i>','I2C/SPI DTA');"));
|
||||
oappend(SET_F("addInfo('4LineDisplay:pin[]',2,'','SPI CS');"));
|
||||
oappend(SET_F("addInfo('4LineDisplay:pin[]',3,'','SPI DC');"));
|
||||
oappend(SET_F("addInfo('4LineDisplay:pin[]',4,'','SPI RST');"));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -760,7 +760,7 @@ public:
|
||||
StaticJsonDocument<64> root;
|
||||
char str[64] = { '\0' };
|
||||
sprintf_P(str, PSTR("%d~%d~%s"), presetLow, presetHigh, increase?"":"-");
|
||||
root[F("ps")] = str;
|
||||
root["ps"] = str;
|
||||
deserializeState(root.as<JsonObject>(), CALL_MODE_BUTTON_PRESET);
|
||||
/*
|
||||
String apireq = F("win&PL=~");
|
||||
|
||||
Reference in New Issue
Block a user