Updated code for hardware group 2 (from HW v1.2 onwards)

This commit is contained in:
Julian Metzler 2018-12-18 21:03:31 +01:00
parent 42a189e9a8
commit ac0360fdba
7 changed files with 55 additions and 14 deletions

View File

@ -59,8 +59,19 @@ enum UpdateStatus {
CONSTANTS CONSTANTS
*/ */
#define PIN_STATUS 10 #define HW_GROUP 2 // Changes with hardware changes that require software changes
#if HW_GROUP == 1
#define PIN_STATUS 10
#define PIN_ACTIVITY 9 // Unusable
#define PIN_CONFIG 0
#endif
#if HW_GROUP == 2
#define PIN_STATUS 5
#define PIN_ACTIVITY 4
#define PIN_CONFIG 0 #define PIN_CONFIG 0
#endif
#define WIFI_TIMEOUT 10000 #define WIFI_TIMEOUT 10000
#define UPDATE_START_DELAY 3000 #define UPDATE_START_DELAY 3000
@ -69,8 +80,7 @@ enum UpdateStatus {
GLOBAL VARIABLES GLOBAL VARIABLES
*/ */
unsigned long HW_GROUP = 1; // Changes with hardware changes that require software changes unsigned long FW_VERSION = 1812180001; // Changes with each release; must always increase
unsigned long FW_VERSION = 1808070003; // Changes with each release; must always increase
unsigned long SP_VERSION = 0; // Loaded from SPIFFS; changed with each SPIFFS build; must always increase (uses timestamp as version) unsigned long SP_VERSION = 0; // Loaded from SPIFFS; changed with each SPIFFS build; must always increase (uses timestamp as version)
// FW & SPIFFS update settings // FW & SPIFFS update settings
@ -221,6 +231,25 @@ void blinkLEDStatusLoop(unsigned int duration) {
delay(duration); delay(duration);
} }
void setLEDActivity(bool state) {
#if HW_GROUP == 1
digitalWrite(PIN_STATUS, state);
#else
digitalWrite(PIN_ACTIVITY, state);
#endif
}
void blinkLEDActivitySingle(unsigned int duration) {
setLEDActivity(1);
delay(duration);
setLEDActivity(0);
}
void blinkLEDActivityLoop(unsigned int duration) {
blinkLEDActivitySingle(duration);
delay(duration);
}
void handleConfigButton() { void handleConfigButton() {
// Read the config button state to determine if it has been pressed or released // Read the config button state to determine if it has been pressed or released
btnState = !digitalRead(PIN_CONFIG); btnState = !digitalRead(PIN_CONFIG);
@ -598,6 +627,7 @@ t_httpUpdate_return doUpdateInsecure(bool spiffs) {
void doUpdate(bool spiffs) { void doUpdate(bool spiffs) {
// Set both LEDs on during update // Set both LEDs on during update
setLEDStatus(1); setLEDStatus(1);
setLEDActivity(1);
pinMode(2, OUTPUT); pinMode(2, OUTPUT);
digitalWrite(2, LOW); digitalWrite(2, LOW);
@ -636,6 +666,9 @@ void setup() {
WiFi.mode(WIFI_AP); WiFi.mode(WIFI_AP);
pinMode(PIN_STATUS, OUTPUT); pinMode(PIN_STATUS, OUTPUT);
#if HW_GROUP != 1
pinMode(PIN_ACTIVITY, OUTPUT);
#endif
pinMode(PIN_CONFIG, INPUT_PULLUP); pinMode(PIN_CONFIG, INPUT_PULLUP);
//attachInterrupt(digitalPinToInterrupt(PIN_CONFIG), ISR_config, CHANGE); //attachInterrupt(digitalPinToInterrupt(PIN_CONFIG), ISR_config, CHANGE);
@ -702,7 +735,8 @@ void setup() {
#endif #endif
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
blinkLEDStatusLoop(125); blinkLEDStatusLoop(60);
blinkLEDActivityLoop(60);
} }
if (AP_ACTIVE) { if (AP_ACTIVE) {
@ -733,12 +767,14 @@ void loop() {
if (newClient) client = newClient; if (newClient) client = newClient;
if (client) { if (client) {
while (client.available()) { while (client.available()) {
setLEDStatus(1); setLEDActivity(1);
Serial.write(client.read()); Serial.write(client.read());
setLEDStatus(0); setLEDActivity(0);
} }
while (Serial.available()) { while (Serial.available()) {
setLEDActivity(1);
client.write(Serial.read()); client.write(Serial.read());
setLEDActivity(0);
} }
} }

View File

@ -1 +0,0 @@
1808070003

Binary file not shown.

1
firmware1.version Normal file
View File

@ -0,0 +1 @@
1812180001

BIN
firmware2.bin Normal file

Binary file not shown.

1
firmware2.version Normal file
View File

@ -0,0 +1 @@
1812180001

View File

@ -10,16 +10,20 @@ import os
import re import re
import time import time
with open("WiFi_Shield.ino", 'r') as f: with open("Caracal_Firmware.ino", 'r') as f:
code = f.read() code = f.read()
match = re.search(r"#define HW_GROUP (\d+)", code)
hw_version = match.group(1)
match = re.search(r"FW_VERSION = (\d+);", code) match = re.search(r"FW_VERSION = (\d+);", code)
fw_version = match.group(1) fw_version = match.group(1)
with open("firmware.version", 'w') as f: fname = "firmware{}.bin".format(hw_version)
f.write(fw_version) if os.path.exists("Caracal_Firmware.ino.generic.bin"):
if os.path.exists(fname):
os.remove(fname)
os.rename("Caracal_Firmware.ino.generic.bin", fname)
if os.path.exists("WiFi_Shield.ino.generic.bin"): with open("firmware{}.version".format(hw_version), 'w') as f:
if os.path.exists("firmware.bin"): f.write(fw_version)
os.remove("firmware.bin")
os.rename("WiFi_Shield.ino.generic.bin", "firmware.bin")