help using LCD Assistant and GIMP(Resolved)
I am trying use OLED 96X16 which uses the SSD1306 chip to display images.
So far I have been successful creating an image 96X16pic. image.
But I am not successful is to convert the image into propeller ($) binary data.
The LCD Assistant is used to convert the image Hex Data but
when I try to convert Hex Data, the conversion displays all "Hex 0" in C format.
If I get the image converted to Hex Data the I could convert Mex Data to ($) binary data.
I know this have been done before but I cannot find the way to do it. I
googled and looked in this forum but with no successful.
I hope someone will enlighten me with the details how to proceed.
Thank you,
Siri
So far I have been successful creating an image 96X16pic. image.
But I am not successful is to convert the image into propeller ($) binary data.
The LCD Assistant is used to convert the image Hex Data but
when I try to convert Hex Data, the conversion displays all "Hex 0" in C format.
If I get the image converted to Hex Data the I could convert Mex Data to ($) binary data.
I know this have been done before but I cannot find the way to do it. I
googled and looked in this forum but with no successful.
I hope someone will enlighten me with the details how to proceed.
Thank you,
Siri
Comments
It just dawned on me that a simple Python program could process the C output to Spin -- I'm going to give that a try right now.
My first issue is the LCD Assistant is all "0x00" every single data point.
I will do a global replace if I can get a true Hex output and add the byte headers manually.
I can read the 96X16 created image but unable to convert with the LCD Assistant.
Thanks
Siri
Is your image monochrome (1 bit per pixel)? Maybe the software gets confused if it is not...
From the command line enter: python lcda_convert.py tablename where tablename is the name of the input file (from LCDA) file less the '.c' extension.
#!/usr/bin/env python # Convert LCD Assistant file in C format to Spin format # -- Jon McPhalen # -- 08 MAY 2019 def process_file(table): if len(table) > 12: table = table[0:12] # truncate if too long header0 = ' ' + table + (' ' * (14-len(table))) + 'byte ' header1 = (' ' * 16) + 'byte ' try: infile = open(table+'.c', 'r') # open c file for n in range(6): # skip to data infile.readline() except: return -2 # could not open in file try: outfile = open(table+'.spin', 'w') # create spin file outfile.write('dat\n' + '\n') # insert dat section except: infile.close() return -3 # could not open out file outcount = 0 for line in infile: # loop through file if line.find('}') == -1: # if not last line line = line.replace('0x', '$') # C --> Spin notation line = line.replace(',\n', '') # clean end of line if outcount == 0: outfile.write(header0 + line + '\n') else: outfile.write(header1 + line + '\n') outcount += 1 infile.close() outfile.close() print("Processed {} lines.".format(outcount)) return 0 def main(args): if len(args) == 1: print("Table name not specified.") return -1 else: return(process_file(args[1])) if __name__ == '__main__': import sys sys.exit(main(sys.argv))
I am still new to Python programming -- if there is a better way to write this program, please let me know.
The forum doesn't allow the attachment of Python files so I appended .txt to that file -- remove this before use.
Thank you for your help.
Siri
The program works
instead of
line.find('}')
you can use'}' in line
instead off = open('..') for line in f: ... f.close()
you are encouraged to use (Reading and Writing files):with open('..') as f: for line in f: ...
the last requires some slight changes to the logic
EDIT:
This is how my process_file would end up using he hints from above:
def process_file(table): header0 = 'DAT\n\n {:12s} byte {}\n' # Use string format to align things header1 = '{:16s}byte {}\n' outcount = 0 extract = False # Extract indicator with open(table+'.c') as f: # Open file for reading with open(table+'.spin','w') as out: # Open file for writing for line in f: if '{' in line: extract = True # Start extracting elif '}' in line: extract = False # Stop extracting elif extract: # tokenize the line, stripping whitespace as we go along. # Skip empty tokens (which is end of the line) p = [x.strip().replace('0x','$') for x in line.strip().split(',') if x] if not outcount: # use the fact the '0' is treated as false in python # limit the table to 12 characters at this place only # join the line again out.write(header0.format(table[:12], ', '.join(p))) else: out.write(header1.format('', ', '.join(p))) outcount += 1 print("Processed {} lines.".format(outcount)) return 0
I got a bit different coding style than @JonnyMac and tend to merge multiple lines into one if I can get away with it
That is something I tend to avoid -- I always go for obvious. The owners of the company I work for have told us that they are working on have Guido van Rossum come to our office for a day (no date set); I am looking forward to hearing his perspective. What I don't understand is the requirement for colons after definitions and in if-elif-else constructs.
Anyway, thanks for the feedback. I will copy-and-paste snippets into idle so that I can fully understand what's happening.
block indicator, makes it easier to see when indentation is required
look here aswell: list-comprehensions
EDIT: Python style guide is almost recommended reading when you code in python.