This commit is contained in:
fvanroie 2021-10-09 00:00:24 +02:00
commit 91835d3684

View File

@ -1,8 +1,14 @@
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
For full license information read the LICENSE file in the project folder */
// USAGE: - Copy this file and rename it to my_custom.cpp
// - Change false to true on line 9
// 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 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"
@ -10,14 +16,14 @@
#include "custom/my_custom.h"
uint16_t fanspeed = 0;
uint16_t fanangle = 450;
uint16_t fanspeed = 0; // rotation off by default (the time between angle turns in ms)
uint16_t fanangle = 450; // default angle of one turn (0.1 degree precision, so this means 45°)
unsigned long prev_loop = 0;
static void my_rotate_fan()
{
uint8_t page = 1;
uint8_t id = 150;
uint8_t page = 1; // the page of the object you want to rotate
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);
if(!fan) return; // object doesn't exist
@ -44,30 +50,23 @@ void custom_loop()
void custom_every_second()
{
Serial.print("#");
// Unused
}
void custom_every_5seconds()
{
Log.verbose(TAG_CUSTOM, "5 seconds have passsed...");
dispatch_state_subtopic("my_sensor", "{\"test\":123}");
// Unused
}
bool custom_pin_in_use(uint pin)
{
if(pin == 1024) return true; // fictuous used pin
// otherwise the pin is not used
// no pins are used
return false;
}
void custom_get_sensors(JsonDocument& doc)
{
/* Sensor Name */
JsonObject sensor = doc.createNestedObject(F("Custom"));
/* Key-Value pair of the sensor value */
sensor[F("Random")] = random(256);
// Unused
}
/* 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);
}
#endif // HASP_USE_CUSTOM
#endif // HASP_USE_CUSTOM