Skip to content

Commit

Permalink
changed state packet & ranges 4 brightness
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadhyGit committed Oct 1, 2023
1 parent 22f485f commit dd7fb0d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions components/awox_mesh/mesh_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ void MeshDevice::handle_packet(std::string &packet) {
temperature = packet[13];
color_brightness = packet[15];
// If brightness == 0, then state is off
state = (white_brightness & 1) == 1;
// state = (white_brightness & 1) == 1;
state = transition_mode;

R = packet[16];
G = packet[17];
Expand Down Expand Up @@ -401,8 +402,8 @@ void MeshDevice::handle_packet(std::string &packet) {
return;

} else {
ESP_LOGW(TAG, "Unknown report, dev [%d]: command %02X => %s", mesh_id, static_cast<unsigned char>(packet[7]),
TextToBinaryString(packet).c_str());
// ESP_LOGW(TAG, "Unknown report, dev [%d]: command %02X => %s", mesh_id, static_cast<unsigned char>(packet[7]),
// TextToBinaryString(packet).c_str());

return;
}
Expand Down Expand Up @@ -505,13 +506,13 @@ void MeshDevice::publish_state(Device *device) {

root["color_mode"] = "color_temp";

root["brightness"] = convert_value_to_available_range(device->white_brightness, 1, 0x7f, 0, 255);
root["brightness"] = convert_value_to_available_range(device->white_brightness, 0, 100, 0, 255);

if (device->color_mode) {
root["color_mode"] = "rgb";
root["brightness"] = convert_value_to_available_range(device->color_brightness, 0xa, 0x64, 0, 255);
} else {
root["color_temp"] = convert_value_to_available_range(device->temperature, 0, 0x7f, 153, 370);
root["color_temp"] = convert_value_to_available_range(device->temperature, 0, 100, 153, 370);
}
JsonObject color = root.createNestedObject("color");
color["r"] = device->R;
Expand Down Expand Up @@ -675,7 +676,7 @@ void MeshDevice::process_incomming_command(Device *device, JsonObject root) {
this->set_color_brightness(device->mesh_id, brightness);

} else if (root.containsKey("brightness")) {
int brightness = convert_value_to_available_range((int) root["brightness"], 0, 255, 1, 0x7f);
int brightness = convert_value_to_available_range((int) root["brightness"], 0, 255, 1, 100);

state_set = true;
device->state = true;
Expand All @@ -686,7 +687,7 @@ void MeshDevice::process_incomming_command(Device *device, JsonObject root) {
}

if (root.containsKey("color_temp")) {
int temperature = convert_value_to_available_range((int) root["color_temp"], 153, 370, 0, 0x7f);
int temperature = convert_value_to_available_range((int) root["color_temp"], 153, 370, 0, 100);

state_set = true;
device->state = true;
Expand Down

0 comments on commit dd7fb0d

Please sign in to comment.