Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _Boards/Atmel/Board_Mega/arduino_mega.board.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"DelayAfterFirmwareUpdate": 0,
"FirmwareBaseName": "mobiflight_mega",
"FirmwareExtension": "hex",
"LatestFirmwareVersion": "3.0.0",
"LatestFirmwareVersion": "0.0.1",
"FriendlyName": "Arduino Mega 2560",
"MobiFlightType": "MobiFlight Mega",
"ResetFirmwareFile": "reset.arduino_mega_1_0_2.hex"
Expand Down
2 changes: 1 addition & 1 deletion _Boards/Atmel/Board_Nano/arduino_nano.board.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"FirmwareBaseName": "mobiflight_nano",
"FirmwareExtension": "hex",
"FriendlyName": "Arduino Nano",
"LatestFirmwareVersion": "3.0.0",
"LatestFirmwareVersion": "0.0.1",
"MobiFlightType": "MobiFlight Nano",
"ResetFirmwareFile": "reset.arduino_uno_1_0_2.hex"
},
Expand Down
2 changes: 1 addition & 1 deletion _Boards/Atmel/Board_ProMicro/arduino_micro.board.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"FirmwareBaseName": "mobiflight_micro",
"FirmwareExtension": "hex",
"FriendlyName": "Arduino Pro Micro",
"LatestFirmwareVersion": "3.0.0",
"LatestFirmwareVersion": "0.0.1",
"MobiFlightType": "MobiFlight Micro",
"ResetFirmwareFile": "reset.arduino_promicro_1_0_2.hex"
},
Expand Down
2 changes: 1 addition & 1 deletion _Boards/Atmel/Board_Uno/arduino_uno.board.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"FriendlyName": "Arduino Uno",
"FirmwareBaseName": "mobiflight_uno",
"FirmwareExtension": "hex",
"LatestFirmwareVersion": "3.0.0",
"LatestFirmwareVersion": "0.0.1",
"MobiFlightType": "MobiFlight Uno",
"ResetFirmwareFile": "reset.arduino_uno_1_0_2.hex"
},
Expand Down
2 changes: 1 addition & 1 deletion _Boards/RaspberryPi/Pico/raspberrypi_pico.board.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"FirmwareBaseName": "mobiflight_raspberrypico",
"FirmwareExtension": "uf2",
"FriendlyName": "Raspberry Pico",
"LatestFirmwareVersion": "3.0.0",
"LatestFirmwareVersion": "0.0.1",
"MobiFlightType": "MobiFlight RaspiPico",
"ResetFirmwareFile": "reset.raspberry_pico_flash_nuke.uf2"
},
Expand Down
26 changes: 23 additions & 3 deletions copy_fw_files.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Import("env")
import os, zipfile, shutil
import fileinput
from pathlib import Path

# Get the version number from the build environment.
Expand All @@ -10,9 +11,9 @@
firmware_version = firmware_version.strip(".")

zip_file_name = 'Mobiflight-Connector'
build_path = './_build'
build_path_fw = build_path + '/firmware'
build_path_json = build_path + '/Boards'
build_path = Path('./_build')
build_path_fw = build_path / 'firmware'
build_path_json = build_path / 'Boards'
distrubution_path = './_dist'
board_folder = ['./_Boards/Atmel', './_Boards/RaspberryPi']

Expand All @@ -38,6 +39,13 @@ def copy_fw_files (source, target, env):
file_extension = '.json'
copy_files_by_extension(board_folder, build_path_json, file_extension)

# set FW version within boad.json files
replacements = {
"0.0.1": firmware_version
}
for file_path in build_path_json.rglob("*.json"):
replace_in_file(file_path, replacements)

# Create ZIP file and add files from distrubution folder
zip_file_path = distrubution_path + '/' + zip_file_name + '_' + firmware_version + '.zip'
createZIP(build_path, zip_file_path, zip_file_name)
Expand Down Expand Up @@ -65,5 +73,17 @@ def createZIP(original_folder_path, zip_file_path, new_folder_name):
zipf.write(os.path.join(root, file), new_path)


def replace_in_file(file_path, replacements):
"""Replace all keys in `replacements` with their values in the given file."""
with open(file_path, "r", encoding="utf-8") as file:
content = file.read()

for old, new in replacements.items():
content = content.replace(old, new)

with open(file_path, "w", encoding="utf-8") as file:
file.write(content)


env.AddPostAction("$BUILD_DIR/${PROGNAME}.hex", copy_fw_files)
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", copy_fw_files)
Loading