JuReceiver/juRCReceiver.h

102 lines
1.9 KiB
C
Raw Normal View History

2023-09-10 15:33:34 +02:00
#ifndef _juRCReceiver_h_
#define _juRCReceiver_h_
#ifndef myId
#error "myId is not defined"
#endif
#ifndef myChannel
#error "myChannel is not defined"
#endif
#ifndef debug
#define debug false
#endif
#include <Preferences.h>
#include <SPI.h>
#include <Wire.h>
#include "pthread.h"
#include <jqueue.h>
#include <jmutex.h>
//
#include "structsAndDefines.h"
on_connect _j_on_connect = nullptr;
on_disconnect _j_on_disconnect = nullptr;
on_data _j_on_data = nullptr;
void jSetOnConnect(on_connect conn) { _j_on_connect = conn; }
void jSetOnDisconnect(on_disconnect conn) { _j_on_disconnect = conn; }
void jSetOnData(on_data conn) { _j_on_data = conn; }
// 3 (CE) 0 //4 (CSN) 4 //5 (SCK) 18 //6 (MOSI) 23 //7 (MISO) 19
// CE CSN
Preferences preferences;
unsigned long last = 0;
unsigned long delta = 0;
float avg = 10;
#include "system_general/rc_handler.h"
//
#include "rcserial.h"
#include "system_sensors/compass.h"
#include "system_sensors/gnss.h"
#include "system_sensors/mpu.h"
void jSetup() {
Serial.begin(115200);
#if debug
Serial.println("start up");
#endif
#if debug
bool prefsucc =
#endif
preferences.begin("data", false);
#if debug
if (!prefsucc) Serial.println("prefs false");
#endif
initRC();
#if debug
Serial.println("inited rc");
#endif
Wire.begin();
#if debug
Serial.println("inited wire");
#endif
initMPU();
#if debug
Serial.println("inited mpu");
#endif
initGNSS();
#if debug
Serial.println("inited gnss");
#endif
initCOMP();
#if debug
Serial.println("inited comp");
#endif
_rc_serial_init();
last = millis();
}
void jSensorLoop() {
unsigned long now = millis();
delta = now - last;
last = now;
avg = avg * 0.9 + delta * 0.1;
#if debug
Serial.println("Sensor Loop, avg = " + String(avg));
#endif
MPULoop();
GNSSLoop();
COMPLoop();
}
void jRadioLoop() { handleRC(); }
#endif