Shop OBEX P1 Docs P2 Docs Learn Events
help using LCD Assistant and GIMP(Resolved) — Parallax Forums

help using LCD Assistant and GIMP(Resolved)

msiriwardenamsiriwardena Posts: 301
edited 2019-05-10 12:49 in Propeller 1
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

Comments

  • JonnyMacJonnyMac Posts: 8,918
    edited 2019-05-08 23:00
    I tend to do a global replace of "0x" with "$" and manually add in the "byte" headers at the beginning of each line.

    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.
  • @ JonnyMac

    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
  • RaymanRayman Posts: 13,851
    edited 2019-05-09 00:10
    LCD Assistant appears to be for monochrome images only...
    Is your image monochrome (1 bit per pixel)? Maybe the software gets confused if it is not...
  • JonnyMacJonnyMac Posts: 8,918
    edited 2019-05-09 12:55
    Here's a little Python (3) program that processes a file, converting it from C to Spin. I have included all my files for you to see in input and output. As Ray points out, this is for monochrome files and displays. Make sure that your bitmap file is 2 colors only (see my example).

    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.
  • @JonnyMac,@Rayman

    Thank you for your help.

    Siri
  • rosco_pcrosco_pc Posts: 449
    edited 2019-05-11 07:01
    JonnyMac wrote: »
    I am still new to Python programming -- if there is a better way to write this program, please let me know.

    The program works :). There are a few things that can make it more 'pythonic':
    instead of
    line.find('}')
    
    you can use
    '}' in line
    
    instead of
    f = 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 :) : the line p = [...] seems like magic but is using list comprehension to get stuff done, it is basically the same as a for loop)
  • The program works :). There are a few things that can make it more 'pythonic'
    I do try to test everything before posting. And as I will be using LCDA in the next couple weeks, this seemed like an opportune time to write a utility that I could use.
    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.
  • rosco_pcrosco_pc Posts: 449
    edited 2019-05-11 18:13
    JonnyMac wrote: »
    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.
    I envy you
    What I don't understand is the requirement for colons after definitions and in if-elif-else constructs.
    block indicator, makes it easier to see when indentation is required
    Anyway, thanks for the feedback. I will copy-and-paste snippets into idle so that I can fully understand what's happening.
    look here aswell: list-comprehensions

    EDIT: Python style guide is almost recommended reading when you code in python.
Sign In or Register to comment.