116 lines
No EOL
2.2 KiB
C
116 lines
No EOL
2.2 KiB
C
#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
|
|
|
|
#ifndef debugReceive
|
|
#define debugReceive false
|
|
#endif
|
|
|
|
// #include <Preferences.h>
|
|
#include <SPI.h>
|
|
#include <Wire.h>
|
|
#include <jmutex.h>
|
|
#include <jqueue.h>
|
|
|
|
#include "fs_helper.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
|
|
|
|
unsigned long last = 0;
|
|
unsigned long delta = 0;
|
|
float avg = 10;
|
|
|
|
#include "system_general/rc_handler.h"
|
|
#include "io.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
|
|
init_little_fs();
|
|
|
|
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 = micros();
|
|
delta = now - last;
|
|
last = now;
|
|
avg = avg * 0.9 + delta * 0.1;
|
|
#if debug
|
|
if ((dcounterxy) % 100 == 0)
|
|
Serial.println("Sensor Loop, avg = " + String(avg));
|
|
#endif
|
|
MPULoop();
|
|
GNSSLoop();
|
|
COMPLoop();
|
|
}
|
|
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();
|
|
}
|
|
|
|
#endif |