STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
main.h
Go to the documentation of this file.
1#pragma once
2
3#include <Adafruit_LIS3DH.h>
4
5// =============================================================================
6// USER CONFIG — adjust these to change behavior
7// =============================================================================
8
9// Full-scale range: LIS3DH_RANGE_2_G, LIS3DH_RANGE_4_G, LIS3DH_RANGE_8_G,
10// LIS3DH_RANGE_16_G For launch detection use _8_G or _16_G
11#define ACCEL_RANGE LIS3DH_RANGE_16_G
12
13// Interrupt threshold in g (e.g., 2.5g distinguishes launch from handling)
14#define INTERRUPT_THRESHOLD_G 2.5f
15
16// Duration: number of ODR cycles the event must persist before triggering
17// At 400 Hz, 1 count = 2.5 ms. 10 counts = 25 ms.
18#define INTERRUPT_DURATION_COUNTS 10
19
20// Output data rate
21#define ACCEL_ODR LIS3DH_DATARATE_400_HZ
22
23// ESP32 GPIO connected to LIS3DH INT1 pin
24#define LIS3DH_INT1_PIN 23
25
26// SPI pins
27#define LIS3DH_CS_PIN 17
28#define LIS3DH_MOSI_PIN 3
29#define LIS3DH_MISO_PIN 16
30#define LIS3DH_CLK_PIN 2
31
32// =============================================================================
33// DERIVED CONSTANTS — do not edit below unless you know what you're doing
34// =============================================================================
35
36// LSB size (mg) per full-scale range setting.
37// ±2g → 16 mg/LSB
38// ±4g → 32 mg/LSB
39// ±8g → 62 mg/LSB (datasheet value)
40// ±16g → 186 mg/LSB (datasheet value)
41static constexpr float lis3dh_lsb_mg(lis3dh_range_t range) {
42 switch (range) {
44 return 16.0f;
46 return 32.0f;
48 return 62.0f;
50 return 186.0f;
51 default:
52 return 16.0f;
53 }
54}
55
56// INT1_THS: 7-bit register, clamped to 0x7F.
57// Value = threshold_g * 1000 / lsb_mg, rounded and clamped.
58static constexpr uint8_t INT1_THS_VALUE = []() -> uint8_t {
59 float lsb = lis3dh_lsb_mg(ACCEL_RANGE);
60 float raw = (INTERRUPT_THRESHOLD_G * 1000.0f) / lsb;
61 uint8_t val = (raw > 127.0f) ? 127 : (uint8_t)raw;
62 return (val == 0) ? 1 : val; // minimum 1
63}();
64
65// INT1_DUR: 7-bit duration register value (ODR cycles)
66static constexpr uint8_t INT1_DUR_VALUE =
67 (INTERRUPT_DURATION_COUNTS > 127) ? 127
This is a library for the Adafruit LIS3DH Accel breakout board.
lis3dh_range_t
A structure to represent scales.
@ LIS3DH_RANGE_16_G
@ LIS3DH_RANGE_8_G
@ LIS3DH_RANGE_2_G
@ LIS3DH_RANGE_4_G
#define ACCEL_RANGE
Definition main.h:11
#define INTERRUPT_DURATION_COUNTS
Definition main.h:18
#define INTERRUPT_THRESHOLD_G
Definition main.h:14
static constexpr float lis3dh_lsb_mg(lis3dh_range_t range)
Definition main.h:41
static constexpr uint8_t INT1_THS_VALUE
Definition config.h:48
static constexpr uint8_t INT1_DUR_VALUE
Definition config.h:55