Skip to content

Commit

Permalink
improve reading brightness/ct after scene change
Browse files Browse the repository at this point in the history
  • Loading branch information
martgras committed Dec 29, 2020
1 parent 0ec7fe1 commit af1912f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ framework = arduino
board_build.partitions = partitions.csv

build_flags = ${usersettings.build_flags}
-DCORE_DEBUG_LEVEL=5
-DCORE_DEBUG_LEVEL=4
-DCONFIG_SW_COEXIST_ENABLE=1
; -DBOARD_HAS_PSRAM
; -mfix-esp32-psram-cache-issue
Expand Down
4 changes: 2 additions & 2 deletions platformio_usersettings.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ build_flags = -DWIFISID='"mywifi"'
; -DUSE_ETHERNET ## use ethernet instead of Wifi
; -DLR_BLEADDRESS='"c4:b9:71:da:19:c7"' ## if you add the device address here we can skip scanning at startup
-DROTARY=1 ## use a rotary attached to esp32
-DROTARY_PIN_A=GPIO_NUM_27 ## pin a (CLK) of the rotary (Fire Beetle D3) - Set to GPIO_NUM_0 if no rotary is connected
-DROTARY_PIN_B=GPIO_NUM_26 ## pin b (DT) of the rotary (Fire Beetle D4) - Set to GPIO_NUM_0 if no rotary is connected
-DROTARY_PIN_A=GPIO_NUM_27 ## pin a (CLK) of the rotary (Fire Beetle D4) - Set to GPIO_NUM_0 if no rotary is connected
-DROTARY_PIN_B=GPIO_NUM_26 ## pin b (DT) of the rotary (Fire Beetle D3) - Set to GPIO_NUM_0 if no rotary is connected
-DROTARY_PIN_BUTTON=GPIO_NUM_25 ## input pin of the rotary switch (SW) (Fire Beetle D2) - Set to GPIO_NUM_0 if no rotary is connected
### LONG PRESS Behavior: LONG PRESS on the rotary button is used to switch to the next scene. LONG_PRESS_DELAY defines how long the button must be pressed for the first event.
### LONG_PRESS_INTERVAL defines how long it takes to switch to the next scene
Expand Down
9 changes: 4 additions & 5 deletions src/LukeRobertsBle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ bool BleGattClient::send_queued() {
command.on_send(0);
}
needs_result = true;
yield();
delay(50);
}
}
// Other pending commands
while (!pending_commands.empty()) {
auto cmd = pending_commands.front();
send(cmd.data, cmd.size);
needs_result = true;
yield();
delay(100);
pending_commands.pop();
if (cmd.on_send) {
cmd.on_send(0);
Expand Down Expand Up @@ -231,8 +231,7 @@ BleGattClient::on_complete_callback BleGattClient::on_connect_ = nullptr;
BleGattClient::on_complete_callback BleGattClient::on_disconnect_ = nullptr;
notify_callback BleGattClient::on_notify_ = nullptr;
BleGattClient::on_downlight_callback BleGattClient::on_downlight_notification_ =
nullptr; // [](uint8_t,uint16_t){ log_i("=============== DEFAULT ON DOWN
// ===============");} ;
nullptr;

// BleGattClient::ClientCallbacks BleGattClient::client_cb_;

Expand All @@ -244,7 +243,7 @@ std::vector<int> SceneMapper::brightness_map_ = {

std::vector<int> SceneMapper::colortemperature_map_ = {
0, 2700, 4000, 3800, 2800, 4000, 2700, 4000}; // Load the default values
#endif
#endif

std::map<uint8_t, std::string> scenes = {{0, "OFF"}};

Expand Down
6 changes: 3 additions & 3 deletions src/LukeRobertsBle.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class BleGattClient {
client = nullptr;
return false;
}
yield();
delay(10);
}

struct BleCommand {
Expand Down Expand Up @@ -226,9 +226,9 @@ class BleGattClient {
pRemoteCharacteristic->getUUID().toString().c_str(), length, length,
(char *)pData, (int)pData[0]);

log_d("Client data received len: %d\n", length);
log_v("Client data received len: %d\n", length);
for (auto i = 0; i < length; i++) {
log_d("Response byte[%d]: %d (0x%X)", i, pData[i], pData[i]);
log_v("Response byte[%d]: %d (0x%X)", i, pData[i], pData[i]);
}

if (on_downlight_notification_ != nullptr &&
Expand Down
5 changes: 2 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class LR_Ble_Device {
4,
false,
[&](int) {
if (state().power) {
/*if (true || state().power)*/ {
char json[32];
snprintf(json, sizeof(json), "%d", state_.scene);
mqtt.queue("stat/" HOSTNAME "/SCENE", json);
Expand All @@ -114,7 +114,6 @@ class LR_Ble_Device {
// Not sure why this doesn't work from constustructor
void init() {
gatt_client_.set_on_downlight([&](uint8_t brightness, uint16_t kelvin) {

state_.brightness = brightness;
state_.kelvin = kelvin;
state_.mired = switch_kelvin_mired(state_.kelvin);
Expand Down Expand Up @@ -254,7 +253,7 @@ class LR_Ble_Device {
gatt_client_.cached_commands[kScene].is_dirty |=
force_dirty || (state_.scene == 0 || state_.scene != new_scene);
state_.scene = new_scene;
#ifdef OLLD
#ifdef OLD
// if (state_.brightness == 0) {
state_.brightness = SceneMapper::map_brightness(state_.scene);
// }
Expand Down

0 comments on commit af1912f

Please sign in to comment.