mirror of https://github.com/arendst/Tasmota.git
Merge branch 'arendst:development' into development
This commit is contained in:
commit
c7404049eb
|
@ -37,14 +37,23 @@ int WiFiClass32::getPhyMode() {
|
|||
int phy_mode = 0; // " BGNL"
|
||||
uint8_t protocol_bitmap;
|
||||
if (esp_wifi_get_protocol(WIFI_IF_STA, &protocol_bitmap) == ESP_OK) {
|
||||
if (protocol_bitmap & 1) { phy_mode = 1; } // 11b
|
||||
if (protocol_bitmap & 2) { phy_mode = 2; } // 11g
|
||||
if (protocol_bitmap & 4) { phy_mode = 3; } // 11n
|
||||
if (protocol_bitmap & 1) { phy_mode = WIFI_PHY_MODE_11B; } // 1 = 11b
|
||||
if (protocol_bitmap & 2) { phy_mode = WIFI_PHY_MODE_11G; } // 2 = 11bg
|
||||
if (protocol_bitmap & 4) { phy_mode = WIFI_PHY_MODE_11N; } // 3 = 11bgn
|
||||
if (protocol_bitmap & 8) { phy_mode = 4; } // Low rate
|
||||
}
|
||||
return phy_mode;
|
||||
}
|
||||
|
||||
bool WiFiClass32::setPhyMode(WiFiPhyMode_t mode) {
|
||||
uint8_t protocol_bitmap = WIFI_PROTOCOL_11B; // 1
|
||||
switch (mode) {
|
||||
case 3: protocol_bitmap |= WIFI_PROTOCOL_11N; // 4
|
||||
case 2: protocol_bitmap |= WIFI_PROTOCOL_11G; // 2
|
||||
}
|
||||
return (ESP_OK == esp_wifi_set_protocol(WIFI_IF_STA, protocol_bitmap));
|
||||
}
|
||||
|
||||
void WiFiClass32::wps_disable() {
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,11 @@
|
|||
#define WIFI_LIGHT_SLEEP 1
|
||||
#define WIFI_MODEM_SLEEP 2
|
||||
|
||||
typedef enum WiFiPhyMode
|
||||
{
|
||||
WIFI_PHY_MODE_11B = 1, WIFI_PHY_MODE_11G = 2, WIFI_PHY_MODE_11N = 3
|
||||
} WiFiPhyMode_t;
|
||||
|
||||
class WiFiClass32 : public WiFiClass
|
||||
{
|
||||
public:
|
||||
|
@ -41,6 +46,7 @@ public:
|
|||
}
|
||||
static void setSleepMode(int iSleepMode);
|
||||
static int getPhyMode();
|
||||
static bool setPhyMode(WiFiPhyMode_t mode);
|
||||
|
||||
static void wps_disable();
|
||||
static void setOutputPower(int n);
|
||||
|
|
|
@ -114,6 +114,7 @@ struct WIFI {
|
|||
uint8_t wifi_test_counter = 0;
|
||||
uint16_t save_data_counter = 0;
|
||||
uint8_t old_wificonfig = MAX_WIFI_OPTION; // means "nothing yet saved here"
|
||||
uint8_t phy_mode = 0;
|
||||
bool wifi_test_AP_TIMEOUT = false;
|
||||
bool wifi_Test_Restart = false;
|
||||
bool wifi_Test_Save_SSID2 = false;
|
||||
|
|
|
@ -2478,10 +2478,14 @@ void CmndWifi(void)
|
|||
WifiEnable();
|
||||
#endif
|
||||
}
|
||||
#ifdef ESP8266
|
||||
} else if ((XdrvMailbox.payload >= 2) && (XdrvMailbox.payload <= 4)) {
|
||||
WiFi.setPhyMode(WiFiPhyMode_t(XdrvMailbox.payload - 1)); // 1-B/2-BG/3-BGN
|
||||
// Wifi 2 = B
|
||||
// Wifi 3 = BG
|
||||
// Wifi 4 = BGN
|
||||
#ifdef ESP32
|
||||
Wifi.phy_mode = XdrvMailbox.payload - 1;
|
||||
#endif
|
||||
WiFi.setPhyMode(WiFiPhyMode_t(XdrvMailbox.payload - 1)); // 1-B/2-BG/3-BGN
|
||||
}
|
||||
Response_P(PSTR("{\"" D_JSON_WIFI "\":\"%s\",\"" D_JSON_WIFI_MODE "\":\"11%c\"}"), GetStateText(Settings->flag4.network_wifi), pgm_read_byte(&kWifiPhyMode[WiFi.getPhyMode() & 0x3]) );
|
||||
}
|
||||
|
|
|
@ -217,6 +217,11 @@ void WifiBegin(uint8_t flag, uint8_t channel)
|
|||
WiFiSetSleepMode();
|
||||
// if (WiFi.getPhyMode() != WIFI_PHY_MODE_11N) { WiFi.setPhyMode(WIFI_PHY_MODE_11N); } // B/G/N
|
||||
// if (WiFi.getPhyMode() != WIFI_PHY_MODE_11G) { WiFi.setPhyMode(WIFI_PHY_MODE_11G); } // B/G
|
||||
#ifdef ESP32
|
||||
if (Wifi.phy_mode) {
|
||||
WiFi.setPhyMode(WiFiPhyMode_t(Wifi.phy_mode)); // 1-B/2-BG/3-BGN
|
||||
}
|
||||
#endif
|
||||
if (!WiFi.getAutoConnect()) { WiFi.setAutoConnect(true); }
|
||||
// WiFi.setAutoReconnect(true);
|
||||
switch (flag) {
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#define XLGT_08 8
|
||||
|
||||
// Layout: Bits B[7:8]=10 (address selection identification bits), B[5:6] sleep mode if set to 00, B[0:4] Address selection
|
||||
#define BP5758D_ADDR_SLEEP 0x86 //10 00 0110: Sleep mode bits set (OUT1 gray-scale level setup selected, ignored by chip)
|
||||
#define BP5758D_ADDR_SLEEP 0x80 //10 00 xxxx: Set to sleep mode
|
||||
#define BP5758D_ADDR_SETUP 0x90 //10 01 0000: OUT1-5 enable/disable setup - used during init
|
||||
#define BP5758D_ADDR_OUT1_CR 0x91 //10 01 0001: OUT1 current range
|
||||
#define BP5758D_ADDR_OUT2_CR 0x92 //10 01 0010: OUT2 current range
|
||||
|
@ -44,6 +44,7 @@
|
|||
|
||||
// Output enabled (OUT1-5, represented by lower 5 bits)
|
||||
#define BP5758D_ENABLE_OUTPUTS_ALL 0x1F
|
||||
#define BP5758D_DISABLE_OUTPUTS_ALL 0x00
|
||||
|
||||
// Current values: Bit 6 to 0 represent 30mA, 32mA, 16mA, 8mA, 4mA, 2mA, 1mA respectively
|
||||
#define BP5758D_10MA 0x0A // 0 0001010
|
||||
|
@ -106,14 +107,25 @@ void Bp5758dStop(void) {
|
|||
/********************************************************************************************/
|
||||
|
||||
bool Bp5758dSetChannels(void) {
|
||||
static bool bIsSleeping = false; //Save sleep state of Lamp
|
||||
uint16_t *cur_col_10 = (uint16_t*)XdrvMailbox.command;
|
||||
|
||||
// If we receive 0 for all channels, we'll assume that the lightbulb is off, and activate BP5758d's sleep mode.
|
||||
if (cur_col_10[0]==0 && cur_col_10[1]==0 && cur_col_10[2]==0 && cur_col_10[3]==0 && cur_col_10[4]==0) {
|
||||
Bp5758dStart(BP5758D_ADDR_SETUP);
|
||||
Bp5758dWrite(BP5758D_DISABLE_OUTPUTS_ALL);
|
||||
Bp5758dStart(BP5758D_ADDR_SLEEP);
|
||||
Bp5758dStop();
|
||||
bIsSleeping = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (bIsSleeping) {
|
||||
bIsSleeping = false; //No need to run it every time a val gets changed
|
||||
Bp5758dStart(BP5758D_ADDR_SETUP); //Sleep mode gets disabled too since bits 5:6 get set to 01
|
||||
Bp5758dWrite(BP5758D_ENABLE_OUTPUTS_ALL); //Set all outputs to ON
|
||||
Bp5758dStop();
|
||||
}
|
||||
|
||||
// Even though we could address changing channels only, in practice we observed that the lightbulb always sets all channels.
|
||||
Bp5758dStart(BP5758D_ADDR_OUT1_GL);
|
||||
|
|
Loading…
Reference in New Issue