mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-25 12:16:42 +00:00
Add my_custom_template
This commit is contained in:
parent
a2ab8cfc2c
commit
3b377c8814
2
.gitignore
vendored
2
.gitignore
vendored
@ -19,6 +19,8 @@ build_output/firmware/*.exe
|
|||||||
src/custom/*
|
src/custom/*
|
||||||
!src/custom/README.md
|
!src/custom/README.md
|
||||||
!src/custom/bootlogo_template.h
|
!src/custom/bootlogo_template.h
|
||||||
|
!src/custom/my_custom_template.h
|
||||||
|
!src/custom/my_custom_template.cpp
|
||||||
|
|
||||||
## Test result files
|
## Test result files
|
||||||
*.xml
|
*.xml
|
||||||
|
47
src/custom/my_custom_template.cpp
Normal file
47
src/custom/my_custom_template.cpp
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
|
||||||
|
For full license information read the LICENSE file in the project folder */
|
||||||
|
|
||||||
|
#include "hasplib.h"
|
||||||
|
#include "custom/my_custom.h"
|
||||||
|
|
||||||
|
#if HASP_USE_CUSTOM > 0
|
||||||
|
|
||||||
|
void custom_setup()
|
||||||
|
{
|
||||||
|
// Initialization code here
|
||||||
|
randomSeed(millis());
|
||||||
|
}
|
||||||
|
|
||||||
|
void custom_loop()
|
||||||
|
{
|
||||||
|
// Non-blocking code here, this should execure very fast!
|
||||||
|
}
|
||||||
|
|
||||||
|
void custom_every_second()
|
||||||
|
{
|
||||||
|
Serial.print("#");
|
||||||
|
}
|
||||||
|
|
||||||
|
void custom_every_5seconds()
|
||||||
|
{
|
||||||
|
Log.verbose(TAG_CUSTOM, "5 seconds have passsed...");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool custom_pin_in_use(uint pin)
|
||||||
|
{
|
||||||
|
if(pin == 1024) return true; // fictuous used pin
|
||||||
|
|
||||||
|
// otherwise the pin is not used
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void custom_get_sensors(JsonObject& doc)
|
||||||
|
{
|
||||||
|
/* Sensor Name */
|
||||||
|
JsonObject sensor = doc.createNestedObject(F("Custom"));
|
||||||
|
|
||||||
|
/* Key-Value pair of the sensor value */
|
||||||
|
sensor[F("Random")] = random(256);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // HASP_USE_CUSTOM
|
30
src/custom/my_custom_template.h
Normal file
30
src/custom/my_custom_template.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
|
||||||
|
For full license information read the LICENSE file in the project folder */
|
||||||
|
|
||||||
|
#ifndef HASP_CUSTOM_H
|
||||||
|
#define HASP_CUSTOM_H
|
||||||
|
|
||||||
|
#include "hasplib.h"
|
||||||
|
#if HASP_USE_CUSTOM > 0
|
||||||
|
|
||||||
|
/* This function is called at boot */
|
||||||
|
void custom_setup();
|
||||||
|
|
||||||
|
/* This function is called every itteration of the main loop */
|
||||||
|
void custom_loop();
|
||||||
|
|
||||||
|
/* This function is called every second */
|
||||||
|
void custom_every_second();
|
||||||
|
|
||||||
|
/* This function is called every 5 seconds */
|
||||||
|
void custom_every_5seconds();
|
||||||
|
|
||||||
|
/* return true if the pin used by the custom code */
|
||||||
|
bool custom_pin_in_use(uint pin);
|
||||||
|
|
||||||
|
/* Add a key which defines a JsonObject to add to the sensor JSON output */
|
||||||
|
void custom_get_sensors(JsonObject& doc);
|
||||||
|
|
||||||
|
#endif // HASP_USE_CUSTOM
|
||||||
|
|
||||||
|
#endif // HASP_CUSTOM_H
|
Loading…
x
Reference in New Issue
Block a user