From 37fef2891140074b809f79102be793d2ff8d644a Mon Sep 17 00:00:00 2001 From: Skittles Date: Wed, 22 Apr 2026 22:47:12 -0700 Subject: [PATCH] Add initial sensor sampler and processing components --- app/CMakeLists.txt | 9 ++++++++- app/src/SensorDataProcessor.cpp | 9 +++++++++ app/src/SensorDataProcessor.hpp | 19 +++++++++++++++++++ app/src/SensorSampler.cpp | 9 +++++++++ app/src/SensorSampler.hpp | 19 +++++++++++++++++++ app/src/main.cpp | 21 ++++++++++++++++++--- 6 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 app/src/SensorDataProcessor.cpp create mode 100644 app/src/SensorDataProcessor.hpp create mode 100644 app/src/SensorSampler.cpp create mode 100644 app/src/SensorSampler.hpp diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index f639f6c..cf40623 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -9,7 +9,14 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(app LANGUAGES C) -target_sources(app PRIVATE src/main.cpp) +target_sources(app + PRIVATE + src/main.cpp + src/SensorDataProcessor.cpp + src/SensorDataProcessor.hpp + src/SensorSampler.cpp + src/SensorSampler.hpp +) # The code below locates the git index file for this repository and adds it as a dependency for # the application VERSION file so that if the repo has a new commit added, even if no files in diff --git a/app/src/SensorDataProcessor.cpp b/app/src/SensorDataProcessor.cpp new file mode 100644 index 0000000..f32a11e --- /dev/null +++ b/app/src/SensorDataProcessor.cpp @@ -0,0 +1,9 @@ +#include "SensorDataProcessor.hpp" +#include + +void app::SensorDataProcessor::entryPoint(void *, void *, void *) { + while (true) { + printk("app::SensorDataProcessor::entryPoint - Running...\n"); + k_sleep(K_SECONDS(5)); + } +} diff --git a/app/src/SensorDataProcessor.hpp b/app/src/SensorDataProcessor.hpp new file mode 100644 index 0000000..ae936d1 --- /dev/null +++ b/app/src/SensorDataProcessor.hpp @@ -0,0 +1,19 @@ +#ifndef SENSOR_DATA_PROCESSOR_HPP +#define SENSOR_DATA_PROCESSOR_HPP + +namespace app { + +class SensorDataProcessor { +public: + SensorDataProcessor() = default; + ~SensorDataProcessor() = default; + + // Thread entry + static void entryPoint(void *, void *, void *); + +private: +}; + +} // namespace app + +#endif diff --git a/app/src/SensorSampler.cpp b/app/src/SensorSampler.cpp new file mode 100644 index 0000000..3cc8471 --- /dev/null +++ b/app/src/SensorSampler.cpp @@ -0,0 +1,9 @@ +#include "SensorSampler.hpp" +#include + +void app::SensorSampler::entryPoint(void *, void *, void *) { + while (true) { + printk("app::SensorSampler::entryPoint - Running...\n"); + k_sleep(K_SECONDS(5)); + } +} diff --git a/app/src/SensorSampler.hpp b/app/src/SensorSampler.hpp new file mode 100644 index 0000000..606687e --- /dev/null +++ b/app/src/SensorSampler.hpp @@ -0,0 +1,19 @@ +#ifndef SENSOR_SAMPLER_HPP +#define SENSOR_SAMPLER_HPP + +namespace app { + +class SensorSampler { +public: + SensorSampler() = default; + ~SensorSampler() = default; + + // Thread entry + static void entryPoint(void *, void *, void *); + +private: +}; + +} // namespace app + +#endif diff --git a/app/src/main.cpp b/app/src/main.cpp index 888e381..9570a5d 100644 --- a/app/src/main.cpp +++ b/app/src/main.cpp @@ -3,19 +3,34 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include "SensorDataProcessor.hpp" +#include "SensorSampler.hpp" +#include #include #include -#include - LOG_MODULE_REGISTER(main, CONFIG_APP_LOG_LEVEL); +// Sensor Data Processor +static constexpr size_t SensorDataProcessorStackSize = 1024; +static constexpr size_t SensorDataProcessorPriority = 5; +K_THREAD_DEFINE(SensorDataProcessorThreadId, SensorDataProcessorStackSize, + app::SensorDataProcessor::entryPoint, NULL, NULL, NULL, + SensorDataProcessorPriority, 0, 0); + +// Sensor Sampler +static constexpr size_t SensorSamplerStackSize = 1024; +static constexpr size_t SensorSamplerPriority = 5; +K_THREAD_DEFINE(SensorSamplerThreadId, SensorSamplerStackSize, + app::SensorSampler::entryPoint, NULL, NULL, NULL, + SensorSamplerPriority, 0, 0); + int main() { printk("Zephyr Example Application %s\n", APP_VERSION_STRING); printk("Build with C++ standard: %ldL\n", __cplusplus); while (true) { - printk("Running...\n"); + printk("main - Running...\n"); k_sleep(K_SECONDS(5)); }