Esempio n. 1
0
 def _encode_pos(self, x, y):
     """Encode a postion into bytes."""
     return struct.pack(self._ENCODE_POS, x, y)
     del x, y
     clean_mem()
Esempio n. 2
0
def get_time():
    return (2018,06,13,15,14,15,0,135)
    clean_mem()
Esempio n. 3
0
from gc import collect as clean_mem
import gc

gc.enable()
clean_mem()
from staging import screen

clean_mem()
from tg_modules.tasking import thread_list

clean_mem()

#make the thread_list for the whole project, send to screen:
trd = thread_list()
screen.init(trd)
clean_mem()

screen.place_top_bar()
trd.chug()
clean_mem()
screen.place_top_bar()
trd.chug()
'''from staging.pin_port import i2c_port
import time

from adafruit.ds3231 import DS3231

print(gc.mem_free(),gc.mem_alloc())

ds = DS3231(i2c_port)
print(ds.datetime)'''
Esempio n. 4
0
def bat_percent():
    return (100,10,50)[random.randrange(3)]
    clean_mem()
Esempio n. 5
0
def is_charging():
    return(0,1,0)[random.randrange(3)]
    clean_mem()
Esempio n. 6
0
def text_task(x, y, str, priority=3):
    thread.add_task(disp.text, (x, y, str), priority)
    del x, y, str
    clean_mem()
Esempio n. 7
0
def rect_task(x, y, w, h, color, priority=1):
    thread.add_task(disp.rect, (x, y, w, h, color), priority)
    del x, y, w, h, color
    clean_mem()
Esempio n. 8
0
 def chug(self):
     for cur_list in self.thread_list:
         while len(cur_list):
             cur_list[0].perform()
             cur_list.pop(0)
             clean_mem()
Esempio n. 9
0
def init(thread_list):
    global thread
    thread = thread_list
    del thread_list
    clean_mem()
Esempio n. 10
0
 def __init__(self, length=3):
     self.thread_list = [[]] * (length + 1)
     clean_mem()
Esempio n. 11
0
    def text(self,
             xin,
             yin,
             text,
             color=color_white,
             background=color_black,
             size=1,
             rect_extension=0,
             italics=0):
        comp_list = []
        enter_stat = False
        if type(text) != list:
            text = (text.upper()).split('__')
        while len(text):
            try:
                comp_list.append(0)
                comp_list += self.text_dict['__' + text[0] + '__']
            except KeyError:
                while len(text[0]):  # for each section
                    #--------------------------------------------------------
                    #check for enter character
                    if (text[0][0] == '''
'''):  # this is the enter character
                        enter_stat = True
                        if (len(text) == True):
                            text[0] = text[0][1:]
                            next_text = text.copy(
                            )  #make next_text the rest of the text (list form)
                        break
                #--------------------------------------------------------
                # check if the text will spill over the side of the display
                    try:
                        next_x_end = (
                            len(comp_list) * size + xin - 1 +
                            len(self.text_dict[(text[0][0]).upper()]))
                        if (next_x_end > self.width):
                            if (len(text) == True):
                                del next_x_end
                                next_text = text.copy(
                                )  #make next_text the rest of the text (list form)
                            break
                    except KeyError:
                        pass
                #--------------------------------------------------------
                #make the comp_list additions
                    comp_list.append(0)
                    try:
                        comp_list += self.text_dict[text[0][0]]
                    except KeyError:
                        comp_list += self.text_dict["__?__"]
                    text[0] = text[0][1:]
                #--------------------------------------------------------
            if len(text):
                text.pop(0)
        clean_mem()
        width = len(comp_list) * size
        height = self.text_dict['Height'] * size
        sq_size = size**2
        global array
        array = bytearray(width * height * sq_size *
                          self.color_depth)  # 2 if for color depth
        for x_pos in range(width):  #cycle through stripes
            for y_pos in (range(height)):  # cycle through bits in stripes
                #calc 1st bit position
                pos = self._byte_coord(width, x_pos, y_pos)
                #figureout witch color
                if (comp_list[x_pos] & 2**(height - y_pos - 1)):
                    cur_color = color
                else:  # elif background:
                    cur_color = background
                #change array
                for byte_offset in (range(self.color_depth)):
                    array[pos + self.color_depth - 1 - byte_offset] = (
                        (cur_color) >> byte_offset * 8) & 255  #(0b11111111)
        #put background around
        self.rect(xin, yin, width + 1, height + 1 + rect_extension, background)
        #put text as block
        self._block(xin, yin + 1, xin - 1 + width * size + italics,
                    yin - 1 + height * size + 1, array)
        try:
            self.text(xin,
                      yin + 1 + rect_extension + 7 * size,
                      next_text,
                      color=color,
                      background=background,
                      size=size,
                      rect_extension=rect_extension,
                      italics=italics)
        except NameError:
            pass
Esempio n. 12
0
 def fill(self, color=0):
     #"""Fill the whole display with the specified color."""
     self.rect(0, 0, self.hardware_width, self.hardware_height, color)
     del color
     clean_mem()
Esempio n. 13
0
 def _decode_pixel(self, data):
     """Decode bytes into a pixel color."""
     return color565(*struct.unpack(self._DECODE_PIXEL, data))
     del data
     clean_mem()
Esempio n. 14
0
 def add_task(self,func, arg_tup, priority = 0):
     if self.thread_list[priority]:  # edit: dropped use of len(), which is less pythonic
         self.thread_list[priority].append(task(func, arg_tup))
     else:
         self.thread_list[priority] = [task(func, arg_tup)]
     clean_mem()