Skip to content

Latest commit

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

OneSensor

HAPI Compatibility: Works with new Check/Apply/ApplyPack API (2026-Q2)

HAPI sensor driver components — parameterized on bus and chip at compile time. Zero dynamic allocation, pure-static dispatch.

Part of the InternetOfPins project family.

Overview

Each sensor is a HAPI component. The bus (I2C, 1-Wire) is injected as a template parameter, so the same driver works across AVR, ESP32, and any other target that provides a compatible bus implementation.

Drivers in this library depend on OneBus for bus types. For drivers that live directly in a project without the OneBus dependency, see the standalone versions in OneIO (oneIO/sensor/).

Drivers

DS18B20 — 1-Wire temperature sensor

#include<oneSensor/temperature/ds18b20.h>
#include<oneBus/oneWire.h>// OneWire bus: Arduino pin 4 (any target)using Bus = oneBus::OneWire<4>;
using Temp = oneSensor::DS18B20<Bus>;
using Api = Temp::Api; // hapi::APIOf<SensorDef, DS18B20<Bus>>Api::begin();
// Non-blocking: trigger, wait 750 ms, readApi::trigger();
// ... do other work for 750 ms ...auto r = Api::read();
if (r.ok) printf("%.2f °C\n", r.tempC());
// Blocking: trigger + wait + read in one callauto r2 = Api::sample();

For AVR with cycle-accurate timing:

#include<oneBus/oneWire.h>
#include<chips/avr/avrPort.h>using Bus = oneBus::AvrOneWire<hw::avr::chip::PortC, 4>; // PC4 = A4using Api = oneSensor::DS18B20<Bus>::Api;

MPU6050 — I2C 6-axis IMU

#include<oneSensor/imu/mpu6050.h>// TwiMaster: any compatible I2C master (AvrTwiMaster, ArduinoWire, ...)using Imu = oneSensor::MPU6050<TwiMaster>;
using Api = Imu::Api;
Api::begin(); // wakes device, sets default gyro/accel rangesauto r = Api::read(); // burst-read 14 bytes, returns Readingprintf("ax=%d ay=%d az=%d\n", r.ax, r.ay, r.az);
printf("gx=%d gy=%d gz=%d\n", r.gx, r.gy, r.gz);
printf("temp=%.2f °C\n", r.tempC());
// Optional: change full-scale range before begin()Api::setGyroRange(oneInput::MPU6050<TwiMaster>::GyroRange::Deg500);
Api::setAccelRange(oneInput::MPU6050<TwiMaster>::AccelRange::G8);

Default I2C address is 0x68 (AD0 low). Use MPU6050<TwiMaster, 0x69> when AD0 is pulled high.

Usage summary

#include<oneSensor/oneSensor.h>// includes all sensor headers

Sensors expose Api as a pre-assembled hapi::APIOf<> type. Call static methods directly on Api — no object needed. Multiple sensors on the same bus coexist because each driver controls its own CS / ROM ID; they share the bus type without interference.

License

MIT — see LICENSE.

Author: Rui Azevedo (neu-rah) · Azores, Portugal

About

HAPI sensor driver components — parameterized on bus and chip

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages