forked from sidoh/esp8266_milight_hub
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
736 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Chris Mullins | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include <FUT091PacketFormatter.h> | ||
#include <V2RFEncoding.h> | ||
#include <Units.h> | ||
|
||
static const uint8_t BRIGHTNESS_SCALE_MAX = 0x97; | ||
static const uint8_t KELVIN_SCALE_MAX = 0xC5; | ||
|
||
void FUT091PacketFormatter::updateBrightness(uint8_t value) { | ||
command(static_cast<uint8_t>(FUT091Command::BRIGHTNESS), V2PacketFormatter::tov2scale(value, BRIGHTNESS_SCALE_MAX, 2)); | ||
} | ||
|
||
void FUT091PacketFormatter::updateTemperature(uint8_t value) { | ||
command(static_cast<uint8_t>(FUT091Command::KELVIN), V2PacketFormatter::tov2scale(value, KELVIN_SCALE_MAX, 2, false)); | ||
} | ||
|
||
void FUT091PacketFormatter::enableNightMode() { | ||
uint8_t arg = groupCommandArg(OFF, groupId); | ||
command(static_cast<uint8_t>(FUT091Command::ON_OFF) | 0x80, arg); | ||
} | ||
|
||
BulbId FUT091PacketFormatter::parsePacket(const uint8_t *packet, JsonObject& result) { | ||
uint8_t packetCopy[V2_PACKET_LEN]; | ||
memcpy(packetCopy, packet, V2_PACKET_LEN); | ||
V2RFEncoding::decodeV2Packet(packetCopy); | ||
|
||
BulbId bulbId( | ||
(packetCopy[2] << 8) | packetCopy[3], | ||
packetCopy[7], | ||
REMOTE_TYPE_FUT091 | ||
); | ||
|
||
uint8_t command = (packetCopy[V2_COMMAND_INDEX] & 0x7F); | ||
uint8_t arg = packetCopy[V2_ARGUMENT_INDEX]; | ||
|
||
if (command == (uint8_t)FUT091Command::ON_OFF) { | ||
if ((packetCopy[V2_COMMAND_INDEX] & 0x80) == 0x80) { | ||
result["command"] = "night_mode"; | ||
} else if (arg < 5) { // Group is not reliably encoded in group byte. Extract from arg byte | ||
result["state"] = "ON"; | ||
bulbId.groupId = arg; | ||
} else { | ||
result["state"] = "OFF"; | ||
bulbId.groupId = arg-5; | ||
} | ||
} else if (command == (uint8_t)FUT091Command::BRIGHTNESS) { | ||
uint8_t level = V2PacketFormatter::fromv2scale(arg, BRIGHTNESS_SCALE_MAX, 2, true); | ||
result["brightness"] = Units::rescale<uint8_t, uint8_t>(level, 255, 100); | ||
} else if (command == (uint8_t)FUT091Command::KELVIN) { | ||
uint8_t kelvin = V2PacketFormatter::fromv2scale(arg, KELVIN_SCALE_MAX, 2, false); | ||
result["color_temp"] = Units::whiteValToMireds(kelvin, 100); | ||
} else { | ||
result["button_id"] = command; | ||
result["argument"] = arg; | ||
} | ||
|
||
return bulbId; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <V2PacketFormatter.h> | ||
|
||
#ifndef _FUT091_PACKET_FORMATTER_H | ||
#define _FUT091_PACKET_FORMATTER_H | ||
|
||
enum class FUT091Command { | ||
ON_OFF = 0x01, | ||
BRIGHTNESS = 0x2, | ||
KELVIN = 0x03 | ||
}; | ||
|
||
class FUT091PacketFormatter : public V2PacketFormatter { | ||
public: | ||
FUT091PacketFormatter() | ||
: V2PacketFormatter(0x21, 4) // protocol is 0x21, and there are 4 groups | ||
{ } | ||
|
||
virtual void updateBrightness(uint8_t value); | ||
virtual void updateTemperature(uint8_t value); | ||
virtual void enableNightMode(); | ||
|
||
virtual BulbId parsePacket(const uint8_t* packet, JsonObject& result); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.