qr footprint wizard: add option for error correction level

QR codes allow 4 different levels of error correction.  By increasing the level, larger numbers of data bytes can be corrupted without invalidating the code
This commit is contained in:
SubaruArai 2024-03-11 23:37:29 +00:00 committed by Seth Hillbrand
parent 3cc1617f5a
commit d7173dd6d1
1 changed files with 17 additions and 2 deletions

View File

@ -42,6 +42,14 @@ class QRCodeWizard(FootprintWizardBase.FootprintWizard):
0,
min_value=0,
)
# ErrorCorrectLevel: L = 7%, M = 15% Q = 25% H = 30%
self.AddParam(
"Barcode",
"Error Correction Level",
self.uString,
"M",
hint="One of L(7%), M(15%), Q(25%), H(30%)"
)
self.AddParam(
"Barcode",
"Type Number",
@ -63,6 +71,7 @@ class QRCodeWizard(FootprintWizardBase.FootprintWizard):
def CheckParameters(self):
self.Barcode = self.parameters['Barcode']['Contents']
self.RawECLevel = str(self.parameters['Barcode']['Error Correction Level']).upper()
self.TypeNumber = self.parameters['Barcode']['Type Number']
self.X = self.parameters['Barcode']['Qr Pixel Width']
self.negative = self.parameters['Barcode']['Negative']
@ -75,8 +84,14 @@ class QRCodeWizard(FootprintWizardBase.FootprintWizard):
self.module.Value().SetText(str(self.Barcode))
# ErrorCorrectLevel: L = 7%, M = 15% Q = 25% H = 30%
if not (len(self.RawECLevel) == 1 and self.RawECLevel in "LMQH"):
self.GetParam("Barcode", "Error Correction Level").AddError(
'"Error Correction Level" must be one of L(7%), M(15%), Q(25%), H(30%)'
)
self.ECLevel = qrcode.ErrorCorrectLevel.M
else:
self.ECLevel = getattr(qrcode.ErrorCorrectLevel, self.RawECLevel)
# Check if the content is too long
# technically we don't need this conversion (TypeNumber=0 will be