Skip to content

Don't activate every longpress nightmode #718

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/MiLight/FUT089PacketFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,30 @@ BulbId FUT089PacketFormatter::parsePacket(const uint8_t *packet, JsonObject resu

uint8_t command = (packetCopy[V2_COMMAND_INDEX] & 0x7F);
uint8_t arg = packetCopy[V2_ARGUMENT_INDEX];
bool long_press = (packetCopy[V2_COMMAND_INDEX] & 0x80) == 0x80;

if (command == FUT089_ON) {
if ((packetCopy[V2_COMMAND_INDEX] & 0x80) == 0x80) {
result[GroupStateFieldNames::COMMAND] = MiLightCommandNames::NIGHT_MODE;
} else if (arg == FUT089_MODE_SPEED_DOWN) {
if (arg == FUT089_MODE_SPEED_DOWN) {
result[GroupStateFieldNames::COMMAND] = MiLightCommandNames::MODE_SPEED_DOWN;
result[GroupStateFieldNames::LONG_PRESS] = long_press;
} else if (arg == FUT089_MODE_SPEED_UP) {
result[GroupStateFieldNames::COMMAND] = MiLightCommandNames::MODE_SPEED_UP;
result[GroupStateFieldNames::LONG_PRESS] = long_press;
} else if (arg == FUT089_WHITE_MODE) {
result[GroupStateFieldNames::COMMAND] = MiLightCommandNames::SET_WHITE;
result[GroupStateFieldNames::LONG_PRESS] = long_press;
} else if (arg <= 8) { // Group is not reliably encoded in group byte. Extract from arg byte
result[GroupStateFieldNames::STATE] = "ON";
bulbId.groupId = arg;
result[GroupStateFieldNames::LONG_PRESS] = long_press;
} else if (arg >= 9 && arg <= 17) {
result[GroupStateFieldNames::STATE] = "OFF";
bulbId.groupId = arg-9;
result[GroupStateFieldNames::LONG_PRESS] = long_press;
if (long_press) {
result[GroupStateFieldNames::STATE] = "ON";
Copy link

@Jojo-1000 Jojo-1000 Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the behavior of the packet sniffer. Now when I keep pressing the off button, it will show one "OFF" state and then "ON" with night_mode. Before it was continuous "OFF" with night mode. I am not sure which way is better, but to me it is confusing that I am pressing off but the command shows as on.

result[GroupStateFieldNames::COMMAND] = MiLightCommandNames::NIGHT_MODE;
}
}
} else if (command == FUT089_COLOR) {
uint8_t rescaledColor = (arg - FUT089_COLOR_OFFSET) % 0x100;
Expand All @@ -147,6 +155,7 @@ BulbId FUT089PacketFormatter::parsePacket(const uint8_t *packet, JsonObject resu
}
} else if (command == FUT089_MODE) {
result[GroupStateFieldNames::MODE] = arg;
result[GroupStateFieldNames::LONG_PRESS] = long_press;
} else {
result["button_id"] = command;
result["argument"] = arg;
Expand Down
11 changes: 8 additions & 3 deletions lib/MiLight/FUT091PacketFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,21 @@ BulbId FUT091PacketFormatter::parsePacket(const uint8_t *packet, JsonObject resu

uint8_t command = (packetCopy[V2_COMMAND_INDEX] & 0x7F);
uint8_t arg = packetCopy[V2_ARGUMENT_INDEX];
bool long_press = (packetCopy[V2_COMMAND_INDEX] & 0x80) == 0x80;

if (command == (uint8_t)FUT091Command::ON_OFF) {
if ((packetCopy[V2_COMMAND_INDEX] & 0x80) == 0x80) {
result[GroupStateFieldNames::COMMAND] = MiLightCommandNames::NIGHT_MODE;
} else if (arg < 5) { // Group is not reliably encoded in group byte. Extract from arg byte
if (arg < 5) { // Group is not reliably encoded in group byte. Extract from arg byte
result[GroupStateFieldNames::STATE] = "ON";
result[GroupStateFieldNames::LONG_PRESS] = long_press;
bulbId.groupId = arg;
} else {
result[GroupStateFieldNames::STATE] = "OFF";
bulbId.groupId = arg-5;
result[GroupStateFieldNames::LONG_PRESS] = long_press;
if (long_press) {
result[GroupStateFieldNames::STATE] = "ON";
result[GroupStateFieldNames::COMMAND] = MiLightCommandNames::NIGHT_MODE;
}
}
} else if (command == (uint8_t)FUT091Command::BRIGHTNESS) {
uint8_t level = V2PacketFormatter::fromv2scale(arg, BRIGHTNESS_SCALE_MAX, 2, true);
Expand Down
4 changes: 3 additions & 1 deletion lib/Types/GroupStateField.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace GroupStateFieldNames {
static const char HEX_COLOR[] = "hex_color";
static const char COMMAND[] = "command";
static const char COMMANDS[] = "commands";
static const char LONG_PRESS[] = "long_press";
};

enum class GroupStateField {
Expand All @@ -45,7 +46,8 @@ enum class GroupStateField {
GROUP_ID,
DEVICE_TYPE,
OH_COLOR,
HEX_COLOR
HEX_COLOR,
LONG_PRESS
};

class GroupStateFieldHelpers {
Expand Down