Add my_custom_template

This commit is contained in:
fvanroie 2021-07-12 03:56:41 +02:00
parent a2ab8cfc2c
commit 3b377c8814
3 changed files with 79 additions and 0 deletions

2
.gitignore vendored
View File

@ -19,6 +19,8 @@ build_output/firmware/*.exe
src/custom/*
!src/custom/README.md
!src/custom/bootlogo_template.h
!src/custom/my_custom_template.h
!src/custom/my_custom_template.cpp
## Test result files
*.xml

View 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

View 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