Adding RPM and speed calc, changing receiver mac

This commit is contained in:
2018-05-08 23:23:39 +02:00
parent a13936c35e
commit a17572fa1a
5 changed files with 116 additions and 17 deletions

View File

@ -36,14 +36,16 @@ esp_now_peer_info_t remote;
float temperature = 0;
float voltage = 0;
float speed = 0;
float kmh = 0;
uint8_t sendTemperature = 0;
uint8_t sendTemperatureDecimals = 0;
uint8_t sendVoltage = 0;
uint8_t sendVoltageDecimals = 0;
uint8_t sendRPMupper = 1;
uint8_t sendRPMlower = 2;
uint8_t sendSpeed = 0;
uint8_t sendSpeedDecimals = 0;
#include "rpm.h"
//#define pairingMode
#define CONNECTION_TIMEOUT 300
@ -80,9 +82,9 @@ void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len) {
// Answer with response
const uint8_t respData[] = { sendVoltage, sendVoltageDecimals, sendTemperature, sendTemperatureDecimals, sendRPMupper, sendRPMlower };
const uint8_t respData[] = { sendVoltage, sendVoltageDecimals, sendTemperature, sendTemperatureDecimals, sendSpeed, sendSpeedDecimals };
Serial.print("Sending RESPONSE.... ");
esp_err_t result = esp_now_send(mac_addr, respData, sizeof(data));
esp_err_t result = esp_now_send(mac_addr, respData, sizeof(respData));
if (result == ESP_OK) {
Serial.println("Success");
} else if (result == ESP_ERR_ESPNOW_NOT_INIT) {
@ -192,8 +194,8 @@ bool manageRemote() {
void checkTemperature() {
sensors.requestTemperatures(); // Send the command to get temperatures
temperature = sensors.getTempCByIndex(0);
Serial.print("Temp: ");
Serial.println(temperature);
//Serial.print("Temp: ");
//Serial.println(temperature);
if(temperature < 35) digitalWrite(fanRelais, LOW);
if(temperature > 40) digitalWrite(fanRelais, HIGH);
sendTemperature = abs(floor(temperature));
@ -202,9 +204,9 @@ void checkTemperature() {
void checkVoltage() {
digitalWrite(voltageEnable, HIGH);
Serial.print("Voltage: ");
//Serial.print("Voltage: ");
int value = analogRead(voltagePin);
Serial.println(value);
//Serial.println(value);
float batteryVoltage = 0.0;
@ -220,8 +222,8 @@ void checkVoltage() {
sendVoltage = abs(floor(batteryVoltage));
sendVoltageDecimals = (batteryVoltage - sendVoltage) * 100;
Serial.print("Voltage: ");
Serial.println(batteryVoltage);
//Serial.print("Voltage: ");
//Serial.println(batteryVoltage);
digitalWrite(voltageEnable, LOW); // change to low
}
@ -237,6 +239,8 @@ void setup() {
pinMode(voltageEnable, OUTPUT);
pinMode(fanRelais, OUTPUT);
initRPMPins();
// Init escs, min and max value similar as Traxxas TQI 1100, 1900
// chanel, minAngel, maxAngel, minPulseWidth, maxPulseWidth
esc1.attach(esc1pin, 0, 0, 255, 1100, 1900);
@ -244,6 +248,15 @@ void setup() {
sensors.begin();
xTaskCreatePinnedToCore(
measureRpm,
"rpm task",
1000,
NULL,
1,
&rpmTaskHandle,
0);
//Set device in AP mode to begin with
WiFi.mode(WIFI_AP);