mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-25 20:26:41 +00:00
Merge branch 'master' of http://github.com/fvanroie/hasp-lvgl
This commit is contained in:
commit
91835d3684
@ -1,8 +1,14 @@
|
|||||||
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
|
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
|
||||||
For full license information read the LICENSE file in the project folder */
|
For full license information read the LICENSE file in the project folder */
|
||||||
|
|
||||||
// USAGE: - Copy this file and rename it to my_custom.cpp
|
// USAGE: - Copy this file and rename it to my_custom_fan_rotator.cpp, also copy my_custom_template.h and rename it to my_custom.h
|
||||||
// - Change false to true on line 9
|
// - Change false to true on line 15
|
||||||
|
// - Set the page and id of your object on lines 25 and 26
|
||||||
|
// - Optionally set the default rotation state and angle on lines 19 and 20
|
||||||
|
// - At run time you can change fanspeed and fanangle by updating the topics hasp/<yourplate>/custom/fanspeed
|
||||||
|
// and hasp/<yourplate>/custom/fanangle with values desired from your home automation system
|
||||||
|
// NOTE: This gives best results with small images (up to 64x64 pixels). Large images may draw choppy due to limited
|
||||||
|
// computing capacity of the MCU.
|
||||||
|
|
||||||
#include "hasplib.h"
|
#include "hasplib.h"
|
||||||
|
|
||||||
@ -10,14 +16,14 @@
|
|||||||
|
|
||||||
#include "custom/my_custom.h"
|
#include "custom/my_custom.h"
|
||||||
|
|
||||||
uint16_t fanspeed = 0;
|
uint16_t fanspeed = 0; // rotation off by default (the time between angle turns in ms)
|
||||||
uint16_t fanangle = 450;
|
uint16_t fanangle = 450; // default angle of one turn (0.1 degree precision, so this means 45°)
|
||||||
unsigned long prev_loop = 0;
|
unsigned long prev_loop = 0;
|
||||||
|
|
||||||
static void my_rotate_fan()
|
static void my_rotate_fan()
|
||||||
{
|
{
|
||||||
uint8_t page = 1;
|
uint8_t page = 1; // the page of the object you want to rotate
|
||||||
uint8_t id = 150;
|
uint8_t id = 150; // the id of the object you want to rotate
|
||||||
|
|
||||||
lv_obj_t* fan = hasp_find_obj_from_page_id(page, id);
|
lv_obj_t* fan = hasp_find_obj_from_page_id(page, id);
|
||||||
if(!fan) return; // object doesn't exist
|
if(!fan) return; // object doesn't exist
|
||||||
@ -44,30 +50,23 @@ void custom_loop()
|
|||||||
|
|
||||||
void custom_every_second()
|
void custom_every_second()
|
||||||
{
|
{
|
||||||
Serial.print("#");
|
// Unused
|
||||||
}
|
}
|
||||||
|
|
||||||
void custom_every_5seconds()
|
void custom_every_5seconds()
|
||||||
{
|
{
|
||||||
Log.verbose(TAG_CUSTOM, "5 seconds have passsed...");
|
// Unused
|
||||||
dispatch_state_subtopic("my_sensor", "{\"test\":123}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool custom_pin_in_use(uint pin)
|
bool custom_pin_in_use(uint pin)
|
||||||
{
|
{
|
||||||
if(pin == 1024) return true; // fictuous used pin
|
// no pins are used
|
||||||
|
|
||||||
// otherwise the pin is not used
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void custom_get_sensors(JsonDocument& doc)
|
void custom_get_sensors(JsonDocument& doc)
|
||||||
{
|
{
|
||||||
/* Sensor Name */
|
// Unused
|
||||||
JsonObject sensor = doc.createNestedObject(F("Custom"));
|
|
||||||
|
|
||||||
/* Key-Value pair of the sensor value */
|
|
||||||
sensor[F("Random")] = random(256);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Receive custom topic & payload messages */
|
/* Receive custom topic & payload messages */
|
||||||
@ -99,4 +98,4 @@ void custom_topic_payload(const char* topic, const char* payload, uint8_t source
|
|||||||
// Log.verbose(TAG_CUSTOM, "Handled custom message: %s => %s", topic, payload);
|
// Log.verbose(TAG_CUSTOM, "Handled custom message: %s => %s", topic, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // HASP_USE_CUSTOM
|
#endif // HASP_USE_CUSTOM
|
||||||
|
Loading…
x
Reference in New Issue
Block a user