From 05a15772d7796dbbf41617251bba8f745bccded9 Mon Sep 17 00:00:00 2001 From: Fisch Date: Tue, 3 Dec 2024 17:21:37 +0100 Subject: [PATCH] add variablename option --- imagegenerator/generate.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/imagegenerator/generate.py b/imagegenerator/generate.py index a3befd1..1b0b6c4 100644 --- a/imagegenerator/generate.py +++ b/imagegenerator/generate.py @@ -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=""