Progress commit

This commit is contained in:
Jared Dunbar 2023-04-06 17:33:00 -04:00
parent 60432ca9ed
commit 0ee958e5c4
6 changed files with 66 additions and 54 deletions

View File

@ -9,23 +9,15 @@
; https://docs.platformio.org/page/projectconf.html ; https://docs.platformio.org/page/projectconf.html
[platformio] [platformio]
default_envs = esp12e default_envs = leonardo
name = RemoteTrainControl name = RemoteTrainControl
[env:esp12e] [env:leonardo]
platform = espressif8266 platform = atmelavr
framework = arduino framework = arduino
board = esp12e board = leonardo
lib_deps =
adafruit/Adafruit ADS1X15@^2.4.0
SPI
adafruit/Adafruit SSD1306@^2.5.7
[env:nodemcuv2]
platform = espressif8266
framework = arduino
board = nodemcuv2
lib_deps = lib_deps =
adafruit/Adafruit ADS1X15@^2.4.0 adafruit/Adafruit ADS1X15@^2.4.0
SPI SPI
adafruit/Adafruit SSD1306@^2.5.7 adafruit/Adafruit SSD1306@^2.5.7
jgromes/RadioLib@^5.7.0

View File

@ -10,12 +10,11 @@ void controlsInit() {
ads1115.setGain(GAIN_ONE); ads1115.setGain(GAIN_ONE);
} }
float map(float x, float in_min, float in_max, float out_min, float out_max) float map(float x, float in_min, float in_max, float out_min, float out_max) {
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
} }
void getControlsState(float &throttle, int &direction, bool &horn, bool &bell, bool &lights) { void getControlsState(float &throttle, int8_t &direction, bool &horn, bool &bell, bool &lights) {
float throttle_volts = ads1115.computeVolts(ads1115.readADC_SingleEnded(0)); float throttle_volts = ads1115.computeVolts(ads1115.readADC_SingleEnded(0));
float direction_volts = ads1115.computeVolts(ads1115.readADC_SingleEnded(1)); float direction_volts = ads1115.computeVolts(ads1115.readADC_SingleEnded(1));

View File

@ -3,6 +3,6 @@
void controlsInit(); void controlsInit();
float map(float x, float in_min, float in_max, float out_min, float out_max); float map(float x, float in_min, float in_max, float out_min, float out_max);
void getControlsState(float &throttle, int &direction, bool &horn, bool &bell, bool &lights); void getControlsState(float &throttle, int8_t &direction, bool &horn, bool &bell, bool &lights);
#endif #endif

View File

@ -1,29 +1,69 @@
#include "Arduino.h" #include "Arduino.h"
#include "screen.h" #include "screen.h"
#include "wifi.h"
#include "controls.h" #include "controls.h"
#include <ESP8266WiFi.h> #include <RadioLib.h>
#include <ESP8266WebServer.h> #include "string.h"
#include <string>
using namespace std; using namespace std;
// RF69 has the following connections:
// CS pin: 10
// DIO0 pin: 2
// RESET pin: 3
RF69 radio = new Module(10, 2, 3);
void radioInit() {
Serial.print(F("[RF69] Initializing ... "));
int state = radio.begin(918.5, 300.0, 60.0, 250.0, 10, 32);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
}
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
displayInit(); displayInit();
controlsInit(); controlsInit();
WiFi.softAP(WIFI_SSID, WIFI_PASS); radioInit();
displayWiFiInformation(WIFI_SSID, WIFI_PASS);
} }
float throttle = 0.0f; float throttle = 0.0f;
uint8_t direction = 0; int8_t direction = 0;
bool horn = false; bool horn = false;
bool bell = false; bool bell = false;
bool lights = false; bool lights = false;
void sendStringToRadio(String str) {
int state = radio.transmit("Hello World!");
if (state == RADIOLIB_ERR_NONE) {
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 64 bytes
Serial.println(F("too long!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
}
}
void serializeThrottleDirection(float throttle, int8_t direction, String &str) {
str += String(throttle);
str += ",";
str += String(direction);
}
void sendControlOutputs(float throttle, int8_t direction, bool horn, bool bell, bool lights) {
String str;
serializeThrottleDirection(throttle, direction, str);
Serial.println(str);
sendStringToRadio(str);
}
void loop() { void loop() {
getControlsState(throttle, direction, horn, bell, lights); getControlsState(throttle, direction, horn, bell, lights);
displayControlStatus(throttle, direction, horn, bell, lights); displayControlStatus(throttle, direction, horn, bell, lights);
//sendControlOutputs(throttle, direction, horn, bell, lights); sendControlOutputs(throttle, direction, horn, bell, lights);
delay(1); delay(100);
} }

View File

@ -3,7 +3,7 @@
#include <Wire.h> #include <Wire.h>
#include <Adafruit_GFX.h> #include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h> #include <Adafruit_SSD1306.h>
#include <string> #include "string.h"
using namespace std; using namespace std;
#define SCREEN_WIDTH 128 #define SCREEN_WIDTH 128
@ -21,7 +21,7 @@ void displayInit() {
} }
} }
void displayString(string inputString) { void displayString(String inputString) {
if (!displayEnabled) { if (!displayEnabled) {
return; return;
} }
@ -30,25 +30,7 @@ void displayString(string inputString) {
} }
} }
void displayWiFiInformation(string wifiSSID, string wifiPassword) { void displayDirection(int8_t &direction) {
if (!displayEnabled) {
return;
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
displayString("WiFi Information:");
display.setCursor(0,8);
displayString("SSID: ");
displayString(wifiSSID);
display.setCursor(0,16);
displayString("Pass: ");
displayString(wifiPassword);
display.display();
}
void displayDirection(int &direction) {
if (direction == 0) { if (direction == 0) {
displayString("N"); displayString("N");
} else if (direction == 1) { } else if (direction == 1) {
@ -68,7 +50,7 @@ void displayBool(bool &state) {
} }
} }
void displayControlStatus(float &throttle, int &direction, bool &horn, bool &bell, bool &lights) { void displayControlStatus(float &throttle, int8_t &direction, bool &horn, bool &bell, bool &lights) {
if (!displayEnabled) { if (!displayEnabled) {
return; return;
} }

View File

@ -1,14 +1,13 @@
#ifndef SCREEN_H #ifndef SCREEN_H
#define SCREEN_H #define SCREEN_H
#include <string> #include "string.h"
using namespace std; using namespace std;
void displayInit(); void displayInit();
void displayString(string inputString); void displayString(String inputString);
void displayWiFiInformation(string wifiSSID, string wifiPassword); void displayDirection(int8_t &direction);
void displayDirection(int &direction);
void displayBool(bool &state); void displayBool(bool &state);
void displayControlStatus(float &throttle, int &direction, bool &horn, bool &bell, bool &lights); void displayControlStatus(float &throttle, int8_t &direction, bool &horn, bool &bell, bool &lights);
#endif #endif