# josmeuleman/frlibintegration architecture

> Architecture diagram of the GitHub repository josmeuleman/frlibintegration, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/josmeuleman/frlibintegration
- Repository: https://github.com/josmeuleman/frlibintegration

## Overview

##### Main Components
- FlightRecorder Logger Component:
- The Logger (FRLogger) – central to aggregating sensor data and writing it to SD.
- Methods such as CheckSD, StartLogger, UpdateSensors, WriteLogger.
- Sensor Abstraction and Implementations:
- The abstract FRSensor class as the parent.
- Concrete sensor classes derived from FRSensor like FRAnalog, FRAS5600, FRBMP280, FRMPU9250, FRMS4525DO, FRTinyGPS, and FRPPMReceiver.
- External and Underlying Dependencies:
- Mention libraries that the project depends on (e.g., FRLibBasics, AS5600, Adafruit_BMP280, MPU9250, TinyGPSPlus-ESP32, etc.).
- Use of Arduino’s I2C (Wire) for sensor initializations.
- Examples / Integration Templates:
- Various example projects (e.g., FRLoggerServoIntegrationTemplate, FRServoControlTemplate, FRTestTwoReceivers) illustrate how the components interact in practice. These examples also showcase different integration patterns like multi-tasking at different frequencies.

##### Relationships and Interactions
- The FRLogger is at the center – it aggregates sensor objects.
- Each sensor class (child of FRSensor) implements two key methods (HeaderString() for CSV/log file headers and SensorString() for data rows) that feed into the logger.
- Sensors are initialized (many with I2C communication via Wire) and then “registered” with the logger using AddSensor.
- Data/invocation flow from sensor initializations to sensor object creation.
- Registration of sensor objects into logger.
- The logger periodically calls UpdateSensors and WriteLogger, gathering data from each sensor.
- Examples illustrate the top-level “main loop” integration where sensor update functions and servo control processes (which run at differing frequencies) operate concurrently.

##### Architectural Patterns and Design Principles
- Modular design with separation of concerns: Logger management is separated from sensor data acquisition.
- Inheritance and polymorphism are key: FRSensor acts as the base class from which specialized sensor classes derive behavior.
- External dependency injection: Many sensor classes require external libraries (and even hardware interfaces) to function.
- Example-driven integration: The project provides sample sketches to illustrate proper usage patterns.

##### Technologies, Frameworks, and Libraries (as important labels
- Arduino IDE environment (and ESP32-specific libraries).
- I2C communication (Wire library).
- External sensor libraries (Adafruit, MPU9250, TinyGPSPlus, etc.).
- SD card logging (via FRLogger).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Hardware/External Interfaces
    subgraph "Hardware/External Interfaces"
        E1["I2C (Wire)"]:::hardware
        E2["SD Card"]:::hardware
        E3["Arduino IDE/ESP32 & External Libs"]:::external
    end

    %% Core Library (src)
    subgraph "Core Library (src)"
        L["FRLogger – handles aggregation and logging"]:::core
        SA["FRSensor (Base Class)"]:::core
        S1["FRAnalog – analog sensor"]:::core
        S2["FRAS5600 – AS5600 sensor"]:::core
        S3["FRBMP280 – pressure sensor"]:::core
        S4["FRMPU9250 – IMU sensor"]:::core
        S5["FRMS4525DO – additional sensor"]:::core
        S6["FRTinyGPS – GPS sensor"]:::core
        S7["FRPPMReceiver – PPM receiver"]:::core
    end

    %% Integration/Examples
    subgraph "Integration/Examples"
        Ex1["FRLoggerServoIntegrationTemplate – servo integration example"]:::example
        Ex2["FRLoggerTemplate – basic logger example"]:::example
        Ex3["FRServoControlTemplate – servo control example"]:::example
        Ex4["FRTestTwoReceivers – two receivers test"]:::example
    end

    %% Inheritance from FRSensor base class
    S1 -->|"inherits"| SA
    S2 -->|"inherits"| SA
    S3 -->|"inherits"| SA
    S4 -->|"inherits"| SA
    S5 -->|"inherits"| SA
    S6 -->|"inherits"| SA
    S7 -->|"inherits"| SA

    %% Sensor registration with FRLogger
    S1 -->|"registers"| L
    S2 -->|"registers"| L
    S3 -->|"registers"| L
    S4 -->|"registers"| L
    S5 -->|"registers"| L
    S6 -->|"registers"| L
    S7 -->|"registers"| L

    %% Hardware interfaces feed sensor initialization
    E1 --- S1
    E1 --- S2
    E1 --- S3
    E1 --- S4
    E1 --- S5
    E1 --- S6
    E1 --- S7

    %% SD Card is used by Logger for logging data
    E2 ---|"log output"| L

    %% External environment provides support to the Core Library
    E3 --- L
    E3 --- SA

    %% Integration examples use the FRLogger component
    Ex1 -->|"uses"| L
    Ex2 -->|"uses"| L
    Ex3 -->|"uses"| L
    Ex4 -->|"uses"| L

    %% Click Events for Component Mappings
    click L "https://github.com/josmeuleman/frlibintegration/blob/main/src/FRLogger.h"
    click SA "https://github.com/josmeuleman/frlibintegration/blob/main/src/FRSensor.h"
    click S1 "https://github.com/josmeuleman/frlibintegration/blob/main/src/FRAnalog.h"
    click S2 "https://github.com/josmeuleman/frlibintegration/blob/main/src/FRAS5600.h"
    click S3 "https://github.com/josmeuleman/frlibintegration/blob/main/src/FRBMP280.h"
    click S4 "https://github.com/josmeuleman/frlibintegration/blob/main/src/FRMPU9250.h"
    click S5 "https://github.com/josmeuleman/frlibintegration/blob/main/src/FRMS4525DO.h"
    click S6 "https://github.com/josmeuleman/frlibintegration/blob/main/src/FRTinyGPS.h"
    click S7 "https://github.com/josmeuleman/frlibintegration/blob/main/src/FRPPMReceiver.h"
    click Ex1 "https://github.com/josmeuleman/frlibintegration/tree/main/examples/FRLoggerServoIntegrationTemplate"
    click Ex2 "https://github.com/josmeuleman/frlibintegration/tree/main/examples/FRLoggerTemplate"
    click Ex3 "https://github.com/josmeuleman/frlibintegration/tree/main/examples/FRServoControlTemplate"
    click Ex4 "https://github.com/josmeuleman/frlibintegration/tree/main/examples/FRTestTwoReceivers"

    %% Styling
    classDef hardware fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef core fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef example fill:#FFFF99,stroke:#333,stroke-width:2px;
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:2px;
```
