Skip to content

TinyMeasurement CONFIGURATION

Info

This header file configures the entire TinyMeasurement module, and each submodule includes this header file. It defines the configuration options and macros for TinyMeasurement, allowing users to customize settings as needed. By modifying the configuration options in this header file, users can easily adjust the behavior and functionality of TinyMeasurement to meet specific requirements. The documentation update speed is slow and may not be consistent with the actual code, please refer to the actual code.

Overview

The tiny_measurement_config.h header file contains all configuration macros for the TinyMeasurement middleware. All configuration options use the #ifndef pattern, which means you can override any default value by defining the macro before including this header file.

Configuration Categories

Online Sensing Configuration

These macros control the default behavior of online sensing operations:

  • Sampling Frequency: Default rate for continuous data acquisition (0.1 - 1000 Hz, default: 1.0 Hz, practical limit: ~200 Hz, primarily constrained by MQTT transmission bandwidth)
  • Note: Code comment says "Default: 20.0 Hz" but actual default value is 1.0 Hz
  • MQTT Transmission: Enable/disable automatic MQTT data transmission
  • Serial Output: Enable/disable console output via printf and ESP_LOG
  • LCD Display: Optional LCD display support (requires compilation flag)

Offline Sensing Configuration

These macros control high-frequency batch data collection:

  • Sampling Frequency: Higher default rate for offline collection (1 - 4000 Hz)
  • Sampling Duration: How long to collect data (0.1 - 3600 seconds)
  • Storage Options: Enable/disable SD card and memory buffer storage
  • MQTT Report: Enable/disable MQTT reporting after sampling completes

Real-Time Processing Architecture Configuration

These macros control real-time data processing with three architecture options:

  • Sampling Frequency: Default rate for real-time processing (Architecture 1: 0.1 - 1000 Hz, Architecture ⅔: 0.1 - 10000 Hz)
  • Note: Config default is 20.0 Hz, but actual architecture implementations use 100.0 Hz as hardcoded default
  • MQTT/Serial Output: Enable/disable output channels
  • Acceleration Detection: Enable/disable real-time detection with LCD feedback
  • Architecture-Specific: Buffer sizes, task priorities, stack sizes, and core assignments for each architecture
  • Common Settings: LCD update intervals and acceleration detection thresholds

Customization

To customize any default value, define the macro before including the header:

// Override default online sensing frequency
#define TINY_MEASUREMENT_ONLINE_SENSING_DEFAULT_FREQ_HZ 10.0f

#include "tiny_measurement.h"
/**
 * @file tiny_measurement_config.h
 * @author SHUAIWEN CUI (SHUAIWEN001@e.ntu.edu.sg)
 * @brief The configuration file for the tiny_measurement middleware.
 * @version 1.0
 * @date 2025-12-17
 * @copyright Copyright (c) 2025
 *
 */

#pragma once

/* DEPENDENCIES */

// lower level dependencies
#include "tiny_ai.h"

