add variablename option

This commit is contained in:
interfisch 2024-12-03 17:21:37 +01:00
parent 7f6cfebf98
commit 05a15772d7
1 changed files with 9 additions and 2 deletions

View File

@ -10,6 +10,7 @@ parser = argparse.ArgumentParser(
parser.add_argument('filename') # positional argument
parser.add_argument('-o', '--output') # option that takes a value
parser.add_argument('-f', '--format', choices=['firmware','nodered','nodered_int'], default='firmware', help='Output format') # option that takes a value
parser.add_argument('-n', '--variablename', action='store_true') # use outputfilename as variable name (for firmats nodered and nodered_int
parser.add_argument('-v', '--verbose', action='store_true') # on/off flag
parser.add_argument('-i', '--invert', action='store_true')
parser.add_argument('-y', '--ymirror', action='store_true')
@ -27,6 +28,11 @@ pix = im.load()
print(im.size) # Get the width and hight of the image for iterating over
#print(pix[10,10]) # Get the RGBA Value of the a pixel of an image
variablename="msg.payload"
if (args.variablename):
variablename=outputfilename.split('.')[0]
print("Using variablename="+str(variablename))
output_pre=""
output_col_preL=""
output_col_writeCol_flag=False
@ -44,7 +50,8 @@ if args.format=='firmware':
output_col_write_binary_flag=True
output_col_post=";\n"
elif args.format=='nodered': #Nodered Binary
output_pre="msg.payload=\"\\\n"
#output_pre="msg.payload=\"\\\n"
output_pre=variablename+"=\"\\\n"
output_col_preL=""
output_col_writeCol_flag=False
output_col_preR=""
@ -52,7 +59,7 @@ elif args.format=='nodered': #Nodered Binary
output_col_post="\\\n"
output_post="\";\nreturn msg;"
elif args.format=='nodered_int': #Nodered Int
output_pre="msg.payload=\"\\\n"
output_pre=variablename+"=\"\\\n"
output_col_preL=""
output_col_writeCol_flag=False
output_col_preR=""