JuReceiver/juRCReceiver.h

116 lines
2.2 KiB
C
Raw Permalink 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
2023-09-17 13:57:28 +02:00
#ifndef debugReceive
#define debugReceive false
#endif
2023-09-21 16:04:40 +02:00
// #include <Preferences.h>
2023-09-10 15:33:34 +02:00
#include <SPI.h>
#include <Wire.h>
#include <jmutex.h>
2023-09-17 13:57:28 +02:00
#include <jqueue.h>
2023-09-10 15:33:34 +02:00
2023-09-21 16:04:40 +02:00
#include "fs_helper.h"
2023-09-10 15:33:34 +02:00
//
#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
unsigned long last = 0;
unsigned long delta = 0;
float avg = 10;
#include "system_general/rc_handler.h"
2023-09-24 20:46:10 +02:00
#include "io.h"
2023-09-10 15:33:34 +02:00
//
#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
2023-09-24 15:50:32 +02:00
init_little_fs();
2023-09-21 16:04:40 +02:00
2023-09-10 15:33:34 +02:00
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() {
2023-09-21 16:04:40 +02:00
unsigned long now = micros();
2023-09-10 15:33:34 +02:00
delta = now - last;
last = now;
avg = avg * 0.9 + delta * 0.1;
#if debug
2023-09-17 13:57:28 +02:00
if ((dcounterxy) % 100 == 0)
2023-09-25 17:54:15 +02:00
Serial.println("Sensor Loop, avg = " + String(avg/1000));
2023-09-10 15:33:34 +02:00
#endif
MPULoop();
GNSSLoop();
COMPLoop();
}
2023-09-17 13:57:28 +02:00
void jRadioLoop() {
#if debug
unsigned long now = millis();
static long unsigned last = 0;
static long unsigned delta = 0;
static long unsigned radioLoopCount = 0;
static float avg = 2.;
delta = now - last;
last = now;
avg = avg * 0.9 + delta * 0.1;
if ((radioLoopCount++) % 200 == 0)
Serial.println("Radio Loop, avg = " + String(avg));
#endif
handleRC();
}
2023-09-10 15:33:34 +02:00
#endif