Skip to content

Commit

Permalink
Upgraded to Esp8266 version 2.2.0-RC1, minor bug fixes. Update to wor…
Browse files Browse the repository at this point in the history
…k with faraday-motion/vesc version 1.1
  • Loading branch information
Sune Pedersen committed Nov 7, 2016
1 parent 7dbd76b commit 87a13ad
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 158 deletions.
34 changes: 0 additions & 34 deletions Faraday.NODEMCU/Faraday.Discbrakes.ino

This file was deleted.

136 changes: 78 additions & 58 deletions Faraday.NODEMCU/Faraday.LED.ino
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
#if defined(ENABLELED)

byte lastMotorDirection = -1;

void setupLeds()
{
leds.init(LEDSTOTAL);
lastMotorDirection = motorDirection;
leds.Begin();
showLedLights();
}

void updateLeds()
{
if (leds.CanShow())
leds.Show();
}

void showLedState()
Expand All @@ -22,13 +32,20 @@ void showLedLights()
//Front lights
for (int i = LEDSFRONTINDEX; i < LEDSFRONTINDEX + LEDSFRONTCOUNT; i++) {
setPixelColor(i, 100, 100, 100);
yield();
}
for (int i = LEDSBACKINDEX; i < LEDSBACKINDEX + LEDSBACKCOUNT; i++) {
//If braking, put brake lights
if (motorDirection == 2)
setPixelColor(i, 255, 0, 0);
else
setPixelColor(i, 100, 0, 0);
if (lastMotorDirection != motorDirection)
{
for (int i = LEDSBACKINDEX; i < LEDSBACKINDEX + LEDSBACKCOUNT; i++) {
//If braking, put brake lights
if (motorDirection == 2)
setPixelColor(i, 255, 0, 0);
else
setPixelColor(i, 100, 0, 0);
yield();
}
updateLeds();
lastMotorDirection = motorDirection;
}
}

Expand Down Expand Up @@ -80,64 +97,67 @@ void setLedControls()
}
}
}
byte readyColorCounter = 0;
byte readyColor = 1;
byte readyColorStep = 3;
const byte readyColorMin = 0;
const byte readyColorMax = 90;
byte readyColorCounter = 0;
byte readyColor = 1;
byte readyColorStep = 3;
const byte readyColorMin = 0;
const byte readyColorMax = 90;

void ledReadyState()
{
for (int i = LEDSCONTROLINDEX; i < LEDSCONTROLCOUNT; i++) {
pixels[i] = Wheel(readyColorCounter);
}
if (readyColorCounter <= readyColorMin)
readyColor = +readyColorStep;
else if (readyColorCounter >= readyColorMax)
readyColor = -readyColorStep;
readyColorCounter += readyColor;
void ledReadyState()
{
for (int i = LEDSCONTROLINDEX; i < LEDSCONTROLCOUNT; i++) {
leds.SetPixelColor(i, Wheel(readyColorCounter));
yield();
}
if (readyColorCounter <= readyColorMin)
readyColor = +readyColorStep;
else if (readyColorCounter >= readyColorMax)
readyColor = -readyColorStep;
readyColorCounter += readyColor;
}

void ledDeadState()
void ledDeadState()
{
uint8_t i;
static uint8_t c = 0;
static uint8_t d = 5;
for (i = LEDSCONTROLINDEX; i < LEDSCONTROLCOUNT; i++)
{
uint8_t i;
static uint8_t c = 0;
static uint8_t d = 5;
for (i = LEDSCONTROLINDEX; i < LEDSCONTROLCOUNT; i++)
setPixelColor(i, c, 0, 0);
c += d;
if ( (c >= 255) || (c <= 0) ) d = -d;
setPixelColor(i, c, 0, 0);
yield();
}
c += d;
if ( (c >= 255) || (c <= 0) ) d = -d;
}

void setPixelColor(byte index, byte r, byte g, byte b)
{
pixels[index].R = r;
pixels[index].G = g;
pixels[index].B = b;
}
void setPixelColor(byte index, byte r, byte g, byte b)
{
RgbColor pixel(r, g, b);
leds.SetPixelColor(index, pixel);
}

Pixel_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
Pixel_t p;
if (WheelPos < 85) {
p.R = 255 - WheelPos * 3;
p.G = 0;
p.B = WheelPos * 3;
return p;
} else if (WheelPos < 170) {
WheelPos -= 85;
p.R = 0;
p.G = WheelPos * 3;
p.B = 255 - WheelPos * 3;
return p;
} else {
WheelPos -= 170;
p.R = WheelPos * 3;
p.G = 255 - WheelPos * 3;
p.B = 0;
return p;
}
}

RgbColor Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
RgbColor p;
if (WheelPos < 85) {
p.R = 255 - WheelPos * 3;
p.G = 0;
p.B = WheelPos * 3;
return p;
} else if (WheelPos < 170) {
WheelPos -= 85;
p.R = 0;
p.G = WheelPos * 3;
p.B = 255 - WheelPos * 3;
return p;
} else {
WheelPos -= 170;
p.R = WheelPos * 3;
p.G = 255 - WheelPos * 3;
p.B = 0;
return p;
}
}
#endif

