max7219_8digit icon indicating copy to clipboard operation
max7219_8digit copied to clipboard

[Patch] write_to_buffer and write_to_buffer_with_dots (un-reverse order)

Open GM-Script-Writer-62850 opened this issue 7 months ago • 1 comments

EDIT: i made a fork of this and made a bunch of improvements if you want to make any changes based on it


Existing version prints in the reverse order based on the pin out for the MAX7219 datasheet Changes:

  • Print text in the correct order
  • Clean up the code for better performance
  • Starting string with . works as expected (treated as .)
    • .1.2.3.4.5.6.7. works as expected
  • Using .. is a bad idea, could be fixed, but is there a use case?
  • Probably could add support for daisy chained (yes you can do that, look up the DOUT pin on the MAX7219)
    def write_to_buffer(self, s):
        l = len(s)
        if l < 8:
            s = "%-8s" % s
        for i in range(0,8):
            self.buffer[i] = self.decode_char(s[i])
        
    def write_to_buffer_with_dots(self, s):
      i = len(s)
      x=7

      while i > 0:
        i -= 1
        if i > 0 and s[i] == '.':
          i -= 1
          self.buffer[x] = self.decode_char(s[i]) | 0x80
        else:
          self.buffer[x] = self.decode_char(s[i])
        x -= 1

      while x > -1:
        self.buffer[x] = 0x00 #self.decode_char(' ')
        x -= 1

GM-Script-Writer-62850 avatar Jul 01 '24 05:07 GM-Script-Writer-62850