Merge pull request #195 from cyberman54/development

v1.6.53
This commit is contained in:
Verkehrsrot 2018-11-02 08:41:49 +01:00 committed by GitHub
commit cd756af443
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
57 changed files with 115 additions and 18 deletions

View File

@ -37,5 +37,8 @@ extern TaskHandle_t ledLoopTask;
void rgb_set_color(uint16_t hue);
void blink_LED(uint16_t set_color, uint16_t set_blinkduration);
void ledLoop(void *parameter);
#if (HAS_LED != NOT_A_PIN)
void switch_LED(uint8_t state);
#endif
#endif

View File

@ -12,5 +12,6 @@
#include "beacon_array.h"
#include "ota.h"
#include "irqhandler.h"
#include "led.h"
#endif

View File

@ -1,9 +1,34 @@
#ifndef _SPISEND_H
#define _SPISEND_H
#include "globals.h"
#include "spi.h"
extern TaskHandle_t SpiTask;
extern QueueHandle_t SPISendQueue;
/*
* Process data in SPI send queue
*/
void spi_loop(void *pvParameters);
/*
* initialize local SPI wire interface
*/
void hal_spi_init();
/*
* Perform SPI write transaction on local SPI wire interface
* - write the command byte 'cmd'
* - write 'len' bytes out of 'buf'
*/
void hal_spi_write(uint8_t cmd, const uint8_t* buf, int len);
/*
* Perform SPI read transaction on local SPI wire interface
* - read the command byte 'cmd'
* - read 'len' bytes into 'buf'
*/
void hal_spi_read(uint8_t cmd, uint8_t* buf, int len);
#endif

View File

@ -29,7 +29,7 @@ description = Paxcounter is a proof-of-concept ESP32 device for metering passeng
[common]
; for release_version use max. 10 chars total, use any decimal format like "a.b.c"
release_version = 1.6.51
release_version = 1.6.54
; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running!
; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose
debug_level = 0

View File

@ -25,7 +25,7 @@
#define LORA_MOSI (27)
#define LORA_RST (14)
#define LORA_IO0 (26)
#define LORA_IO1 (34)
#define LORA_IO2 (35)
#define LORA_IO1 (35)
#define LORA_IO2 (34)
#endif

View File

@ -87,6 +87,28 @@ void rgb_set_color(uint16_t hue) {}
#endif
#if (HAS_LED != NOT_A_PIN)
void switch_LED(uint8_t state) {
if (state == LED_ON) {
// switch LED on
#ifdef LED_ACTIVE_LOW
digitalWrite(HAS_LED, LOW);
#else
digitalWrite(HAS_LED, HIGH);
#endif
} else if (state == LED_OFF) {
// switch LED off
#ifdef LED_ACTIVE_LOW
digitalWrite(HAS_LED, HIGH);
#else
digitalWrite(HAS_LED, LOW);
#endif
}
}
#endif
#if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED)
void blink_LED(uint16_t set_color, uint16_t set_blinkduration) {
@ -98,7 +120,8 @@ void blink_LED(uint16_t set_color, uint16_t set_blinkduration) {
void ledLoop(void *parameter) {
while (1) {
// Custom blink running always have priority other LoRaWAN led management
// Custom blink running always have priority other LoRaWAN led
// management
if (LEDBlinkStarted && LEDBlinkDuration) {
// Custom blink is finished, let this order, avoid millis() overflow
if ((millis() - LEDBlinkStarted) >= LEDBlinkDuration) {
@ -154,20 +177,14 @@ void ledLoop(void *parameter) {
if (LEDState != previousLEDState) {
if (LEDState == LED_ON) {
rgb_set_color(LEDColor);
#ifdef LED_ACTIVE_LOW
digitalWrite(HAS_LED, LOW);
#else
digitalWrite(HAS_LED, HIGH);
// if we have only single LED we use it to blink for status
#ifndef HAS_RGB_LED
switch_LED(LED_ON);
#endif
} else {
rgb_set_color(COLOR_NONE);
#ifdef LED_ACTIVE_LOW
digitalWrite(HAS_LED, HIGH);
#else
digitalWrite(HAS_LED, LOW);
#ifndef HAS_RGB_LED
switch_LED(LED_OFF);
#endif
}
previousLEDState = LEDState;

View File

@ -96,7 +96,12 @@ void setup() {
#if (HAS_LED != NOT_A_PIN)
pinMode(HAS_LED, OUTPUT);
strcat_P(features, " LED");
// switch on power LED if we have 2 LEDs, else use it for status
#ifdef HAS_RGB_LED
switch_LED(LED_ON);
#endif
#endif
#ifdef HAS_RGB_LED
rgb_set_color(COLOR_PINK);
strcat_P(features, " RGB");

View File

@ -48,6 +48,7 @@ void PayloadConvert::addConfig(configData_t value) {
buffer[cursor++] = value.vendorfilter;
buffer[cursor++] = value.rgblum;
buffer[cursor++] = value.gpsmode;
buffer[cursor++] = value.monitormode;
memcpy(buffer + cursor, value.version, 10);
cursor += 10;
}

View File

@ -105,7 +105,10 @@ void set_countmode(uint8_t val[]) {
ESP_LOGW(
TAG,
"Remote command: set counter mode called with invalid parameter(s)");
return;
}
reset_counters(); // clear macs
get_salt(); // get new salt
}
void set_screensaver(uint8_t val[]) {

View File

@ -1,6 +1,6 @@
#ifdef HAS_SPI
#include "globals.h"
#include "spisend.h"
// Local logging tag
static const char TAG[] = "main";
@ -13,18 +13,60 @@ TaskHandle_t SpiTask;
// SPI feed Task
void spi_loop(void *pvParameters) {
uint8_t buf[32];
configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check
while (1) {
// check if data to send on SPI interface
if (xQueueReceive(SPISendQueue, &SendBuffer, (TickType_t)0) == pdTRUE) {
hal_spi_write(SendBuffer.MessagePort, SendBuffer.Message,
SendBuffer.MessageSize);
ESP_LOGI(TAG, "%d bytes sent to SPI", SendBuffer.MessageSize);
}
vTaskDelay(2 / portTICK_PERIOD_MS); // yield to CPU
} // end of infinite loop
// check if command is received on SPI command port, then call interpreter
hal_spi_read(RCMDPORT, buf, 32);
if (buf[0])
rcommand(buf, sizeof(buf));
vTaskDelay(2 / portTICK_PERIOD_MS); // yield to CPU
} // end of infinite loop
vTaskDelete(NULL); // shoud never be reached
} // spi_loop()
// SPI hardware abstraction layer
void hal_spi_init() { SPI.begin(SCK, MISO, MOSI, SS); }
void hal_spi_trx(uint8_t port, uint8_t *buf, int len, uint8_t is_read) {
SPISettings settings(1E6, MSBFIRST, SPI_MODE0);
SPI.beginTransaction(settings);
digitalWrite(SS, 0);
SPI.transfer(port);
for (uint8_t i = 0; i < len; i++) {
uint8_t *p = buf + i;
uint8_t data = is_read ? 0x00 : *p;
data = SPI.transfer(data);
if (is_read)
*p = data;
}
digitalWrite(SS, 1);
SPI.endTransaction();
}
void hal_spi_write(uint8_t port, const uint8_t *buf, int len) {
hal_spi_trx(port, (uint8_t *)buf, len, 0);
}
void hal_spi_read(uint8_t port, uint8_t *buf, int len) {
hal_spi_trx(port, buf, len, 1);
}
#endif // HAS_SPI