mirror of
https://github.com/sascha-hemi/HGD4_reversed.git
synced 2026-03-21 00:03:48 +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 time
|
||||
|
||||
Import("env")
|
||||
|
||||
@@ -13,7 +14,21 @@ def generate_production_binary(source, target, env):
|
||||
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(signature_bin), "Missing signature file!"
|
||||
env.Execute(
|
||||
@@ -23,8 +38,16 @@ def generate_production_binary(source, target, env):
|
||||
)
|
||||
)
|
||||
|
||||
# Generate DFU package
|
||||
if not os.path.isfile(env.subst(dfu_package)):
|
||||
# Check if we need to regenerate 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.VerboseAction(
|
||||
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)
|
||||
@@ -1,9 +1,9 @@
|
||||
[env:hgd6]
|
||||
[env:hgd4]
|
||||
platform = nordicnrf52
|
||||
board = hgd6
|
||||
board = hgd4
|
||||
framework = arduino
|
||||
board_build.variants_dir = variants
|
||||
board_build.variant = hgd6
|
||||
board_build.variant = hgd4
|
||||
lib_deps =
|
||||
adafruit/Adafruit Unified Sensor@^1.1.15
|
||||
adafruit/Adafruit LIS3DH@^1.3.0
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
ModemConfig deviceConfig;
|
||||
|
||||
//set if config should be saved to modem
|
||||
bool saveConfig = true;
|
||||
bool saveConfig = false;
|
||||
|
||||
void setup() {
|
||||
rtt.trimDownBufferFull();
|
||||
rtt.println("|x-------XStarting setupX-------x|");
|
||||
rtt.println("|---------Starting setup---------|");
|
||||
gpioinit();
|
||||
sensorData.wakeup_reason = NRF_POWER->RESETREAS;
|
||||
delay(200);
|
||||
@@ -1483,7 +1483,7 @@ bool loadConfigFromModem(ModemConfig& config) {
|
||||
return false;
|
||||
}
|
||||
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");
|
||||
modemFileClose();
|
||||
return false;
|
||||
@@ -2223,11 +2223,24 @@ bool waitForNextTransmission(unsigned long interval) {
|
||||
}
|
||||
|
||||
void performBackgroundTasks() {
|
||||
// Check battery voltage periodically
|
||||
static unsigned long lastBatteryCheck = 0;
|
||||
if (millis() - lastBatteryCheck > 30000) { // Check every 30 seconds
|
||||
sensorData.battery_voltage = readBatteryVoltage();
|
||||
lastBatteryCheck = millis();
|
||||
// Turn off on sw long press
|
||||
if(digitalRead(PWR_SW_IN)){
|
||||
rtt.println("Button pressed");
|
||||
digitalWrite(GREEN_LED,LOW);
|
||||
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) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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
|
||||
g
|
||||
exit
|
||||
|
||||
Reference in New Issue
Block a user