From 3b377c8814dce3500fe20bf7215f9f218530eeb1 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Mon, 12 Jul 2021 03:56:41 +0200 Subject: [PATCH] Add my_custom_template --- .gitignore | 2 ++ src/custom/my_custom_template.cpp | 47 +++++++++++++++++++++++++++++++ src/custom/my_custom_template.h | 30 ++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 src/custom/my_custom_template.cpp create mode 100644 src/custom/my_custom_template.h diff --git a/.gitignore b/.gitignore index ec12ef67..f20e5c21 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/src/custom/my_custom_template.cpp b/src/custom/my_custom_template.cpp new file mode 100644 index 00000000..453497fa --- /dev/null +++ b/src/custom/my_custom_template.cpp @@ -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 \ No newline at end of file diff --git a/src/custom/my_custom_template.h b/src/custom/my_custom_template.h new file mode 100644 index 00000000..21322f24 --- /dev/null +++ b/src/custom/my_custom_template.h @@ -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 \ No newline at end of file