Skip to content

Commit

Permalink
controlling animation from mobile app
Browse files Browse the repository at this point in the history
  • Loading branch information
jiripraus committed Dec 23, 2020
1 parent af582f8 commit ccf438e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
2 changes: 0 additions & 2 deletions src/floower-esp32/automaton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ void Automaton::init() {
changeState(STATE_STANDBY);
floower->onLeafTouch([=](FloowerTouchEvent event){ onLeafTouch(event); });
remote->onTakeOver([=]() { onRemoteTookOver(); }); // remote controller took over

floower->startAnimation(FloowerColorAnimation::CANDLE);
}

void Automaton::update() {
Expand Down
41 changes: 27 additions & 14 deletions src/floower-esp32/remote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,37 @@ static const char* LOG_TAG = "Remote";
#define BATTERY_POWER_STATE_DISCHARGING B00101111

// BLE data packets
#define STATE_PACKET_SIZE 4

typedef struct StatePacketData {
byte petalsOpenLevel; // 0-100%, read-write
byte petalsOpenLevel; // normally petals open level 0-100%, read-write
byte R; // 0-255, read-write
byte G; // 0-255, read-write
byte B; // 0-255, read-write

RgbColor getColor() {
return RgbColor(R, G, B);
}
};

#define STATE_PACKET_SIZE 4
typedef union StatePacket {
StatePacketData data;
uint8_t bytes[STATE_PACKET_SIZE];
};

#define STATE_CHANGE_PACKET_SIZE 6

// TODO: define
#define STATE_TRANSITION_MODE_BIT_COLOR 0
#define STATE_TRANSITION_MODE_BIT_PETALS 1
#define STATE_TRANSITION_MODE_BIT_PETALS 1 // when this bit is set, the VALUE parameter means open level of petals (0-100%)
#define STATE_TRANSITION_MODE_BIT_ANIMATION 2 // when this bit is set, the VALUE parameter means ID of animation

typedef struct StateChangePacketData : StatePacketData {
typedef struct StateChangePacketData {
byte value;
byte R; // 0-255, read-write
byte G; // 0-255, read-write
byte B; // 0-255, read-write
byte duration; // 100 of milliseconds
byte mode; // transition mode
byte mode; // 8 flags, see defines above

RgbColor getColor() {
return RgbColor(R, G, B);
}
};

#define STATE_CHANGE_PACKET_SIZE 6
typedef union StateChangePacket {
StateChangePacketData data;
uint8_t bytes[STATE_CHANGE_PACKET_SIZE];
Expand Down Expand Up @@ -222,7 +224,18 @@ void Remote::StateChangeCharacteristicsCallbacks::onWrite(BLECharacteristic *cha
}
if (CHECK_BIT(statePacket.data.mode, STATE_TRANSITION_MODE_BIT_PETALS)) {
// petals open/close
remote->floower->setPetalsOpenLevel(statePacket.data.petalsOpenLevel, statePacket.data.duration * 100);
remote->floower->setPetalsOpenLevel(statePacket.data.value, statePacket.data.duration * 100);
}
else if (CHECK_BIT(statePacket.data.mode, STATE_TRANSITION_MODE_BIT_ANIMATION)) {
// play animation (according to value)
switch (statePacket.data.value) {
case 1:
remote->floower->startAnimation(FloowerColorAnimation::RAINBOW);
break;
case 2:
remote->floower->startAnimation(FloowerColorAnimation::CANDLE);
break;
}
}

if (remote->takeOverCallback != nullptr) {
Expand Down

0 comments on commit ccf438e

Please sign in to comment.