70 changes: 37 additions & 33 deletions Faraday.NODEMCU/Faraday.NODEMCU.ino
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//Requires
//http://arduino.esp8266.com/stable/package_esp8266com_index.json
//VERSION: 2.1.0
//Requires
//http://arduino.esp8266.com/staging/package_esp8266com_index.json
//VERSION: 2.2.0-RC1
//ArduinoNunchuk
//Metro
//WS2812
//NeoPixelBus
//Faraday.Vesc

//Optional defines
Expand All @@ -14,21 +14,24 @@
#define ENABLEWIFI //Enable wifi AP
#define ENABLENUNCHUK //Enable control through a nunchuk
//#define ENABLELED //Enable led control - NOT WORKING RELIABLE
//#define ENABLEDEADSWITCH //Enable dead man switch
//#define ENABLEDEADSWITCH //Enable dead man switch
//#define ENABLEOTAUPDATE //OTA - Not working
//#define ENABLEDISCBRAKE //Disc brakes - not working
#define ENABLESMOOTHING //Enable smothing of input values
#define ENABLENONLINEARBRAKE // Non linear braking, softer braking in the beginning

#define FARADAY_VERSION "NODEMCU20160505-2.2.0-RC1"

//How many clients should be able to connect to this ESP8266
#define MAX_SRV_CLIENTS 1
#define MAX_SRV_CLIENTS 5

//Pins
#define PINEXTERNALRESET 16
#define PINDEADSWITCH 12
#define PINSERVOESC 0
#define PINSERVOBRAKE1 2
#define PINSERVOBRAKE2 14
#define PINPIXEL 3

//Required includes
#include <Arduino.h>
Expand All @@ -38,7 +41,8 @@
#include <IPAddress.h>
#include <Servo.h>
#include <Metro.h>
#include <ws2812_i2s.h>
#include <NeoPixelBus.h>
//#include <ws2812_i2s.h>
#include <ArduinoJson.h>
#include "FS.h"

Expand Down Expand Up @@ -81,16 +85,15 @@ Servo servoESC;
#endif

#if defined(ENABLELED)
#define LEDSTOTAL 14
#define LEDSCONTROLCOUNT 12
#define LEDSFRONTCOUNT 1
#define LEDSBACKCOUNT 1
#define LEDSTOTAL 24
#define LEDSCONTROLCOUNT 0
#define LEDSFRONTCOUNT 0
#define LEDSBACKCOUNT 24
#define LEDSCONTROLINDEX 0
#define LEDSFRONTINDEX 12
#define LEDSBACKINDEX 13
#define LEDSFRONTINDEX 0
#define LEDSBACKINDEX 0

static WS2812 leds;
static Pixel_t pixels[LEDSTOTAL];
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> leds(LEDSTOTAL, PINPIXEL);
#endif

#if defined(ENABLEWEBUPDATE)
Expand Down Expand Up @@ -179,9 +182,9 @@ void setupSERVO()
void setup()
{
Serial.begin(115200);
delay(1000);
delay(250);
loadConfiguration();

#if defined(ENABLEWIFI)
setupWIFI();
#endif
Expand All @@ -193,10 +196,9 @@ void setup()
#endif
pinMode(PINEXTERNALRESET, OUTPUT);
digitalWrite(PINEXTERNALRESET, LOW);
delay(250);

Serial.print("Faraday Motion FirmwareVersion:");
Serial.println(faradayVersion);
Serial.print(F("Faraday Motion FirmwareVersion:"));
Serial.println(FARADAY_VERSION);

#if defined(ENABLEOTAUPDATE)
setupOTA();
Expand Down Expand Up @@ -255,14 +257,14 @@ void loop()
#endif

yield();
if (metroControllerRead.check() == 1) {
if (metroControllerRead.check() == 1) {
#if defined(ENABLEWIFI)
readFromWifiClient();
readFromWifiClient();
#endif
#if defined(ENABLENUNCHUK)
readFromNunchukClient();
readFromNunchukClient();
#endif
delay(1);
yield();

#if defined(ENABLEDEADSWITCH)
if (digitalRead(PINDEADSWITCH) == HIGH)
Expand Down Expand Up @@ -302,14 +304,16 @@ void loop()
#if defined(ENABLELED)
if (metroLeds.check() == 1)
{
setLedControls();
yield();
}
if (metroLedsReadyState.check() == 1)
{
showLedState();
yield();
leds.show(pixels);
//setLedControls();
showLedLights();
}
// if (metroLedsReadyState.check() == 1)
// {
// showLedState();
// yield();
// }
// updateLeds();
#endif
}
}


2 changes: 1 addition & 1 deletion Faraday.NODEMCU/Faraday.NunchukClient.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ byte defaultNunchukNeutral = 127;
void readFromNunchukClient()
{
nunchuk.update();
delay(1);
yield();
#if defined(ENABLEDEVMODE)
Serial.println("DATA");
Serial.print(nunchuk.analogX, DEC);
Expand Down
28 changes: 0 additions & 28 deletions Faraday.NODEMCU/Faraday.OTA.ino

This file was deleted.

Loading

0 comments on commit 87a13ad

Please sign in to comment.