project
Ghost Hand
Public Unreviewedby John Lauer
A small battery gadget that keeps an automatic sink faucet running while you use the sink: it learns the faucet's timeout, re-arms with the shortest blip, and stops after 10 minutes or when picked up.
main
John Lauer
Studio: project overview, how it works, lights, charging, battery life, firmware source, dashboard screenshots; licenseā¦
c2eaf61
3d ago
/*
* accel.h : LIS2DW12 over TWI0 (PB0 SCL, PB1 SDA, address 0x19)
*/
#ifndef ACCEL_H
#define ACCEL_H
#include <stdint.h>
#include <stdbool.h>
typedef struct { int16_t x, y, z; } vec_mg_t;
bool acc_init(void); /* TWI on, WHO_AM_I check, base configuration */
void acc_mode_sleep(void); /* LP mode 1, 12.5 Hz, wake-up on 62.5 mg to INT1, latched */
void acc_mode_watch(uint16_t wake_mg); /* LP mode 1, 50 Hz, wake-up threshold to INT1 */
bool acc_read(vec_mg_t *v); /* latest sample in mg */
void acc_clear_int(void); /* read the sources: releases the latched INT1 */
void twi_off(void); /* TWI disabled, pins released (external pull-ups) */
/* geometry helpers (pure integer math) */
bool vec_tilt_over_30(const vec_mg_t *a, const vec_mg_t *b); /* angle(a,b) > 30 deg */
uint32_t vec_dist2(const vec_mg_t *a, const vec_mg_t *b); /* |a-b|^2 in mg^2 */
#endif