2018-04-17 11:52:17 +02:00
|
|
|
// ESPNOWSkate Receiver by Lukas Bachschwell this device SLAVE =D
|
2018-04-01 20:06:45 +02:00
|
|
|
#include "Arduino.h"
|
|
|
|
#include <esp_now.h>
|
|
|
|
#include <WiFi.h>
|
2024-05-11 17:16:12 +02:00
|
|
|
// #include <OneWire.h>
|
|
|
|
// #include <DallasTemperature.h>
|
|
|
|
#include "valuehelpers.h"
|
2018-04-22 21:46:19 +02:00
|
|
|
|
|
|
|
#include "mac_config.h"
|
2018-04-01 20:06:45 +02:00
|
|
|
|
2018-04-17 11:52:17 +02:00
|
|
|
#define esc1pin 15
|
|
|
|
#define esc2pin 13
|
2018-04-26 17:10:44 +02:00
|
|
|
#define voltageEnable 12
|
|
|
|
#define voltagePin 36
|
2018-04-22 21:46:19 +02:00
|
|
|
#define ONE_WIRE_BUS 14
|
2024-05-11 17:16:12 +02:00
|
|
|
#define fanRelais 18 // Changed from originally 16 to help hover usart
|
2018-04-17 11:52:17 +02:00
|
|
|
|
2018-04-22 21:46:19 +02:00
|
|
|
#define DELETEBEFOREPAIR 0
|
2018-04-01 20:06:45 +02:00
|
|
|
|
2018-04-26 17:10:44 +02:00
|
|
|
// Resistors in Ohms
|
|
|
|
const float deviderR1 = 1275; // needs to be calibrated carefully using a multimeter because of tolerances of the resistors
|
|
|
|
const float deviderR2 = 22000;
|
|
|
|
const float refVoltage = 3.3;
|
|
|
|
|
2024-05-11 17:16:12 +02:00
|
|
|
#define VARIANT_HOVER 1
|
|
|
|
// #define ENABLE_DISPLAY 1
|
|
|
|
|
|
|
|
#ifdef VARIANT_HOVER
|
|
|
|
#define failsafeValue 0
|
|
|
|
#include "hoverusart.h"
|
|
|
|
#else
|
|
|
|
#define failsafeValue 127
|
|
|
|
#include <Servo.h>
|
2018-04-01 20:06:45 +02:00
|
|
|
Servo esc1;
|
|
|
|
Servo esc2;
|
2024-05-11 17:16:12 +02:00
|
|
|
#endif
|
2018-04-01 20:06:45 +02:00
|
|
|
|
2024-05-11 17:16:12 +02:00
|
|
|
#ifdef ENABLE_DISPLAY
|
|
|
|
#include "SSD1306.h"
|
|
|
|
SSD1306 display(0x3c, 5, 4);
|
|
|
|
#endif
|
2018-04-01 20:06:45 +02:00
|
|
|
|
2024-05-18 15:35:43 +02:00
|
|
|
// OneWire oneWire(ONE_WIRE_BUS);
|
2024-05-11 17:16:12 +02:00
|
|
|
// DallasTemperature sensors(&oneWire); // one instance for all sensrs
|
2018-04-22 21:46:19 +02:00
|
|
|
|
|
|
|
esp_now_peer_info_t remote;
|
|
|
|
|
|
|
|
float temperature = 0;
|
|
|
|
float voltage = 0;
|
2018-05-08 23:23:39 +02:00
|
|
|
float kmh = 0;
|
2018-04-22 21:46:19 +02:00
|
|
|
|
2024-05-18 15:35:43 +02:00
|
|
|
#ifndef VARIANT_HOVER
|
2018-04-22 21:46:19 +02:00
|
|
|
uint8_t sendTemperature = 0;
|
|
|
|
uint8_t sendTemperatureDecimals = 0;
|
|
|
|
uint8_t sendVoltage = 0;
|
2018-04-24 21:31:32 +02:00
|
|
|
uint8_t sendVoltageDecimals = 0;
|
2018-05-08 23:23:39 +02:00
|
|
|
uint8_t sendSpeed = 0;
|
|
|
|
uint8_t sendSpeedDecimals = 0;
|
2024-05-18 15:35:43 +02:00
|
|
|
#endif
|
2018-05-08 23:23:39 +02:00
|
|
|
|
|
|
|
#include "rpm.h"
|
2018-04-22 21:46:19 +02:00
|
|
|
|
2024-05-11 17:16:12 +02:00
|
|
|
// #define pairingMode
|
2018-04-17 11:52:17 +02:00
|
|
|
#define CONNECTION_TIMEOUT 300
|
2018-04-01 20:06:45 +02:00
|
|
|
#define CHANNEL 1
|
|
|
|
long lastPacket = 0;
|
|
|
|
|
|
|
|
bool isConnected = false;
|
2018-06-17 22:40:10 +02:00
|
|
|
uint8_t oldOptions = 0;
|
2018-05-10 15:57:38 +02:00
|
|
|
#define FANS_AUTO 0
|
|
|
|
#define FANS_ON 1
|
|
|
|
#define FANS_OFF 2
|
|
|
|
|
|
|
|
bool lightActive = false;
|
|
|
|
int fanMode = FANS_AUTO;
|
|
|
|
|
|
|
|
#include "lights.h"
|
2024-05-11 17:16:12 +02:00
|
|
|
void setBoardOptions(uint8_t options)
|
|
|
|
{
|
|
|
|
if (options != oldOptions)
|
|
|
|
{
|
2018-06-17 22:40:10 +02:00
|
|
|
oldOptions = options;
|
2018-05-26 22:17:12 +02:00
|
|
|
shouldUpdateLights = true;
|
2024-05-11 17:16:12 +02:00
|
|
|
// Serial.println("true2");
|
2018-05-26 22:17:12 +02:00
|
|
|
}
|
|
|
|
|
2018-06-17 22:09:05 +02:00
|
|
|
lightMode = options & 3;
|
2018-06-17 22:40:10 +02:00
|
|
|
lightActive = (options >> 3) & 1;
|
2018-05-10 15:57:38 +02:00
|
|
|
fanMode = (options >> 2) & 3;
|
2024-05-18 15:35:43 +02:00
|
|
|
#ifdef VARIANT_HOVER
|
|
|
|
ctrl_mode = fanMode;
|
|
|
|
#endif
|
2018-05-10 15:57:38 +02:00
|
|
|
}
|
|
|
|
|
2018-04-01 20:06:45 +02:00
|
|
|
// ESPNOW Functions ############################
|
|
|
|
// config AP
|
2024-05-11 17:16:12 +02:00
|
|
|
void configDeviceAP(bool hidden)
|
|
|
|
{
|
2018-04-01 20:06:45 +02:00
|
|
|
bool result = WiFi.softAP("ESK8", "ESK8_Password+vD8z2YAvoDBW?Zx", CHANNEL, hidden);
|
2024-05-11 17:16:12 +02:00
|
|
|
if (!result)
|
|
|
|
{
|
2018-04-01 20:06:45 +02:00
|
|
|
Serial.println("AP Config failed.");
|
2024-05-11 17:16:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-04-01 20:06:45 +02:00
|
|
|
Serial.println("AP Config Success. Broadcasting with AP: " + String("ESK8"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-11 17:16:12 +02:00
|
|
|
void writeServos(uint16_t firstServo, uint16_t secondServo)
|
|
|
|
{
|
|
|
|
#ifdef VARIANT_HOVER
|
|
|
|
Send(firstServo, secondServo);
|
|
|
|
#else
|
2018-04-01 20:06:45 +02:00
|
|
|
esc1.write(firstServo);
|
|
|
|
esc2.write(secondServo);
|
2024-05-11 17:16:12 +02:00
|
|
|
#endif
|
2018-04-01 20:06:45 +02:00
|
|
|
}
|
|
|
|
|
2018-04-22 21:46:19 +02:00
|
|
|
// callback when data is recv from remote
|
2024-05-11 17:16:12 +02:00
|
|
|
void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len)
|
|
|
|
{
|
2018-04-01 20:06:45 +02:00
|
|
|
char macStr[18];
|
2024-05-11 17:16:12 +02:00
|
|
|
snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
|
|
|
|
Serial.print("Last Packet Recv from: ");
|
|
|
|
Serial.println(macStr);
|
|
|
|
uint8_t recData[5];
|
2018-04-01 20:06:45 +02:00
|
|
|
memcpy(recData, data, data_len);
|
2024-05-11 17:16:12 +02:00
|
|
|
Serial.print("Last Packet Recv Data: ");
|
|
|
|
Serial.println(make16(recData[0], recData[1]));
|
|
|
|
Serial.print(" ");
|
|
|
|
Serial.print(make16(recData[2], recData[3]));
|
|
|
|
Serial.print(" len:");
|
|
|
|
Serial.println(data_len);
|
2018-04-01 20:06:45 +02:00
|
|
|
|
2024-05-11 17:16:12 +02:00
|
|
|
// Answer with response
|
2018-04-24 21:31:32 +02:00
|
|
|
|
2024-05-11 17:16:12 +02:00
|
|
|
const uint8_t respData[] = {sendVoltage, sendVoltageDecimals, sendTemperature, sendTemperatureDecimals, sendSpeed, sendSpeedDecimals};
|
2018-04-22 21:46:19 +02:00
|
|
|
Serial.print("Sending RESPONSE.... ");
|
2018-05-08 23:23:39 +02:00
|
|
|
esp_err_t result = esp_now_send(mac_addr, respData, sizeof(respData));
|
2024-05-11 17:16:12 +02:00
|
|
|
if (result == ESP_OK)
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
Serial.println("Success");
|
2024-05-11 17:16:12 +02:00
|
|
|
}
|
|
|
|
else if (result == ESP_ERR_ESPNOW_NOT_INIT)
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
// How did we get so far!!
|
|
|
|
Serial.println("ESPNOW not Init.");
|
2024-05-11 17:16:12 +02:00
|
|
|
}
|
|
|
|
else if (result == ESP_ERR_ESPNOW_ARG)
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
Serial.println("Invalid Argument");
|
2024-05-11 17:16:12 +02:00
|
|
|
}
|
|
|
|
else if (result == ESP_ERR_ESPNOW_INTERNAL)
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
Serial.println("Internal Error");
|
2024-05-11 17:16:12 +02:00
|
|
|
}
|
|
|
|
else if (result == ESP_ERR_ESPNOW_NO_MEM)
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
Serial.println("ESP_ERR_ESPNOW_NO_MEM");
|
2024-05-11 17:16:12 +02:00
|
|
|
}
|
|
|
|
else if (result == ESP_ERR_ESPNOW_NOT_FOUND)
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
Serial.println("Peer not found.");
|
2024-05-11 17:16:12 +02:00
|
|
|
}
|
|
|
|
else if (result == ESP_ERR_ESPNOW_IF)
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
Serial.println("ESP_ERR_ESPNOW_IF");
|
2024-05-11 17:16:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
Serial.println("Not sure what happened");
|
|
|
|
}
|
|
|
|
|
2018-04-01 20:06:45 +02:00
|
|
|
lastPacket = millis();
|
|
|
|
isConnected = true;
|
2024-05-11 17:16:12 +02:00
|
|
|
// TODO: Could check mac here for some minimal security
|
|
|
|
writeServos(make16(recData[0], recData[1]), make16(recData[2], recData[3]));
|
|
|
|
|
|
|
|
Serial.print("recieved Options: ");
|
|
|
|
setBoardOptions(recData[4]);
|
|
|
|
Serial.println(recData[4], BIN);
|
|
|
|
#ifdef ENABLE_DISPLAY
|
2018-04-01 20:06:45 +02:00
|
|
|
display.clear();
|
|
|
|
char buf[25];
|
2024-05-11 17:16:12 +02:00
|
|
|
sprintf(buf, "1: %i | 2: %i", make16(recData[0], recData[1]), make16(recData[2], recData[3]));
|
2018-04-01 20:06:45 +02:00
|
|
|
display.drawString(2, 0, buf);
|
|
|
|
display.display();
|
2024-05-11 17:16:12 +02:00
|
|
|
#endif
|
2018-04-01 20:06:45 +02:00
|
|
|
}
|
|
|
|
|
2024-05-11 17:16:12 +02:00
|
|
|
void deletePeer()
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
const esp_now_peer_info_t *peer = &remote;
|
|
|
|
const uint8_t *peer_addr = remote.peer_addr;
|
|
|
|
esp_err_t delStatus = esp_now_del_peer(peer_addr);
|
|
|
|
Serial.print("Slave Delete Status: ");
|
2024-05-11 17:16:12 +02:00
|
|
|
if (delStatus == ESP_OK)
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
// Delete success
|
|
|
|
Serial.println("Success");
|
2024-05-11 17:16:12 +02:00
|
|
|
}
|
|
|
|
else if (delStatus == ESP_ERR_ESPNOW_NOT_INIT)
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
// How did we get so far!!
|
|
|
|
Serial.println("ESPNOW Not Init");
|
2024-05-11 17:16:12 +02:00
|
|
|
}
|
|
|
|
else if (delStatus == ESP_ERR_ESPNOW_ARG)
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
Serial.println("Invalid Argument");
|
2024-05-11 17:16:12 +02:00
|
|
|
}
|
|
|
|
else if (delStatus == ESP_ERR_ESPNOW_NOT_FOUND)
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
Serial.println("Peer not found.");
|
2024-05-11 17:16:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
Serial.println("Not sure what happened");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-11 17:16:12 +02:00
|
|
|
bool manageRemote()
|
|
|
|
{
|
|
|
|
if (remote.channel == CHANNEL)
|
|
|
|
{
|
|
|
|
if (DELETEBEFOREPAIR)
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
deletePeer();
|
|
|
|
}
|
|
|
|
|
|
|
|
Serial.print("Remote Status: ");
|
|
|
|
const esp_now_peer_info_t *peer = &remote;
|
|
|
|
const uint8_t *peer_addr = remote.peer_addr;
|
|
|
|
// check if the peer exists
|
|
|
|
bool exists = esp_now_is_peer_exist(peer_addr);
|
2024-05-11 17:16:12 +02:00
|
|
|
if (exists)
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
// Slave already paired.
|
|
|
|
Serial.println("Already Paired");
|
|
|
|
return true;
|
2024-05-11 17:16:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
// Slave not paired, attempt pair
|
|
|
|
esp_err_t addStatus = esp_now_add_peer(peer);
|
2024-05-11 17:16:12 +02:00
|
|
|
if (addStatus == ESP_OK)
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
// Pair success
|
|
|
|
Serial.println("Pair success");
|
|
|
|
return true;
|
2024-05-11 17:16:12 +02:00
|
|
|
}
|
|
|
|
else if (addStatus == ESP_ERR_ESPNOW_NOT_INIT)
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
// How did we get so far!!
|
|
|
|
Serial.println("ESPNOW Not Init");
|
|
|
|
return false;
|
2024-05-11 17:16:12 +02:00
|
|
|
}
|
|
|
|
else if (addStatus == ESP_ERR_ESPNOW_ARG)
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
Serial.println("Invalid Argument");
|
|
|
|
return false;
|
2024-05-11 17:16:12 +02:00
|
|
|
}
|
|
|
|
else if (addStatus == ESP_ERR_ESPNOW_FULL)
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
Serial.println("Peer list full");
|
|
|
|
return false;
|
2024-05-11 17:16:12 +02:00
|
|
|
}
|
|
|
|
else if (addStatus == ESP_ERR_ESPNOW_NO_MEM)
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
Serial.println("Out of memory");
|
|
|
|
return false;
|
2024-05-11 17:16:12 +02:00
|
|
|
}
|
|
|
|
else if (addStatus == ESP_ERR_ESPNOW_EXIST)
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
Serial.println("Peer Exists");
|
|
|
|
return true;
|
2024-05-11 17:16:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
Serial.println("Not sure what happened");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2024-05-11 17:16:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-04-22 21:46:19 +02:00
|
|
|
// No slave found to process
|
|
|
|
Serial.println("No Slave found to process");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-01 20:06:45 +02:00
|
|
|
// end ESPNOW functions
|
|
|
|
|
2024-05-18 15:35:43 +02:00
|
|
|
#ifndef VARIANT_HOVER
|
2024-05-11 17:16:12 +02:00
|
|
|
void checkTemperature()
|
|
|
|
{
|
|
|
|
// sensors.requestTemperatures(); // Send the command to get temperatures
|
|
|
|
// temperature = sensors.getTempCByIndex(0);
|
|
|
|
// Serial.print("Temp: ");
|
|
|
|
// Serial.println(temperature);
|
|
|
|
switch (fanMode)
|
|
|
|
{
|
2018-05-10 15:57:38 +02:00
|
|
|
case FANS_AUTO:
|
2024-05-11 17:16:12 +02:00
|
|
|
if (temperature < 35)
|
|
|
|
digitalWrite(fanRelais, LOW);
|
|
|
|
if (temperature > 40)
|
|
|
|
digitalWrite(fanRelais, HIGH);
|
2018-05-10 15:57:38 +02:00
|
|
|
break;
|
|
|
|
case FANS_ON:
|
|
|
|
digitalWrite(fanRelais, HIGH);
|
|
|
|
break;
|
|
|
|
case FANS_OFF:
|
|
|
|
digitalWrite(fanRelais, LOW);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-04-24 21:31:32 +02:00
|
|
|
sendTemperature = abs(floor(temperature));
|
|
|
|
sendTemperatureDecimals = (temperature - sendTemperature) * 100;
|
2018-04-22 21:46:19 +02:00
|
|
|
}
|
|
|
|
|
2024-05-11 17:16:12 +02:00
|
|
|
void checkVoltage()
|
|
|
|
{
|
2018-04-26 17:10:44 +02:00
|
|
|
digitalWrite(voltageEnable, HIGH);
|
2024-05-11 17:16:12 +02:00
|
|
|
// Serial.print("Voltage: ");
|
2018-04-26 17:10:44 +02:00
|
|
|
int value = analogRead(voltagePin);
|
2024-05-11 17:16:12 +02:00
|
|
|
// Serial.println(value);
|
2018-04-26 17:10:44 +02:00
|
|
|
|
|
|
|
float batteryVoltage = 0.0;
|
|
|
|
int total = 0;
|
|
|
|
|
2024-05-11 17:16:12 +02:00
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
{
|
2018-04-26 17:10:44 +02:00
|
|
|
total += analogRead(voltagePin);
|
|
|
|
}
|
|
|
|
|
|
|
|
batteryVoltage = (refVoltage / 4095.0) * ((float)total / 10.0);
|
|
|
|
// Now we have the actual Voltage, lets calculate the value befor the devider
|
2024-05-11 17:16:12 +02:00
|
|
|
batteryVoltage = batteryVoltage / (deviderR1 / (deviderR1 + deviderR2));
|
2018-04-26 17:10:44 +02:00
|
|
|
|
|
|
|
sendVoltage = abs(floor(batteryVoltage));
|
|
|
|
sendVoltageDecimals = (batteryVoltage - sendVoltage) * 100;
|
2024-05-11 17:16:12 +02:00
|
|
|
// Serial.print("Voltage: ");
|
|
|
|
// Serial.println(batteryVoltage);
|
|
|
|
digitalWrite(voltageEnable, LOW); // change to low
|
2018-04-26 17:10:44 +02:00
|
|
|
}
|
2024-05-18 15:35:43 +02:00
|
|
|
#endif
|
2018-04-26 17:10:44 +02:00
|
|
|
|
2024-05-11 17:16:12 +02:00
|
|
|
void setup()
|
|
|
|
{
|
2018-04-01 20:06:45 +02:00
|
|
|
Serial.begin(115200);
|
2018-04-17 11:52:17 +02:00
|
|
|
Serial.println("ESPNowSkate Receiver");
|
2018-04-01 20:06:45 +02:00
|
|
|
|
2024-05-11 17:16:12 +02:00
|
|
|
#ifdef ENABLE_DISPLAY
|
2018-04-01 20:06:45 +02:00
|
|
|
display.init();
|
|
|
|
display.flipScreenVertically();
|
|
|
|
display.setFont(ArialMT_Plain_16);
|
2024-05-11 17:16:12 +02:00
|
|
|
#endif
|
2018-04-01 20:06:45 +02:00
|
|
|
|
2018-04-26 17:10:44 +02:00
|
|
|
pinMode(voltageEnable, OUTPUT);
|
2018-04-28 13:37:51 +02:00
|
|
|
pinMode(fanRelais, OUTPUT);
|
2018-04-26 17:10:44 +02:00
|
|
|
|
2024-05-11 17:16:12 +02:00
|
|
|
#ifdef VARIANT_HOVER
|
|
|
|
initHoverSerial();
|
|
|
|
#else
|
2018-04-17 11:52:17 +02:00
|
|
|
// Init escs, min and max value similar as Traxxas TQI 1100, 1900
|
|
|
|
// chanel, minAngel, maxAngel, minPulseWidth, maxPulseWidth
|
2018-04-17 21:57:25 +02:00
|
|
|
esc1.attach(esc1pin, 0, 0, 255, 1100, 1900);
|
|
|
|
esc2.attach(esc2pin, 1, 0, 255, 1100, 1900);
|
2018-04-22 21:46:19 +02:00
|
|
|
sensors.begin();
|
2024-05-11 17:16:12 +02:00
|
|
|
initRPMPins();
|
|
|
|
#endif
|
2018-04-22 21:46:19 +02:00
|
|
|
|
2024-05-11 17:16:12 +02:00
|
|
|
// setupLights();
|
|
|
|
// lightOff();
|
2018-05-26 22:17:12 +02:00
|
|
|
|
2024-05-11 17:16:12 +02:00
|
|
|
// xTaskCreatePinnedToCore(
|
|
|
|
// measureRpm,
|
|
|
|
// "rpm task",
|
|
|
|
// 1000,
|
|
|
|
// NULL,
|
|
|
|
// 1,
|
|
|
|
// &rpmTaskHandle,
|
|
|
|
// 0);
|
2018-05-08 23:23:39 +02:00
|
|
|
|
2024-05-11 17:16:12 +02:00
|
|
|
// Set device in AP mode to begin with
|
|
|
|
Serial.println("INIT Wifi");
|
2018-04-22 21:46:19 +02:00
|
|
|
|
2018-04-01 20:06:45 +02:00
|
|
|
WiFi.mode(WIFI_AP);
|
2024-05-11 17:16:12 +02:00
|
|
|
Serial.println("INIT Pair");
|
|
|
|
// configure device AP mode
|
|
|
|
#ifdef pairingMode
|
2018-04-01 20:06:45 +02:00
|
|
|
configDeviceAP(false);
|
2024-05-11 17:16:12 +02:00
|
|
|
#else
|
2018-04-01 20:06:45 +02:00
|
|
|
configDeviceAP(true);
|
2024-05-11 17:16:12 +02:00
|
|
|
#endif
|
2018-04-01 20:06:45 +02:00
|
|
|
|
2024-05-11 17:16:12 +02:00
|
|
|
Serial.print("AP MAC: ");
|
|
|
|
Serial.println(WiFi.softAPmacAddress());
|
2018-04-01 20:06:45 +02:00
|
|
|
|
|
|
|
// Init ESPNow
|
2024-05-11 17:16:12 +02:00
|
|
|
if (esp_now_init() == ESP_OK)
|
|
|
|
{
|
2018-04-01 20:06:45 +02:00
|
|
|
Serial.println("ESPNow Init Success");
|
|
|
|
}
|
2024-05-11 17:16:12 +02:00
|
|
|
else
|
|
|
|
{
|
2018-04-01 20:06:45 +02:00
|
|
|
Serial.println("ESPNow Init Failed");
|
|
|
|
ESP.restart();
|
|
|
|
}
|
2018-04-22 21:46:19 +02:00
|
|
|
|
2018-04-01 20:06:45 +02:00
|
|
|
// Once ESPNow is successfully Init, we will register for recv CB to
|
|
|
|
// get recv packer info.
|
|
|
|
esp_now_register_recv_cb(OnDataRecv);
|
2018-04-22 21:46:19 +02:00
|
|
|
|
2024-05-11 17:16:12 +02:00
|
|
|
for (int i = 0; i < 6; ++i)
|
|
|
|
{
|
|
|
|
remote.peer_addr[i] = (uint8_t)mac_remote[i];
|
2018-04-22 21:46:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
remote.channel = CHANNEL; // pick a channel
|
2024-05-11 17:16:12 +02:00
|
|
|
remote.encrypt = 0; // no encryption
|
|
|
|
remote.ifidx = WIFI_IF_AP;
|
2018-04-22 21:46:19 +02:00
|
|
|
manageRemote();
|
2018-04-01 20:06:45 +02:00
|
|
|
}
|
|
|
|
|
2024-05-11 17:16:12 +02:00
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
if (millis() - lastPacket > CONNECTION_TIMEOUT)
|
|
|
|
{
|
|
|
|
Serial.println("Con timeout!!");
|
2018-04-17 11:52:17 +02:00
|
|
|
isConnected = false;
|
2024-05-11 17:16:12 +02:00
|
|
|
// int failsafeValue = map(analogRead(fallbackpin), 0, 4095, 0, 180);
|
|
|
|
// Taking 127 because it should be the center value anyway
|
2018-04-17 11:52:17 +02:00
|
|
|
writeServos(failsafeValue, failsafeValue);
|
2024-05-11 17:16:12 +02:00
|
|
|
#ifdef ENABLE_DISPLAY
|
2018-04-17 11:52:17 +02:00
|
|
|
display.clear();
|
|
|
|
char buf[25];
|
|
|
|
sprintf(buf, "FAIL: %i", failsafeValue);
|
|
|
|
display.drawString(2, 0, buf);
|
|
|
|
display.display();
|
2024-05-11 17:16:12 +02:00
|
|
|
#endif
|
2018-04-01 20:06:45 +02:00
|
|
|
}
|
2018-04-22 21:46:19 +02:00
|
|
|
|
2024-05-11 17:16:12 +02:00
|
|
|
// checkTemperature();
|
|
|
|
// checkVoltage();
|
|
|
|
#ifdef VARIANT_HOVER
|
|
|
|
Receive();
|
|
|
|
#endif
|
|
|
|
// if (shouldUpdateLights)
|
|
|
|
// updateLights();
|
2018-04-01 20:06:45 +02:00
|
|
|
}
|