mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-27 12:46:34 +00:00
Light control fully functional at 8bit resolution
This commit is contained in:
parent
2121ea63cd
commit
6dd20a566f
@ -22,9 +22,8 @@
|
|||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* BP5758D RGBCW Led bulbs commonly used by Tuya hardware
|
* BP5758D RGBCW Led bulbs commonly used by Tuya hardware
|
||||||
*
|
*
|
||||||
* TODO: Adapt
|
* Example configuration for a Fitop RGBCCT filament light bulb:
|
||||||
* Fitop 10W RGBCCT Bulb (BA60H-W0080-RCBW-E7)
|
* {"NAME":"Fitop Filament RGBCCT","GPIO":[1,1,0,1,1,0,0,0,8416,0,8384,0,0,0],"FLAG":0,"BASE":18,"CMND":"RGBWWTable 255,109,245,255,255"}
|
||||||
* {"NAME":"Fitop 10W RGBCCT","GPIO":[1,1,1,1,1,4032,1,1,4069,1,1,1,1,1],"FLAG":0,"BASE":18,"CMND":"RGBWWTable 167,102,109,255,255"}
|
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
#define XLGT_08 8
|
#define XLGT_08 8
|
||||||
@ -60,10 +59,11 @@ struct BP5758D {
|
|||||||
} Bp5758d;
|
} Bp5758d;
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* Bp5758d code - mostly copied over from SM2135
|
* Bp5758d code
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
const uint8_t BP5758D_DELAY = 2;
|
const uint8_t BP5758D_DELAY = 2;
|
||||||
|
|
||||||
|
/*
|
||||||
void Bp5758dSetLow(uint8_t pin) {
|
void Bp5758dSetLow(uint8_t pin) {
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
digitalWrite(pin, LOW);
|
digitalWrite(pin, LOW);
|
||||||
@ -76,53 +76,48 @@ void Bp5758dSetHigh(uint8_t pin) {
|
|||||||
pinMode(pin, INPUT_PULLUP);
|
pinMode(pin, INPUT_PULLUP);
|
||||||
interrupts();
|
interrupts();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
bool Bp5758dInit(void) {
|
void Bp5758dInit(void) {
|
||||||
digitalWrite(Bp5758d.data, LOW);
|
pinMode(Bp5758d.data, OUTPUT);
|
||||||
digitalWrite(Bp5758d.clk, LOW);
|
pinMode(Bp5758d.clk, OUTPUT);
|
||||||
Bp5758dSetHigh(Bp5758d.data);
|
Bp5758dStop();
|
||||||
Bp5758dSetHigh(Bp5758d.clk);
|
|
||||||
return (!((digitalRead(Bp5758d.data) == LOW || digitalRead(Bp5758d.clk) == LOW)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Bp5758dWrite(uint8_t value) {
|
void Bp5758dWrite(uint8_t value) {
|
||||||
AddLog(LOG_LEVEL_DEBUG, PSTR("LGT: Bp5758dWrite %2x"), value);
|
AddLog(LOG_LEVEL_DEBUG, PSTR("LGT: Bp5758dWrite %2x"), value);
|
||||||
for (uint8_t curr = 0X80; curr != 0; curr >>= 1) {
|
for (int bit_idx = 7; bit_idx >= 0; bit_idx--) {
|
||||||
if (curr & value) {
|
bool bit = bitRead(value, bit_idx);
|
||||||
Bp5758dSetHigh(Bp5758d.data);
|
digitalWrite(Bp5758d.data, bit);
|
||||||
} else {
|
delayMicroseconds(BP5758D_DELAY);
|
||||||
Bp5758dSetLow(Bp5758d.data);
|
digitalWrite(Bp5758d.clk, HIGH);
|
||||||
}
|
delayMicroseconds(BP5758D_DELAY);
|
||||||
Bp5758dSetHigh(Bp5758d.clk);
|
digitalWrite(Bp5758d.clk, LOW);
|
||||||
delayMicroseconds(BP5758D_DELAY);
|
delayMicroseconds(BP5758D_DELAY);
|
||||||
Bp5758dSetLow(Bp5758d.clk);
|
|
||||||
}
|
}
|
||||||
// get Ack or Nak
|
// Wait for ACK
|
||||||
Bp5758dSetHigh(Bp5758d.data);
|
pinMode(Bp5758d.data, INPUT);
|
||||||
Bp5758dSetHigh(Bp5758d.clk);
|
digitalWrite(Bp5758d.clk, HIGH);
|
||||||
delayMicroseconds(BP5758D_DELAY / 2);
|
delayMicroseconds(BP5758D_DELAY);
|
||||||
uint8_t ack = digitalRead(Bp5758d.data);
|
digitalWrite(Bp5758d.clk, LOW);
|
||||||
Bp5758dSetLow(Bp5758d.clk);
|
delayMicroseconds(BP5758D_DELAY);
|
||||||
delayMicroseconds(BP5758D_DELAY / 2);
|
pinMode(Bp5758d.data, OUTPUT);
|
||||||
Bp5758dSetLow(Bp5758d.data);
|
|
||||||
return (0 == ack);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Bp5758dStart(uint8_t addr) {
|
void Bp5758dStart(uint8_t addr) {
|
||||||
AddLog(LOG_LEVEL_DEBUG, PSTR("LGT: Bp5758dStart"));
|
AddLog(LOG_LEVEL_DEBUG, PSTR("LGT: Bp5758dStart"));
|
||||||
Bp5758dSetLow(Bp5758d.data);
|
digitalWrite(Bp5758d.data, LOW);
|
||||||
delayMicroseconds(BP5758D_DELAY);
|
delayMicroseconds(BP5758D_DELAY);
|
||||||
Bp5758dSetLow(Bp5758d.clk);
|
digitalWrite(Bp5758d.clk, LOW);
|
||||||
return Bp5758dWrite(addr);
|
delayMicroseconds(BP5758D_DELAY);
|
||||||
|
Bp5758dWrite(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bp5758dStop(void) {
|
void Bp5758dStop(void) {
|
||||||
AddLog(LOG_LEVEL_DEBUG, PSTR("LGT: Bp5758dStop"));
|
AddLog(LOG_LEVEL_DEBUG, PSTR("LGT: Bp5758dStop"));
|
||||||
Bp5758dSetLow(Bp5758d.data);
|
digitalWrite(Bp5758d.clk, HIGH);
|
||||||
delayMicroseconds(BP5758D_DELAY);
|
delayMicroseconds(BP5758D_DELAY);
|
||||||
Bp5758dSetHigh(Bp5758d.clk);
|
digitalWrite(Bp5758d.data, HIGH);
|
||||||
delayMicroseconds(BP5758D_DELAY);
|
|
||||||
Bp5758dSetHigh(Bp5758d.data);
|
|
||||||
delayMicroseconds(BP5758D_DELAY);
|
delayMicroseconds(BP5758D_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,16 +131,16 @@ bool Bp5758dSetChannels(void) {
|
|||||||
// The first 5bits of this input are transmitted in first byte, the second 5bits in the second byte.
|
// The first 5bits of this input are transmitted in first byte, the second 5bits in the second byte.
|
||||||
// Because or tasmota's controls are 8bit (0-255), we need to multiply by 4 (or shift two bits to the left).
|
// Because or tasmota's controls are 8bit (0-255), we need to multiply by 4 (or shift two bits to the left).
|
||||||
// We thus transmit the first 5bits of tasmota's input as byte1, and the remaining 3bits as byte2 (shifted left two bits).
|
// We thus transmit the first 5bits of tasmota's input as byte1, and the remaining 3bits as byte2 (shifted left two bits).
|
||||||
Bp5758dWrite(cur_col[0] >> 3); //Red: Only take first 5bits of tasmota's input
|
Bp5758dWrite((cur_col[0] & 0x07) << 2); //Red: Only take last 3 bits, multiplied by 4 / shifted to left
|
||||||
Bp5758dWrite((cur_col[0] & 0x07) << 2); //Only take last 3 bits, multiplied by 4 / shifted to left
|
Bp5758dWrite(cur_col[0] >> 3); //Only take first 5bits of tasmota's input
|
||||||
Bp5758dWrite(cur_col[1] >> 3); //Green
|
Bp5758dWrite((cur_col[1] & 0x07) << 2); //Green
|
||||||
Bp5758dWrite((cur_col[1] & 0x07) << 2);
|
Bp5758dWrite(cur_col[1] >> 3);
|
||||||
Bp5758dWrite(cur_col[2] >> 3); //Blue
|
Bp5758dWrite((cur_col[2] & 0x07) << 2); //Blue
|
||||||
Bp5758dWrite((cur_col[2] & 0x07) << 2);
|
Bp5758dWrite(cur_col[2] >> 3);
|
||||||
Bp5758dWrite(cur_col[3] >> 3); //Warm
|
Bp5758dWrite((cur_col[4] & 0x07) << 2); //Cold
|
||||||
Bp5758dWrite((cur_col[3] & 0x07) << 2);
|
Bp5758dWrite(cur_col[4] >> 3);
|
||||||
Bp5758dWrite(cur_col[4] >> 3); //Cold
|
Bp5758dWrite((cur_col[3] & 0x07) << 2); //Warm
|
||||||
Bp5758dWrite((cur_col[4] & 0x07) << 2);
|
Bp5758dWrite(cur_col[3] >> 3);
|
||||||
Bp5758dStop();
|
Bp5758dStop();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -178,6 +173,7 @@ void Bp5758dModuleSelected(void)
|
|||||||
Bp5758dWrite(0x00);
|
Bp5758dWrite(0x00);
|
||||||
Bp5758dWrite(0x00);
|
Bp5758dWrite(0x00);
|
||||||
Bp5758dWrite(0x00);
|
Bp5758dWrite(0x00);
|
||||||
|
Bp5758dStop();
|
||||||
|
|
||||||
TasmotaGlobal.light_type = LT_RGBWC;
|
TasmotaGlobal.light_type = LT_RGBWC;
|
||||||
TasmotaGlobal.light_driver = XLGT_08;
|
TasmotaGlobal.light_driver = XLGT_08;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user