/* Casquette de golf
*
* Copyright 2019 Jean PRABIS
* Inspired from :
* Copyright 2016-2019 Baptiste PELLEGRIN
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
/**********************************************************/
/* Version simplifiée avec seulement altimètre et MPU9250 */
/* Juillet 2019 pour casquette de golf "tenue de tête" */
/**********************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
/*!! !!! WARNING !!! !!*/
/*!! Before building check : !!*/
/*!! libraries/VarioSettings/VarioSettings.h !!*/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
/*******************/
/* General objects */
/*******************/
#define VARIOMETER_POWER_ON_DELAY 2000
#define VARIOMETER_STATE_INITIAL 0
#define VARIOMETER_STATE_DATE_RECORDED 1
#define VARIOMETER_STATE_CALIBRATED 2
#define VARIOMETER_STATE_FLIGHT_STARTED 3
/**********************/
/* alti/vario objects */
/**********************/
#define POSITION_MEASURE_STANDARD_DEVIATION 0.1
#define ACCELERATION_MEASURE_STANDARD_DEVIATION 0.3
kalmanvert kalmanvert;
beeper beeper(VARIOMETER_SINKING_THRESHOLD, VARIOMETER_CLIMBING_THRESHOLD, VARIOMETER_NEAR_CLIMBING_SENSITIVITY, VARIOMETER_BEEP_VOLUME);
/* tap callback : mute/unmute beeper */
void beeperTapCallback(unsigned char direction, unsigned char count) {
static bool muted = false;
muted = !muted;
toneACMute(muted);
}
/*-----------------*/
/* SETUP */
/*-----------------*/
void setup() {
/*****************************/
/* wait for devices power on */
/*****************************/
delay(VARIOMETER_POWER_ON_DELAY);
/**********************/
/* init accelerometer */
/**********************/
Fastwire::setup(FASTWIRE_SPEED, 0);
vertaccel_init();
fastMPUSetTapCallback(beeperTapCallback);
/******************/
/* init barometer */
/******************/
ms5611_init();
/******************/
/* get first data */
/******************/
/* wait for first alti and acceleration */
while( ! (ms5611_dataReady()
#ifdef HAVE_ACCELEROMETER
&& vertaccel_dataReady()
#endif //HAVE_ACCELEROMETER
) ) {
}
/* get first data */
ms5611_updateData();
vertaccel_updateData();
/* init kalman filter */
kalmanvert.init(ms5611_getAltitude(),
vertaccel_getValue(),
POSITION_MEASURE_STANDARD_DEVIATION,
ACCELERATION_MEASURE_STANDARD_DEVIATION,
millis());
}
void enableflightStartComponents(void);
/*----------------*/
/* LOOP */
/*----------------*/
void loop() {
/*****************************/
/* compute vertical velocity */
/*****************************/
if( ms5611_dataReady() && vertaccel_dataReady() ) {
ms5611_updateData();
vertaccel_updateData();
kalmanvert.update( ms5611_getAltitude(),
vertaccel_getValue(),
millis() );
/* set beeper */
beeper.setVelocity( kalmanvert.getVelocity() );
}
/*****************/
/* update beeper */
/*****************/
beeper.update();
}
void enableflightStartComponents(void) {
/* enable near climbing */
#ifdef VARIOMETER_ENABLE_NEAR_CLIMBING_ALARM
beeper.setGlidingAlarmState(true);
#endif
#ifdef VARIOMETER_ENABLE_NEAR_CLIMBING_BEEP
beeper.setGlidingBeepState(true);
#endif
}