#ifdef __cplusplus
extern "C"
{
#endif

/* ============================================================================
 * ONLINE SENSING CONFIGURATION MACROS
 * ============================================================================ */

/**
 * @brief Default sampling frequency for online sensing (Hz)
 * @note Valid range: 0.1 - 1000 Hz (code validates up to 300 Hz)
 * @note Default: 1.0 Hz
 * @note Note: Code comment says "Default: 20.0 Hz" but actual default value is 1.0 Hz
 */
#ifndef TINY_MEASUREMENT_ONLINE_SENSING_DEFAULT_FREQ_HZ
#define TINY_MEASUREMENT_ONLINE_SENSING_DEFAULT_FREQ_HZ 1.0f
#endif

/**
 * @brief Default MQTT transmission enable state for online sensing
 * @note true: Enable MQTT transmission
 * @note false: Disable MQTT transmission
 * @note Default: true
 */
#ifndef TINY_MEASUREMENT_ONLINE_SENSING_DEFAULT_ENABLE_MQTT
#define TINY_MEASUREMENT_ONLINE_SENSING_DEFAULT_ENABLE_MQTT true
#endif

/**
 * @brief Default serial output enable state for online sensing
 * @note true: Enable serial output (printf and ESP_LOG)
 * @note false: Disable serial output
 * @note Default: true
 */
#ifndef TINY_MEASUREMENT_ONLINE_SENSING_DEFAULT_ENABLE_SERIAL
#define TINY_MEASUREMENT_ONLINE_SENSING_DEFAULT_ENABLE_SERIAL true
#endif

/* ============================================================================
 * LCD DISPLAY FEATURE COMPILATION CONTROL
 * ============================================================================ */

/**
 * @brief Enable LCD display feature compilation
 * @note Define this macro to enable LCD display support in online sensing
 * @note If not defined, all LCD-related code will be excluded from compilation
 * @note Default: NOT DEFINED (LCD feature disabled by default)
 * @note To enable: Add -DTINY_MEASUREMENT_ENABLE_LCD to compiler flags
 */
#ifdef TINY_MEASUREMENT_ENABLE_LCD
/**
 * @brief Default LCD display enable state for online sensing
 * @note Only available when TINY_MEASUREMENT_ENABLE_LCD is defined
 * @note true: Enable LCD display output
 * @note false: Disable LCD display output
 * @note Default: false
 */
#ifndef TINY_MEASUREMENT_ONLINE_SENSING_DEFAULT_ENABLE_LCD
#define TINY_MEASUREMENT_ONLINE_SENSING_DEFAULT_ENABLE_LCD true
#endif
#endif /* TINY_MEASUREMENT_ENABLE_LCD */

/* ============================================================================
 * OFFLINE SENSING CONFIGURATION MACROS
 * ============================================================================ */

/**
 * @brief Default sampling frequency for offline sensing (Hz)
 * @note Valid range: 1 - 4000 Hz
 * @note Maximum frequency (4000 Hz) is limited by ADXL355 sensor's maximum output data rate (ODR)
 * @note ADXL355 hardware supports up to 4000 Hz ODR, which is the sensor's physical limit
 * @note Default: 100.0 Hz (high frequency for offline sensing)
 */
#ifndef TINY_MEASUREMENT_OFFLINE_SENSING_DEFAULT_FREQ_HZ
#define TINY_MEASUREMENT_OFFLINE_SENSING_DEFAULT_FREQ_HZ 100.0f
#endif

/**
 * @brief Default sampling duration for offline sensing (seconds)
 * @note Valid range: 0.1 - 3600 seconds
 * @note Default: 10.0 seconds
 */
#ifndef TINY_MEASUREMENT_OFFLINE_SENSING_DEFAULT_DURATION_SEC
#define TINY_MEASUREMENT_OFFLINE_SENSING_DEFAULT_DURATION_SEC 10.0f
#endif

/**
 * @brief Default SD card storage enable state for offline sensing
 * @note true: Enable SD card storage
 * @note false: Disable SD card storage (only memory buffer)
 * @note Default: true
 */
#ifndef TINY_MEASUREMENT_OFFLINE_SENSING_DEFAULT_ENABLE_SD
#define TINY_MEASUREMENT_OFFLINE_SENSING_DEFAULT_ENABLE_SD true
#endif

/**
 * @brief Default memory buffer storage enable state for offline sensing
 * @note true: Enable memory buffer storage
 * @note false: Disable memory buffer storage (only SD card)
 * @note Default: true
 */
#ifndef TINY_MEASUREMENT_OFFLINE_SENSING_DEFAULT_ENABLE_MEMORY
#define TINY_MEASUREMENT_OFFLINE_SENSING_DEFAULT_ENABLE_MEMORY true
#endif

/**
 * @brief Default MQTT report enable state for offline sensing
 * @note true: Enable MQTT report after sampling
 * @note false: Disable MQTT report
 * @note Default: true
 */
#ifndef TINY_MEASUREMENT_OFFLINE_SENSING_DEFAULT_ENABLE_MQTT_REPORT
#define TINY_MEASUREMENT_OFFLINE_SENSING_DEFAULT_ENABLE_MQTT_REPORT true
#endif

/* ============================================================================
 * REAL-TIME PROCESSING ARCHITECTURE CONFIGURATION MACROS
 * ============================================================================ */

/**
 * @brief Default sampling frequency for real-time processing (Hz)
 * @note Valid range: Architecture 1: 0.1 - 1000 Hz, Architecture 2/3: 0.1 - 10000 Hz
 * @note Default: 20.0 Hz (in config), but actual code uses 100.0 Hz as default
 * @note Note: Actual architecture implementations use 100.0 Hz as hardcoded default
 */
#ifndef TINY_MEASUREMENT_RT_PROCESS_DEFAULT_FREQ_HZ
#define TINY_MEASUREMENT_RT_PROCESS_DEFAULT_FREQ_HZ 20.0f
#endif

/**
 * @brief Default MQTT transmission enable state for real-time processing
 * @note true: Enable MQTT transmission
 * @note false: Disable MQTT transmission
 * @note Default: false (disabled for real-time processing)
 */
#ifndef TINY_MEASUREMENT_RT_PROCESS_DEFAULT_ENABLE_MQTT
#define TINY_MEASUREMENT_RT_PROCESS_DEFAULT_ENABLE_MQTT false
#endif

/**
 * @brief Default serial output enable state for real-time processing
 * @note true: Enable serial output (printf and ESP_LOG)
 * @note false: Disable serial output
 * @note Default: true
 */
#ifndef TINY_MEASUREMENT_RT_PROCESS_DEFAULT_ENABLE_SERIAL
#define TINY_MEASUREMENT_RT_PROCESS_DEFAULT_ENABLE_SERIAL true
#endif

/**
 * @brief Default acceleration detection enable state for real-time processing
 * @note true: Enable acceleration detection with LCD feedback
 * @note false: Disable acceleration detection
 * @note Default: true
 */
#ifndef TINY_MEASUREMENT_RT_PROCESS_DEFAULT_ENABLE_ACCEL_DETECTION
#define TINY_MEASUREMENT_RT_PROCESS_DEFAULT_ENABLE_ACCEL_DETECTION true
#endif

/* ============================================================================
 * PRODUCER-CONSUMER ARCHITECTURE CONFIGURATION
 * ============================================================================ */

/**
 * @brief Circular buffer size for Producer-Consumer architecture
 * @note Number of samples stored in the circular buffer
 * @note Default: 512 samples
 * @note Memory usage: buffer_size × sizeof(rt_process_sample_t) ≈ buffer_size × 28 bytes
 */
#ifndef TINY_MEASUREMENT_RT_PC_CIRCULAR_BUFFER_SIZE
#define TINY_MEASUREMENT_RT_PC_CIRCULAR_BUFFER_SIZE 512
#endif

/**
 * @brief Consumer processing interval for Producer-Consumer architecture (milliseconds)
 * @note How often the consumer task processes data from the buffer
 * @note Default: 50 ms (20 times per second)
 */
#ifndef TINY_MEASUREMENT_RT_PC_CONSUMER_PROCESS_INTERVAL_MS
#define TINY_MEASUREMENT_RT_PC_CONSUMER_PROCESS_INTERVAL_MS 50
#endif

/**
 * @brief Number of recent samples to process in Producer-Consumer architecture
 * @note Consumer processes the last N samples for real-time response
 * @note Default: 10 samples
 */
#ifndef TINY_MEASUREMENT_RT_PC_CONSUMER_PROCESS_SAMPLE_COUNT
#define TINY_MEASUREMENT_RT_PC_CONSUMER_PROCESS_SAMPLE_COUNT 10
#endif

/**
 * @brief Default queue size for Producer-Consumer architecture (legacy, not used with circular buffer)
 * @note Default: 50
 */
#ifndef TINY_MEASUREMENT_RT_PC_QUEUE_SIZE_DEFAULT
#define TINY_MEASUREMENT_RT_PC_QUEUE_SIZE_DEFAULT 50
#endif

/**
 * @brief Producer task priority for Producer-Consumer architecture
 * @note Higher priority ensures timely data acquisition
 * @note Default: 10 (high priority)
 */
#ifndef TINY_MEASUREMENT_RT_PC_PRODUCER_PRIORITY
#define TINY_MEASUREMENT_RT_PC_PRODUCER_PRIORITY 10
#endif

/**
 * @brief Consumer task priority for Producer-Consumer architecture
 * @note Default: 8 (high priority, slightly lower than producer)
 */
#ifndef TINY_MEASUREMENT_RT_PC_CONSUMER_PRIORITY
#define TINY_MEASUREMENT_RT_PC_CONSUMER_PRIORITY 8
#endif

/**
 * @brief Producer task stack size for Producer-Consumer architecture (bytes)
 * @note Default: 4096 bytes
 */
#ifndef TINY_MEASUREMENT_RT_PC_PRODUCER_STACK_SIZE
#define TINY_MEASUREMENT_RT_PC_PRODUCER_STACK_SIZE 4096
#endif

/**
 * @brief Consumer task stack size for Producer-Consumer architecture (bytes)
 * @note Default: 8192 bytes (larger for processing tasks)
 */
#ifndef TINY_MEASUREMENT_RT_PC_CONSUMER_STACK_SIZE
#define TINY_MEASUREMENT_RT_PC_CONSUMER_STACK_SIZE 8192
#endif

/* ============================================================================
 * DMA + DOUBLE BUFFER ARCHITECTURE CONFIGURATION
 * ============================================================================ */

/**
 * @brief Buffer size for each buffer in DMA + Double Buffer architecture
 * @note Each buffer (A and B) holds this many samples
 * @note Default: 512 samples per buffer
 * @note Total memory: 2 × buffer_size × sizeof(rt_process_sample_t) ≈ 2 × buffer_size × 28 bytes
 */
#ifndef TINY_MEASUREMENT_RT_DMA_DB_BUFFER_SIZE
#define TINY_MEASUREMENT_RT_DMA_DB_BUFFER_SIZE 512
#endif

/**
 * @brief Producer task priority for DMA + Double Buffer architecture
 * @note Default: 10 (high priority)
 */
#ifndef TINY_MEASUREMENT_RT_DMA_DB_PRODUCER_PRIORITY
#define TINY_MEASUREMENT_RT_DMA_DB_PRODUCER_PRIORITY 10
#endif

/**
 * @brief Consumer task priority for DMA + Double Buffer architecture
 * @note Default: 8 (high priority)
 */
#ifndef TINY_MEASUREMENT_RT_DMA_DB_CONSUMER_PRIORITY
#define TINY_MEASUREMENT_RT_DMA_DB_CONSUMER_PRIORITY 8
#endif

/**
 * @brief Producer task stack size for DMA + Double Buffer architecture (bytes)
 * @note Default: 4096 bytes
 */
#ifndef TINY_MEASUREMENT_RT_DMA_DB_PRODUCER_STACK_SIZE
#define TINY_MEASUREMENT_RT_DMA_DB_PRODUCER_STACK_SIZE 4096
#endif

/**
 * @brief Consumer task stack size for DMA + Double Buffer architecture (bytes)
 * @note Default: 8192 bytes
 */
#ifndef TINY_MEASUREMENT_RT_DMA_DB_CONSUMER_STACK_SIZE
#define TINY_MEASUREMENT_RT_DMA_DB_CONSUMER_STACK_SIZE 8192
#endif

/* ============================================================================
 * DMA + DUAL CORE ARCHITECTURE CONFIGURATION
 * ============================================================================ */

/**
 * @brief Buffer size for each buffer in DMA + Dual Core architecture
 * @note Each buffer (A and B) holds this many samples
 * @note Default: 256 samples per buffer
 * @note Total memory: 2 × buffer_size × sizeof(rt_process_sample_t) ≈ 2 × buffer_size × 28 bytes
 */
#ifndef TINY_MEASUREMENT_RT_DMA_DC_BUFFER_SIZE
#define TINY_MEASUREMENT_RT_DMA_DC_BUFFER_SIZE 256
#endif

/**
 * @brief Producer task priority for DMA + Dual Core architecture
 * @note Runs on Core 0
 * @note Default: 10 (high priority)
 */
#ifndef TINY_MEASUREMENT_RT_DMA_DC_PRODUCER_PRIORITY
#define TINY_MEASUREMENT_RT_DMA_DC_PRODUCER_PRIORITY 10
#endif

/**
 * @brief Consumer task priority for DMA + Dual Core architecture
 * @note Runs on Core 1
 * @note Default: 10 (high priority)
 */
#ifndef TINY_MEASUREMENT_RT_DMA_DC_CONSUMER_PRIORITY
#define TINY_MEASUREMENT_RT_DMA_DC_CONSUMER_PRIORITY 10
#endif

/**
 * @brief Producer task stack size for DMA + Dual Core architecture (bytes)
 * @note Default: 4096 bytes
 */
#ifndef TINY_MEASUREMENT_RT_DMA_DC_PRODUCER_STACK_SIZE
#define TINY_MEASUREMENT_RT_DMA_DC_PRODUCER_STACK_SIZE 4096
#endif

/**
 * @brief Consumer task stack size for DMA + Dual Core architecture (bytes)
 * @note Default: 8192 bytes
 */
#ifndef TINY_MEASUREMENT_RT_DMA_DC_CONSUMER_STACK_SIZE
#define TINY_MEASUREMENT_RT_DMA_DC_CONSUMER_STACK_SIZE 8192
#endif

/**
 * @brief Core assignment for producer task in DMA + Dual Core architecture
 * @note Default: 0 (Core 0 for data acquisition)
 */
#ifndef TINY_MEASUREMENT_RT_DMA_DC_PRODUCER_CORE
#define TINY_MEASUREMENT_RT_DMA_DC_PRODUCER_CORE 0
#endif

/**
 * @brief Core assignment for consumer task in DMA + Dual Core architecture
 * @note Default: 1 (Core 1 for data processing)
 */
#ifndef TINY_MEASUREMENT_RT_DMA_DC_CONSUMER_CORE
#define TINY_MEASUREMENT_RT_DMA_DC_CONSUMER_CORE 1
#endif

/* ============================================================================
 * COMMON REAL-TIME PROCESSING CONFIGURATION
 * ============================================================================ */

/**
 * @brief LCD color hold duration for acceleration detection (microseconds)
 * @note How long the LCD color change persists after condition is detected
 * @note Default: 300000 us (0.3 seconds = 300 ms)
 */
#ifndef TINY_MEASUREMENT_RT_LCD_COLOR_HOLD_DURATION_US
#define TINY_MEASUREMENT_RT_LCD_COLOR_HOLD_DURATION_US 300000U
#endif

/**
 * @brief Minimum interval between LCD updates to avoid SPI bus conflicts (microseconds)
 * @note Prevents concurrent LCD updates that could cause SPI bus errors
 * @note Default: 100000 us (0.1 seconds = 100 ms)
 */
#ifndef TINY_MEASUREMENT_RT_LCD_UPDATE_MIN_INTERVAL_US
#define TINY_MEASUREMENT_RT_LCD_UPDATE_MIN_INTERVAL_US 100000U
#endif

/**
 * @brief Acceleration detection threshold for X axis (g)
 * @note Condition: |x| > threshold triggers detection
 * @note Default: 0.5g
 */
#ifndef TINY_MEASUREMENT_RT_ACCEL_THRESHOLD_X
#define TINY_MEASUREMENT_RT_ACCEL_THRESHOLD_X 0.5f
#endif

/**
 * @brief Acceleration detection threshold for Y axis (g)
 * @note Condition: |y| > threshold triggers detection
 * @note Default: 0.5g
 */
#ifndef TINY_MEASUREMENT_RT_ACCEL_THRESHOLD_Y
#define TINY_MEASUREMENT_RT_ACCEL_THRESHOLD_Y 0.5f
#endif

/**
 * @brief Acceleration detection threshold for Z axis (g)
 * @note Condition: |z| < threshold triggers detection
 * @note Default: 0.5g
 */
#ifndef TINY_MEASUREMENT_RT_ACCEL_THRESHOLD_Z
#define TINY_MEASUREMENT_RT_ACCEL_THRESHOLD_Z 0.5f
#endif

#ifdef __cplusplus
}
#endif