mirror of
https://github.com/sascha-hemi/HGD4_reversed.git
synced 2026-03-21 02:03:56 +01:00
Add button functionality + cleanup (#12)
* Add Button functionality * Delete NRF_firmware/variants/hgd6 directory * Delete NRF_firmware/boards/hgd6.json
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
Import("env")
|
Import("env")
|
||||||
|
|
||||||
@@ -13,7 +14,21 @@ def generate_production_binary(source, target, env):
|
|||||||
env.PioPlatform().get_package_dir("tool-sreccat") or "", "srec_cat"
|
env.PioPlatform().get_package_dir("tool-sreccat") or "", "srec_cat"
|
||||||
)
|
)
|
||||||
|
|
||||||
if not os.path.isfile(env.subst(production_image)):
|
# Get actual paths with variable substitution
|
||||||
|
firmware_hex_path = env.subst(firmware_hex)
|
||||||
|
production_image_path = env.subst(production_image)
|
||||||
|
dfu_package_path = env.subst(dfu_package)
|
||||||
|
|
||||||
|
# Check if we need to regenerate production image
|
||||||
|
need_production = True
|
||||||
|
if os.path.isfile(production_image_path) and os.path.isfile(firmware_hex_path):
|
||||||
|
# Check if firmware is newer than production image
|
||||||
|
firmware_time = os.path.getmtime(firmware_hex_path)
|
||||||
|
production_time = os.path.getmtime(production_image_path)
|
||||||
|
if firmware_time <= production_time:
|
||||||
|
need_production = False
|
||||||
|
|
||||||
|
if need_production:
|
||||||
assert os.path.isfile(bootloader_hex), "Missing bootloader image!"
|
assert os.path.isfile(bootloader_hex), "Missing bootloader image!"
|
||||||
assert os.path.isfile(signature_bin), "Missing signature file!"
|
assert os.path.isfile(signature_bin), "Missing signature file!"
|
||||||
env.Execute(
|
env.Execute(
|
||||||
@@ -23,8 +38,16 @@ def generate_production_binary(source, target, env):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Generate DFU package
|
# Check if we need to regenerate DFU package
|
||||||
if not os.path.isfile(env.subst(dfu_package)):
|
need_dfu = True
|
||||||
|
if os.path.isfile(dfu_package_path) and os.path.isfile(production_image_path):
|
||||||
|
# Check if production image is newer than DFU package
|
||||||
|
production_time = os.path.getmtime(production_image_path)
|
||||||
|
dfu_time = os.path.getmtime(dfu_package_path)
|
||||||
|
if production_time <= dfu_time:
|
||||||
|
need_dfu = False
|
||||||
|
|
||||||
|
if need_dfu:
|
||||||
env.Execute(
|
env.Execute(
|
||||||
env.VerboseAction(
|
env.VerboseAction(
|
||||||
f'adafruit-nrfutil dfu genpkg --dev-type 0x0052 --application "{firmware_hex}" "{dfu_package}"',
|
f'adafruit-nrfutil dfu genpkg --dev-type 0x0052 --application "{firmware_hex}" "{dfu_package}"',
|
||||||
@@ -32,4 +55,5 @@ def generate_production_binary(source, target, env):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Run this function after every build
|
||||||
env.AddPostAction("$BUILD_DIR/${PROGNAME}.hex", generate_production_binary)
|
env.AddPostAction("$BUILD_DIR/${PROGNAME}.hex", generate_production_binary)
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
[env:hgd6]
|
[env:hgd4]
|
||||||
platform = nordicnrf52
|
platform = nordicnrf52
|
||||||
board = hgd6
|
board = hgd4
|
||||||
framework = arduino
|
framework = arduino
|
||||||
board_build.variants_dir = variants
|
board_build.variants_dir = variants
|
||||||
board_build.variant = hgd6
|
board_build.variant = hgd4
|
||||||
lib_deps =
|
lib_deps =
|
||||||
adafruit/Adafruit Unified Sensor@^1.1.15
|
adafruit/Adafruit Unified Sensor@^1.1.15
|
||||||
adafruit/Adafruit LIS3DH@^1.3.0
|
adafruit/Adafruit LIS3DH@^1.3.0
|
||||||
|
|||||||
@@ -4,11 +4,11 @@
|
|||||||
ModemConfig deviceConfig;
|
ModemConfig deviceConfig;
|
||||||
|
|
||||||
//set if config should be saved to modem
|
//set if config should be saved to modem
|
||||||
bool saveConfig = true;
|
bool saveConfig = false;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
rtt.trimDownBufferFull();
|
rtt.trimDownBufferFull();
|
||||||
rtt.println("|x-------XStarting setupX-------x|");
|
rtt.println("|---------Starting setup---------|");
|
||||||
gpioinit();
|
gpioinit();
|
||||||
sensorData.wakeup_reason = NRF_POWER->RESETREAS;
|
sensorData.wakeup_reason = NRF_POWER->RESETREAS;
|
||||||
delay(200);
|
delay(200);
|
||||||
@@ -1483,7 +1483,7 @@ bool loadConfigFromModem(ModemConfig& config) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String configData;
|
String configData;
|
||||||
if (!modemFileRead(configData, 512)) { // Read up to 512 bytes
|
if (!modemFileRead(configData, 1024)) { // Read up to 512 bytes
|
||||||
rtt.println("Failed to read config data");
|
rtt.println("Failed to read config data");
|
||||||
modemFileClose();
|
modemFileClose();
|
||||||
return false;
|
return false;
|
||||||
@@ -2223,11 +2223,24 @@ bool waitForNextTransmission(unsigned long interval) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void performBackgroundTasks() {
|
void performBackgroundTasks() {
|
||||||
// Check battery voltage periodically
|
// Turn off on sw long press
|
||||||
static unsigned long lastBatteryCheck = 0;
|
if(digitalRead(PWR_SW_IN)){
|
||||||
if (millis() - lastBatteryCheck > 30000) { // Check every 30 seconds
|
rtt.println("Button pressed");
|
||||||
sensorData.battery_voltage = readBatteryVoltage();
|
digitalWrite(GREEN_LED,LOW);
|
||||||
lastBatteryCheck = millis();
|
delay(2000);
|
||||||
|
if(digitalRead(PWR_SW_IN)){
|
||||||
|
rtt.println("Button short press, powering down");
|
||||||
|
digitalWrite(GREEN_LED,HIGH);
|
||||||
|
digitalWrite(RED_LED,LOW);
|
||||||
|
delay(10000);
|
||||||
|
digitalWrite(PWR_LATCH,HIGH);
|
||||||
|
delay(10000);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
digitalWrite(GREEN_LED,HIGH);
|
||||||
|
rtt.println("Button short press, transmitting now");
|
||||||
|
lastWaitCheck = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deviceConfig.motion_detection_enabled && millis() - lastMotionCheck > 100) {
|
if (deviceConfig.motion_detection_enabled && millis() - lastMotionCheck > 100) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
r
|
r
|
||||||
loadfile /home/jonas/Desktop/dd/HGD4_reversed-main/NRF_firmware/.pio/build/hgd6/production.hex
|
loadfile /home/jonas/Desktop/dd/HGD4_reversed-main/NRF_firmware/.pio/build/hgd4/production.hex
|
||||||
r
|
r
|
||||||
g
|
g
|
||||||
exit
|
exit
|
||||||
|
|||||||
Reference in New Issue
Block a user