FluxSand 1.0
FluxSand - Interactive Digital Hourglass
Loading...
Searching...
No Matches
main.cpp
1#include <format>
2#include <iostream>
3#include <thread>
4
5#include "ads1115.hpp"
6#include "aht20.hpp"
7#include "bmp280.hpp"
8#include "bsp_gpio.hpp"
9#include "bsp_i2c.hpp"
10#include "bsp_pwm.hpp"
11#include "bsp_spi.hpp"
12#include "comp_ahrs.hpp"
13#include "comp_gui.hpp"
14#include "comp_inference.hpp"
15#include "fluxsand.hpp"
16#include "max7219.hpp"
17#include "mpu9250.hpp"
18
19int main() {
20 /* Buzzer */
21 PWM pwm_buzzer(0, 50, 7.5);
22
23 pwm_buzzer.PlayNote(PWM::NoteName::C, 7, 250);
24 std::this_thread::sleep_for(std::chrono::milliseconds(300));
25 pwm_buzzer.PlayNote(PWM::NoteName::D, 7, 250);
26 std::this_thread::sleep_for(std::chrono::milliseconds(300));
27 pwm_buzzer.PlayNote(PWM::NoteName::E, 7, 250);
28 std::this_thread::sleep_for(std::chrono::milliseconds(300));
29
30 pwm_buzzer.Disable();
31
32 /* User button */
33 Gpio gpio_user_button_1("gpiochip0", 23, false, 1);
34 Gpio gpio_user_button_2("gpiochip0", 24, false, 1);
35
36 /* Max7219 display */
37 SpiDevice spi_display("/dev/spidev1.0", 1000000, SPI_MODE_0);
38 Gpio gpio_display_cs("gpiochip0", 26, true, 1);
39 Max7219<8> display(spi_display, &gpio_display_cs);
40
41 /* BMP280 and AHT20 */
42 I2cDevice i2c_bmp280("/dev/i2c-1", Bmp280::DEFAULT_I2C_ADDR);
43 Bmp280 bmp280(i2c_bmp280);
44
45 I2cDevice i2c_aht20("/dev/i2c-1", Aht20::DEFAULT_I2C_ADDR);
46 Aht20 aht20(i2c_aht20);
47
48 /* ADS1115 */
49 I2cDevice i2c_mpu9250("/dev/i2c-0", Ads1115<2>::DEFAULT_I2C_ADDR);
50 Gpio gpio_ads1115_int("gpiochip0", 5, false, 1);
51 Ads1115<2> ads1115(i2c_mpu9250, gpio_ads1115_int);
52
53 /* MPU9250 */
54 SpiDevice spi_imu_device("/dev/spidev0.0", 1000000, SPI_MODE_0);
55 Gpio gpio_imu_cs("gpiochip0", 22, true, 1);
56 Gpio gpio_imu_int("gpiochip0", 27, false, 1);
57 Mpu9250 mpu9250(&spi_imu_device, &gpio_imu_cs, &gpio_imu_int);
58
59 /* Orientation prediction and CNN model inference */
60 AHRS ahrs;
61 mpu9250.RegisterDataCallback(std::bind(
62 &AHRS::OnData, &ahrs, std::placeholders::_1, std::placeholders::_2));
63
64 InferenceEngine inference_engine(ONNX_MODEL_PATH, 0.1f, 0.65f, 6, 3);
65 ahrs.RegisterDataCallback(std::bind(
66 &InferenceEngine::OnData, &inference_engine, std::placeholders::_1,
67 std::placeholders::_2, std::placeholders::_3));
68
69 CompGuiX gui(display);
70
71 gui.Clear();
72
73 /* Main loop */
74 FluxSand fluxsand(&pwm_buzzer, &gpio_user_button_1, &gpio_user_button_2, &gui,
75 &bmp280, &aht20, &ads1115, &ahrs, &inference_engine);
76
77 while (true) {
78 fluxsand.Run();
79 }
80
81 return 0;
82}
ADS1115 ADC driver with GPIO interrupt-based channel cycling.
Definition ads1115.hpp:22
static constexpr uint8_t DEFAULT_I2C_ADDR
Definition bmp280.hpp:18
LED Matrix GUI Controller with Dual Orientation Support and Sand Animation Physics.
Definition comp_gui.hpp:15
PWM driver with Beep and PlayNote functionality.
Definition bsp_pwm.hpp:21