Skip to content

Instantly share code, notes, and snippets.

@alex-luxonis
Created March 17, 2023 14:47
Show Gist options
  • Save alex-luxonis/c1755a1dc32af67cf9ab76182cdf1c02 to your computer and use it in GitHub Desktop.
Save alex-luxonis/c1755a1dc32af67cf9ab76182cdf1c02 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import os
# WARNING: never set this environment variable with other scripts,
# EEPROM/calib data corruption may occur, or it may even soft-brick the device!
# Also this environment variable should be set externally instead of enabling here
#os.environ["DEPTHAI_ALLOW_FACTORY_FLASHING"] = "235539980"
import depthai as dai
import argparse
import time
parser = argparse.ArgumentParser()
parser.add_argument('-a', '--add_string', default='FFC',
help="String to append to board name. Most common: FFC-3P "
"or FFC-4P. Default: FFC (acting the same as FFC-4P)")
parser.add_argument('-b', '--to_board', default=False, action="store_true",
help="Append to `boardName` instead of `productName`")
parser.add_argument('--overwrite', default=False, action="store_true",
help="Overwrite instead of appending the `-a` option string")
args = parser.parse_args()
with dai.Device(dai.OpenVINO.VERSION_UNIVERSAL, dai.UsbSpeed.HIGH) as device:
mxid = device.getMxId()
name = device.getDeviceName()
calib = device.readCalibration()
boardName = calib.getEepromData().boardName
boardRev = calib.getEepromData().boardRev
productName = calib.getEepromData().productName
newCalib = calib
if args.to_board:
if args.overwrite:
newCalib.setBoardInfo(args.add_string, boardRev)
else:
newCalib.setBoardInfo(boardName + ' ' + args.add_string, boardRev)
else:
if args.overwrite:
newCalib.setProductName(args.add_string)
else:
newCalib.setProductName(productName + ' ' + args.add_string)
print(f"Modifying EEPROM board/product name for the device {name} with ID {mxid}. Original:")
print(" >>> Existing board name :", boardName)
print(" >>> Existing product name:", productName)
boardName = newCalib.getEepromData().boardName
productName = newCalib.getEepromData().productName
print(" >>> NEW board name :", boardName)
print(" >>> NEW product name :", productName)
print()
print("WARNING: Please confirm that the device addressed above is the correct one.")
print("Use with caution, and only on FFC devices! Soft-bricking may occur otherwise!")
print(" Type 'yes' and press Enter to continue... ", end="")
if input().lower() != 'yes':
print("Prompt declined, exiting...")
exit(-1)
currentTime = time.strftime('%Y%m%d_%H%M%S')
backupName = f"backup_{name}_{mxid}_{currentTime}.calib"
calib.eepromToJsonFile(backupName)
print(f'Previous device calibration data backed up at: {backupName}')
print("Flashing new calibration... ", end="")
device.flashCalibration2(newCalib)
print("DONE!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment