Created
January 30, 2022 19:24
-
-
Save kabbi/a5b7dcd92222f55d2f93cdc1acc6665b to your computer and use it in GitHub Desktop.
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
#include <stdbool.h> | |
#include <stdint.h> | |
#include "api.h" | |
#include "mesh.h" | |
#include "libc.h" | |
#define KABBI_COMPANY_ID 0x9832 | |
#define KABBI_STRIP_MODEL_ID 0x0001 | |
#define MSG_STRIP_START_EFFECT_OPCODE BT_MESH_MODEL_OP_3(0x04, KABBI_COMPANY_ID) | |
#define MSG_STRIP_START_EFFECT_STATUS_OPCODE BT_MESH_MODEL_OP_3(0x05, KABBI_COMPANY_ID) | |
#define MSG_STRIP_STOP_EFFECT_OPCODE BT_MESH_MODEL_OP_3(0x06, KABBI_COMPANY_ID) | |
#define MSG_STRIP_STOP_EFFECT_STATUS_OPCODE BT_MESH_MODEL_OP_3(0x07, KABBI_COMPANY_ID) | |
#define MSG_STRIP_SET_PARAM_OPCODE BT_MESH_MODEL_OP_3(0x08, KABBI_COMPANY_ID) | |
#define MSG_STRIP_GET_PARAM_OPCODE BT_MESH_MODEL_OP_3(0x09, KABBI_COMPANY_ID) | |
#define MSG_STRIP_PARAM_STATUS_OPCODE BT_MESH_MODEL_OP_3(0x0a, KABBI_COMPANY_ID) | |
void set_powered(int addr, int value) { | |
uint8_t msg[32]; | |
msg[0] = value; | |
ble_mesh_send_msg(0, addr, BT_MESH_ONOFF_OP_SET_UNACK, 1, msg); | |
} | |
void set_param(int addr, char *name, int value) { | |
uint8_t msg[32]; | |
int name_len = strlen(name); | |
memcpy(msg, &value, 4); | |
memcpy(msg + 4, name, name_len); | |
ble_mesh_send_msg(0, addr, MSG_STRIP_SET_PARAM_OPCODE, name_len + 4, msg); | |
} | |
void start_effect(int addr, char *name) { | |
uint8_t msg[32]; | |
msg[0] = strlen(name); | |
memcpy(msg + 1, name, msg[0]); | |
ble_mesh_send_msg(0, addr, MSG_STRIP_START_EFFECT_OPCODE, 1, msg); | |
} | |
bool is_powered(int addr) { | |
return false; | |
} | |
int time_left = 0; | |
void method0() { | |
time_left = (time_left - 1); | |
set_param(0x0010, "progress", (time_left - 1) / 30 * 100); | |
if (((time_left - 1) == 0)) { | |
set_powered(0x0010, false); | |
} | |
} | |
void method1() { | |
if (!is_powered(0x0010)) { | |
time_left = 30; | |
set_param(0x0010, "progress", 100); | |
start_effect(0x0010, "progress_bar"); | |
timer_start(1000); | |
} | |
} | |
void on_init() { | |
buttons_start(); | |
} | |
void on_button_event(int pressed, int changed) { | |
method1(); | |
} | |
void on_timer_event(int timer_id) { | |
method0(); | |
} | |
void on_destroy() { | |
buttons_stop(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment