Skip to content

Commit

Permalink
Merge pull request #846 from Jojo-1000/fut092-support
Browse files Browse the repository at this point in the history
Add support to decode the FUT092 remote
  • Loading branch information
sidoh authored Nov 23, 2024
2 parents 0a9ab66 + 06c82ac commit 18f437e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 51 deletions.
59 changes: 10 additions & 49 deletions lib/MiLight/FUT089PacketFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,58 +29,14 @@ void FUT089PacketFormatter::updateColorRaw(uint8_t value) {
command(FUT089_COLOR, FUT089_COLOR_OFFSET + value);
}

// change the temperature (kelvin). Note that temperature and saturation share the same command
// number (7), and they change which they do based on the mode of the lamp (white vs. color mode).
// To make this command work, we need to switch to white mode, make the change, and then flip
// back to the original mode.
// change the temperature (kelvin). Update: now uses the fut092 command to skip mode changes
void FUT089PacketFormatter::updateTemperature(uint8_t value) {
// look up our current mode
const GroupState* ourState = this->stateStore->get(this->deviceId, this->groupId, REMOTE_TYPE_FUT089);
BulbMode originalBulbMode;

if (ourState != NULL) {
originalBulbMode = ourState->getBulbMode();

// are we already in white? If not, change to white
if (originalBulbMode != BulbMode::BULB_MODE_WHITE) {
updateColorWhite();
}
}

// now make the temperature change
command(FUT089_KELVIN, 100 - value);

// and return to our original mode
if (ourState != NULL && (settings->enableAutomaticModeSwitching) && (originalBulbMode != BulbMode::BULB_MODE_WHITE)) {
switchMode(*ourState, originalBulbMode);
}
command(FUT092_KELVIN, 100 - value);
}

// change the saturation. Note that temperature and saturation share the same command
// number (7), and they change which they do based on the mode of the lamp (white vs. color mode).
// Therefore, if we are not in color mode, we need to switch to color mode, make the change,
// and switch back to the original mode.
// change the saturation. Update: now uses the fut092 command to skip mode changes
void FUT089PacketFormatter::updateSaturation(uint8_t value) {
// look up our current mode
const GroupState* ourState = this->stateStore->get(this->deviceId, this->groupId, REMOTE_TYPE_FUT089);
BulbMode originalBulbMode = BulbMode::BULB_MODE_WHITE;

if (ourState != NULL) {
originalBulbMode = ourState->getBulbMode();
}

// are we already in color? If not, we need to flip modes
if (ourState != NULL && (settings->enableAutomaticModeSwitching) && (originalBulbMode != BulbMode::BULB_MODE_COLOR)) {
updateHue(ourState->getHue());
}

// now make the saturation change
command(FUT089_SATURATION, 100 - value);

// and revert back if necessary
if (ourState != NULL && (settings->enableAutomaticModeSwitching) && (originalBulbMode != BulbMode::BULB_MODE_COLOR)) {
switchMode(*ourState, originalBulbMode);
}
command(FUT092_SATURATION, 100 - value);
}

void FUT089PacketFormatter::updateColorWhite() {
Expand Down Expand Up @@ -137,7 +93,7 @@ BulbId FUT089PacketFormatter::parsePacket(const uint8_t *packet, JsonObject resu
result[GroupStateFieldNames::BRIGHTNESS] = Units::rescale<uint8_t, uint8_t>(level, 255, 100);
// saturation == kelvin. arg ranges are the same, so can't distinguish
// without using state
} else if (command == FUT089_SATURATION) {
} else if (command == FUT089_KELVIN_SATURATION) {
const GroupState* state = stateStore->get(bulbId);

if (state != NULL && state->getBulbMode() == BULB_MODE_COLOR) {
Expand All @@ -147,6 +103,11 @@ BulbId FUT089PacketFormatter::parsePacket(const uint8_t *packet, JsonObject resu
}
} else if (command == FUT089_MODE) {
result[GroupStateFieldNames::MODE] = arg;
// FUT092 commands
} else if(command == FUT092_KELVIN) {
result[GroupStateFieldNames::COLOR_TEMP] = Units::whiteValToMireds(100 - arg, 100);
} else if(command == FUT092_SATURATION) {
result[GroupStateFieldNames::SATURATION] = 100 - constrain(arg, 0, 100);
} else {
result["button_id"] = command;
result["argument"] = arg;
Expand Down
5 changes: 3 additions & 2 deletions lib/MiLight/FUT089PacketFormatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ enum MiLightFUT089Command {
FUT089_ON = 0x01,
FUT089_OFF = 0x01,
FUT089_COLOR = 0x02,
FUT092_KELVIN = 0x03, // The FUT092 uses the same protocol, but has separate temperature and saturation commands
FUT092_SATURATION = 0x04, // Used by FUT092
FUT089_BRIGHTNESS = 0x05,
FUT089_MODE = 0x06,
FUT089_KELVIN = 0x07, // Controls Kelvin when in White mode
FUT089_SATURATION = 0x07 // Controls Saturation when in Color mode
FUT089_KELVIN_SATURATION = 0x07 // Controls Kelvin when in White mode, controls Saturation when in Color mode
};

enum MiLightFUT089Arguments {
Expand Down

0 comments on commit 18f437e

Please sign in to comment.