LED-Tweak and some first Functions für LubeApp
This commit is contained in:
parent
ffe943f187
commit
829e70d11a
@ -4,10 +4,10 @@
|
|||||||
#define Q(x) #x
|
#define Q(x) #x
|
||||||
#define QUOTE(x) Q(x)
|
#define QUOTE(x) Q(x)
|
||||||
|
|
||||||
#define GPIO_BUTTON 14
|
#define GPIO_BUTTON D5
|
||||||
#define GPIO_LED D6
|
#define GPIO_LED D6
|
||||||
#define GPIO_TRIGGER 2
|
#define GPIO_TRIGGER D4
|
||||||
#define GPIO_PUMP 0
|
#define GPIO_PUMP D3
|
||||||
|
|
||||||
#ifndef HOST_NAME
|
#ifndef HOST_NAME
|
||||||
#define HOST_NAME "ChainLube_%06X" // Use printf-Formatting - Chip-ID (uin32_t) will be added
|
#define HOST_NAME "ChainLube_%06X" // Use printf-Formatting - Chip-ID (uin32_t) will be added
|
||||||
|
24
Software/ChainLube/src/globals.h
Normal file
24
Software/ChainLube/src/globals.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#ifndef _GLOBALS_H_
|
||||||
|
#define _GLOBALS_H_
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
typedef enum eSystem_Status
|
||||||
|
{
|
||||||
|
sysStat_NOP,
|
||||||
|
sysStat_Startup,
|
||||||
|
sysStat_Normal,
|
||||||
|
sysStat_Rain,
|
||||||
|
sysStat_Purge,
|
||||||
|
sysStat_Error
|
||||||
|
} tSystem_Status;
|
||||||
|
|
||||||
|
typedef struct Globals_t {
|
||||||
|
tSystem_Status systemStatus = sysStat_Startup;
|
||||||
|
uint8_t purgePulses= 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern Globals_t globals;
|
||||||
|
extern uint32_t TravelDistance_highRes;
|
||||||
|
|
||||||
|
#endif
|
@ -1,7 +1,32 @@
|
|||||||
#include "lubeapp.h"
|
#include "lubeapp.h"
|
||||||
|
|
||||||
|
extern void LED_Process();
|
||||||
|
|
||||||
void RunLubeApp(LubeConfig_t *cfg)
|
void RunLubeApp(volatile uint32_t *wheelPulseCounter)
|
||||||
{
|
{
|
||||||
|
uint32_t LubeDistance = 0;
|
||||||
|
static uint32_t lubePulseTimestamp = 0;
|
||||||
|
// Calculate traveled Distance in mm
|
||||||
|
TravelDistance_highRes += (*wheelPulseCounter * LubeConfig.DistancePerRevolution_mm);
|
||||||
|
*wheelPulseCounter = 0;
|
||||||
|
|
||||||
|
// check if we have to Lube!
|
||||||
|
switch (globals.systemStatus)
|
||||||
|
{
|
||||||
|
case sysStat_Normal:
|
||||||
|
LubeDistance = LubeConfig.DistancePerLube_Default;
|
||||||
|
break;
|
||||||
|
case sysStat_Rain:
|
||||||
|
LubeDistance = LubeConfig.DistancePerLube_Rain;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TravelDistance_highRes > LubeDistance)
|
||||||
|
lubePulseTimestamp = millis() + LUBE_PULSE_LENGHT_MS;
|
||||||
|
|
||||||
|
//maintain Pin-State of Lube-Pump
|
||||||
|
if (lubePulseTimestamp > millis())
|
||||||
|
digitalWrite(GPIO_PUMP, HIGH);
|
||||||
|
else
|
||||||
|
digitalWrite(GPIO_PUMP, LOW);
|
||||||
}
|
}
|
@ -3,17 +3,11 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "common.h"
|
||||||
|
#include "globals.h"
|
||||||
|
|
||||||
typedef enum eSystem_Status
|
#define LUBE_PULSE_LENGHT_MS 1000
|
||||||
{
|
|
||||||
sysStat_NOP,
|
|
||||||
sysStat_Startup,
|
|
||||||
sysStat_Normal,
|
|
||||||
sysStat_Rain,
|
|
||||||
sysStat_Purge,
|
|
||||||
sysStat_Error
|
|
||||||
} tSystem_Status;
|
|
||||||
|
|
||||||
void RunLubeApp(LubeConfig_t *cfg);
|
void RunLubeApp(volatile uint32_t * wheelPulseCounter);
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -14,6 +14,7 @@
|
|||||||
#include "lubeapp.h"
|
#include "lubeapp.h"
|
||||||
#include "webui.h"
|
#include "webui.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "globals.h"
|
||||||
|
|
||||||
const char *ssid = QUOTE(WIFI_SSID);
|
const char *ssid = QUOTE(WIFI_SSID);
|
||||||
const char *password = QUOTE(WIFI_PASSWORD);
|
const char *password = QUOTE(WIFI_PASSWORD);
|
||||||
@ -29,6 +30,8 @@ const bool debug_flag = false;
|
|||||||
bool startSetupMode = false;
|
bool startSetupMode = false;
|
||||||
char DeviceName[33];
|
char DeviceName[33];
|
||||||
|
|
||||||
|
Globals_t globals;
|
||||||
|
uint32_t TravelDistance_highRes;
|
||||||
volatile uint32_t wheel_pulse = 0;
|
volatile uint32_t wheel_pulse = 0;
|
||||||
|
|
||||||
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(-1);
|
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(-1);
|
||||||
@ -43,16 +46,19 @@ void RemotDebug_printSystemInfo();
|
|||||||
void RemoteDebug_printWifiInfo();
|
void RemoteDebug_printWifiInfo();
|
||||||
void wifiMaintainConnectionTicker_callback();
|
void wifiMaintainConnectionTicker_callback();
|
||||||
void IRAM_ATTR trigger_ISR();
|
void IRAM_ATTR trigger_ISR();
|
||||||
void LED_Process(tSystem_Status newStatus);
|
void LED_Process(tSystem_Status newStatus = sysStat_NOP);
|
||||||
|
|
||||||
Ticker WiFiMaintainConnectionTicker(wifiMaintainConnectionTicker_callback, 1000, 0, MILLIS);
|
Ticker WiFiMaintainConnectionTicker(wifiMaintainConnectionTicker_callback, 1000, 0, MILLIS);
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
system_update_cpu_freq(SYS_CPU_80MHZ);
|
system_update_cpu_freq(SYS_CPU_80MHZ);
|
||||||
|
|
||||||
snprintf(DeviceName, 32, HOST_NAME, ESP.getChipId());
|
snprintf(DeviceName, 32, HOST_NAME, ESP.getChipId());
|
||||||
|
|
||||||
WiFi.mode(WIFI_OFF);
|
WiFi.mode(WIFI_OFF);
|
||||||
WiFi.persistent(false);
|
WiFi.persistent(false);
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.setDebugOutput(true);
|
Serial.setDebugOutput(true);
|
||||||
|
|
||||||
@ -76,15 +82,6 @@ void setup()
|
|||||||
WiFi.setHostname(DeviceName);
|
WiFi.setHostname(DeviceName);
|
||||||
wifiMulti.addAP(QUOTE(WIFI_SSID), QUOTE(WIFI_PASSWORD));
|
wifiMulti.addAP(QUOTE(WIFI_SSID), QUOTE(WIFI_PASSWORD));
|
||||||
|
|
||||||
Serial.println("Connecting Wifi...");
|
|
||||||
if (wifiMulti.run() == WL_CONNECTED)
|
|
||||||
{
|
|
||||||
Serial.println("");
|
|
||||||
Serial.println("WiFi connected");
|
|
||||||
Serial.println("IP address: ");
|
|
||||||
Serial.print(WiFi.localIP());
|
|
||||||
}
|
|
||||||
|
|
||||||
WiFiMaintainConnectionTicker.start();
|
WiFiMaintainConnectionTicker.start();
|
||||||
|
|
||||||
if (MDNS.begin(DeviceName))
|
if (MDNS.begin(DeviceName))
|
||||||
@ -141,16 +138,15 @@ void setup()
|
|||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
|
LED_Process();
|
||||||
tSystem_Status status = sysStat_NOP;
|
RunLubeApp(&wheel_pulse);
|
||||||
|
|
||||||
// status = digitalRead(GPIO_BUTTON) ? Ready_normal : Ready_rain;
|
|
||||||
|
|
||||||
LED_Process(status);
|
|
||||||
RunLubeApp(&LubeConfig);
|
|
||||||
|
|
||||||
WiFiMaintainConnectionTicker.update();
|
WiFiMaintainConnectionTicker.update();
|
||||||
FastLED.show();
|
|
||||||
|
u8x8.setCursor(0, 3);
|
||||||
|
u8x8.printf("%4d m", TravelDistance_highRes / 1000);
|
||||||
|
u8x8.refreshDisplay();
|
||||||
|
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
Debug.handle();
|
Debug.handle();
|
||||||
yield();
|
yield();
|
||||||
@ -230,12 +226,11 @@ void trigger_ISR()
|
|||||||
wheel_pulse++;
|
wheel_pulse++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LED_Process(tSystem_Status newSysStatus = sysStat_NOP)
|
void LED_Process(tSystem_Status newSysStatus)
|
||||||
{
|
{
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
LED_NOP,
|
|
||||||
LED_Startup,
|
LED_Startup,
|
||||||
LED_Normal,
|
LED_Normal,
|
||||||
LED_Confirm_Normal,
|
LED_Confirm_Normal,
|
||||||
@ -246,61 +241,87 @@ void LED_Process(tSystem_Status newSysStatus = sysStat_NOP)
|
|||||||
} tLED_Status;
|
} tLED_Status;
|
||||||
|
|
||||||
static tSystem_Status oldSysStatus = sysStat_NOP;
|
static tSystem_Status oldSysStatus = sysStat_NOP;
|
||||||
static tLED_Status LED_Status = LED_NOP;
|
static tLED_Status LED_Status = LED_Startup;
|
||||||
uint8_t color;
|
|
||||||
uint32_t timer;
|
|
||||||
|
|
||||||
|
uint8_t color = 0;
|
||||||
|
uint32_t timer = 0;
|
||||||
|
uint32_t timestamp = 0;
|
||||||
|
|
||||||
|
if (newSysStatus != sysStat_NOP)
|
||||||
|
{
|
||||||
if (oldSysStatus != newSysStatus)
|
if (oldSysStatus != newSysStatus)
|
||||||
{
|
{
|
||||||
switch (newSysStatus)
|
switch (newSysStatus)
|
||||||
{
|
{
|
||||||
case sysStat_NOP:
|
|
||||||
break;
|
|
||||||
case sysStat_Startup:
|
case sysStat_Startup:
|
||||||
|
LED_Status = LED_Startup;
|
||||||
break;
|
break;
|
||||||
case sysStat_Normal:
|
case sysStat_Normal:
|
||||||
|
timestamp = millis() + 1500;
|
||||||
|
LED_Status = LED_Confirm_Normal;
|
||||||
|
FastLED.setBrightness(64);
|
||||||
break;
|
break;
|
||||||
case sysStat_Rain:
|
case sysStat_Rain:
|
||||||
|
timestamp = millis() + 1500;
|
||||||
|
LED_Status = LED_Confirm_Rain;
|
||||||
|
FastLED.setBrightness(64);
|
||||||
break;
|
break;
|
||||||
case sysStat_Purge:
|
case sysStat_Purge:
|
||||||
|
LED_Status = LED_Purge;
|
||||||
break;
|
break;
|
||||||
case sysStat_Error:
|
case sysStat_Error:
|
||||||
|
LED_Status = LED_Error;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
oldSysStatus = newSysStatus;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FastLED.setBrightness(64);
|
|
||||||
timer = millis();
|
timer = millis();
|
||||||
|
|
||||||
switch (LED_Status)
|
switch (LED_Status)
|
||||||
{
|
{
|
||||||
case LED_NOP:
|
|
||||||
break;
|
|
||||||
case LED_Startup:
|
case LED_Startup:
|
||||||
timer = timer % 2000;
|
timer = timer % 2000;
|
||||||
color = timer > 500 ? 0 : (uint8_t)(timer / 2);
|
color = timer > 500 ? 0 : (uint8_t)(timer / 2);
|
||||||
leds[0] = CRGB(color, color, 0);
|
leds[0] = CRGB(color, color, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LED_Confirm_Normal:
|
case LED_Confirm_Normal:
|
||||||
leds[0] = millis() % 2000 > 1900 ? CRGB::Green : CRGB::Black;
|
if (timestamp < timer)
|
||||||
|
LED_Status = LED_Normal;
|
||||||
|
leds[0] = timer % 500 > 250 ? CRGB::Green : CRGB::Black;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LED_Normal:
|
case LED_Normal:
|
||||||
leds[0] = millis() % 2000 > 1900 ? CRGB::Blue : CRGB::Black;
|
leds[0] = timer % 2000 > 1950 ? CRGB::Green : CRGB::Black;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LED_Confirm_Rain:
|
case LED_Confirm_Rain:
|
||||||
leds[0] = millis() % 2000 > 1900 ? CRGB::Green : CRGB::Black;
|
if (timestamp < timer)
|
||||||
|
LED_Status = LED_Rain;
|
||||||
|
leds[0] = timer % 500 > 250 ? CRGB::Blue : CRGB::Black;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LED_Rain:
|
case LED_Rain:
|
||||||
leds[0] = millis() % 2000 > 1900 ? CRGB::Blue : CRGB::Black;
|
leds[0] = timer % 2000 > 1950 ? CRGB::Blue : CRGB::Black;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LED_Purge:
|
case LED_Purge:
|
||||||
leds[0] = millis() % 2000 > 1900 ? CRGB::HotPink : CRGB::Black;
|
timer = timer % 500;
|
||||||
|
color = timer / 2;
|
||||||
|
leds[0] = CRGB::DeepPink;
|
||||||
|
if (timer < 250)
|
||||||
|
FastLED.setBrightness(color);
|
||||||
|
else
|
||||||
|
FastLED.setBrightness(250 - color);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LED_Error:
|
case LED_Error:
|
||||||
leds[0] = millis() % 500 > 250 ? CRGB::Red : CRGB::Black;
|
leds[0] = timer % 500 > 250 ? CRGB::Red : CRGB::Black;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
FastLED.show();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user