migration repo
All checks were successful
/ Build (push) Successful in 3m37s
/ Release (push) Successful in 8s

This commit is contained in:
FCS
2025-12-01 17:55:44 +01:00
commit ed83354dfb
13 changed files with 719 additions and 0 deletions

182
src/main.cpp Normal file
View File

@@ -0,0 +1,182 @@
#include "../lib/windentelemetry.h"
#include <Arduino.h>
#include <U8g2lib.h>
#include <RadioLib.h>
#ifdef DEVICE_WINDE
#include <tacho.h>
#endif
#ifdef DEVICE_SAILPLANE
#include <airspeed.h>
#endif
SX1262 radio = new Module(LORA_NSS, LORA_DIO1, LORA_NRST, LORA_BUSY);
#ifdef DEVICE_WINDE
volatile bool receivedFlag = false;
// this function is called when a complete packet
// is received by the module
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFlag(void)
{
// we got a packet, set the flag
receivedFlag = true;
}
#endif
#ifdef HELTEC_WIFI_LORA_32_V3
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, OLED_RST, OLED_CLK, OLED_DATA);
#endif
void setup()
{
/* Serial to display data */
Serial.begin(115200);
Serial.println("start");
int state = radio.begin(LORA_FREQ);
if (state == RADIOLIB_ERR_NONE)
{
Serial.println(F("success!"));
}
else
{
Serial.print(F("failed, code "));
Serial.println(state);
while (true)
{
delay(10);
}
}
u8g2.begin();
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_ncenB14_tr);
#ifdef DEVICE_SAILPLANE
u8g2.drawStr(0, 20, "Start Plane");
init_2ndi2c();
init_airspeed_sensor();
init_pressure_sensor();
#endif
#ifdef DEVICE_WINDE
u8g2.drawStr(0, 20, "Start Winde");
init_servo();
init_pixel();
radio.setPacketReceivedAction(setFlag);
// start listening for LoRa packets
state = radio.startReceive();
if (state == RADIOLIB_ERR_NONE)
{
Serial.println(F("success!"));
}
else
{
Serial.print(F("failed, code "));
Serial.println(state);
while (true)
{
delay(10);
}
}
#endif
u8g2.sendBuffer();
}
void loop()
{
#ifdef DEVICE_SAILPLANE
/* Read the sensor */
get_pressure();
int vel_kmh = get_airspeed_kmh();
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_logisoso42_tr);
u8g2.setCursor(0, 60);
u8g2.print(vel_kmh);
u8g2.sendBuffer();
if (vel_kmh > 30)
{
String data = String(vel_kmh);
int state = radio.transmit(data);
if (state == RADIOLIB_ERR_NONE)
{
// the packet was successfully transmitted
Serial.println(F("success!"));
// print measured data rate
Serial.print(F("[SX1262] Datarate:\t"));
Serial.print(radio.getDataRate());
Serial.println(F(" bps"));
}
else if (state == RADIOLIB_ERR_PACKET_TOO_LONG)
{
// the supplied packet was longer than 256 bytes
Serial.println(F("too long!"));
}
else if (state == RADIOLIB_ERR_TX_TIMEOUT)
{
// timeout occured while transmitting packet
Serial.println(F("timeout!"));
}
else
{
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
#ifdef DEBUG
/* Display the data */
Serial.print("IAS (km/h): ");
Serial.println(vel_kmh);
Serial.print(pres.pres_pa(), 6);
Serial.print("IAS (m/s): ");
Serial.println(ias);
Serial.println(vel_kmh);
Serial.print("\t");
Serial.print(pres.die_temp_c(), 6);
Serial.print("\n");
#endif
delay(1000);
}
#endif
#ifdef DEVICE_WINDE
if (receivedFlag)
{
// reset flag
receivedFlag = false;
// you can read received data as an Arduino String
String str;
int state = radio.readData(str);
// you can also read received data as byte array
/*
byte byteArr[8];
int numBytes = radio.getPacketLength();
int state = radio.readData(byteArr, numBytes);
*/
if (state == RADIOLIB_ERR_NONE)
{
// packet was successfully received
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_logisoso42_tr);
u8g2.setCursor(0, 60);
u8g2.print(str);
u8g2.sendBuffer();
Serial.println(str);
int speed = str.toInt();
set_tacho(speed, 70, 150);
}
}
#endif
}