class CommonHardwarePIHD44780GPIO(object):
    """
    Class for interfacing with pi lcd HD44780
    """

    def __init__(self):
        self.lcd_inst = CharLCDGPIO(pin_rs=15, pin_rw=18, pin_e=16,
                                    pins_data=[21, 22, 23, 24],
                                    numbering_mode=GPIO.BOARD,
                                    cols=20, rows=4, dotsize=8,
                                    charmap='A02',
                                    auto_linebreaks=True)

    def com_hard_pi_hd44780_write(self, lcd_string, x_pos=None, y_pos=None):
        if x_pos is not None:
            self.lcd_inst.cursor_pos = (x_pos, y_pos)
        self.lcd_inst.write_string(lcd_string)

    def com_hard_pi_hd44780_clear(self):
        self.lcd_inst.clear()

    def com_hard_pi_hd44780_close(self, clear_screen=True):
        self.lcd_inst.close(clear=clear_screen)
import RPLCD as RPLCD
from RPLCD.gpio import CharLCD
import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)

lcd = CharLCD(numbering_mode=GPIO.BOARD,
              cols=16,
              rows=2,
              pin_rs=37,
              pin_e=35,
              pins_data=[33, 31, 29, 26])
lcd.clear()
kata = input('ketikkan karakter atau kata: ')
lcd.write_string(kata)
time.sleep(3)
GPIO.cleanup()
示例#3
0
class RaspberryPiIODiagnoser:
    def __init__(self):
        logger.debug(FUNCTION_CALL_MSG)
        GPIO.setwarnings(False)
        self.front_button_gpio = 4
        self.back_button_gpio = 3
        self.back_led_gpio = 14  # power LED
        self.bit_mode = 4
        self.pin_modes = {
            4: [33, 31, 29, 23],
            8: [40, 38, 36, 32, 33, 31, 29, 23]
        }

        self.lcd = CharLCD(numbering_mode=GPIO.BOARD,
                           cols=16,
                           rows=2,
                           pin_rs=37,
                           pin_e=35,
                           pins_data=self.pin_modes[self.bit_mode])

        self.front_button = Button(
            pin=self.front_button_gpio,
            bounce_time=0.01,
            hold_time=self.mintime,
            # hold_repeat=True
        )

        self.front_button.when_pressed = self.front_button__when_pressed
        self.front_button.when_held = self.front_button__when_held
        self.front_button.when_released = self.front_button__when_released

        self.back_button = Button(
            pin=self.back_button_gpio,
            bounce_time=0.01,
            hold_time=self.mintime,
            # hold_repeat=True
        )

        self.back_button.when_pressed = self.back_button__when_pressed
        self.back_button.when_held = self.back_button__when_held
        self.back_button.when_released = self.back_button__when_released

        self.back_led = LED(self.back_led_gpio)

        self.lcd.clear()
        self.lcd.home()
        smiley = (
            0b00000,
            0b01010,
            0b01010,
            0b00000,
            0b10001,
            0b10001,
            0b01110,
            0b00000,
        )

        self.lcd.create_char(0, smiley)

        s = chr(0)

        line1 = f"{s}{s}{s}{s}{s}{s}{s}PI{s}{s}{s}{s}{s}{s}{s}"
        line2 = f"{s}{s}{s}{s}DIAGNOSH{s}{s}{s}{s}"

        self.lcd.cursor_pos = (0, 0)
        self.lcd.write_string(line1)
        self.lcd.cursor_pos = (1, 0)
        self.lcd.write_string(line2)

    def front_button__when_pressed(self):
        logger.debug(FUNCTION_CALL_MSG)

    def front_button__when_held(self):
        logger.debug(FUNCTION_CALL_MSG)

    def front_button__when_released(self):
        logger.debug(FUNCTION_CALL_MSG)

    def back_button__when_pressed(self):
        logger.debug(FUNCTION_CALL_MSG)

    def back_button__when_held(self):
        logger.debug(FUNCTION_CALL_MSG)

    def back_button__when_released(self):
        logger.debug(FUNCTION_CALL_MSG)
示例#4
0
class Display(multiprocessing.Process):
	def __init__(self, write_queue):
		super().__init__()
		self.write_queue = write_queue

		self.strings_to_write = ['', '']
		self.changed = multiprocessing.Value(c_bool, True)

		self.lcd = CharLCD(pin_rs=18, pin_rw=None, pin_e=23, pins_data=[12, 16, 20, 21], numbering_mode=GPIO.BCM,
		                   cols=16, rows=2, auto_linebreaks=False)
		self.lock = Lock()
		self.lcd.cursor_mode = 'hide'
		self.watch_queue = Thread(target=self.update_to_write, args=(self.changed, self.lock))

	def run(self):
		self.watch_queue.start()
		top_scroll, bottom_scroll = False, False
		top_string = self.strings_to_write[0]
		bottom_string = self.strings_to_write[1]
		i, j = 0, 0

		while True:
			try:
				if self.changed.value:
					with self.lock:
						# i, j = 0, 0
						self.lcd.clear()

						if True:
						# if len(self.strings_to_write[0]) <= 16:
							top_scroll = False
							self.lcd.cursor_pos = (0, 0)
							self.lcd.write_string(self.strings_to_write[0][:16])
						# else:
						# 	top_scroll = True
						# 	top_string = self.strings_to_write[0] + '  ' + self.strings_to_write[0]
						# 	max_i = len(self.strings_to_write[0]) + 2
						# 	top_freeze_ticks = 4

						# if len(self.strings_to_write[1]) <= 16:
							bottom_scroll = False
							self.lcd.cursor_pos = (1, 0)
							self.lcd.write_string(self.strings_to_write[1][:16])

						# else:
						# 	bottom_scroll = True
						# 	bottom_string = self.strings_to_write[1] + '  ' + self.strings_to_write[1]
						# 	max_j = len(self.strings_to_write[1]) + 2
						# 	bottom_freeze_ticks = 4

						self.changed.value = False

				# if top_scroll:
				# 	self.lcd.cursor_pos = (0, 0)
				# 	self.lcd.write_string(top_string[i:i+16])
				# 	if i == 0:
				# 		if top_freeze_ticks > 0:
				# 			top_freeze_ticks -= 1
				# 		else:
				# 			top_freeze_ticks = 4
				# 			i = 1
				# 	else:
				# 		i = (i + 1) % max_i
				#
				# if bottom_scroll:
				# 	self.lcd.cursor_pos = (1, 0)
				# 	self.lcd.write_string(bottom_string[j:j+16])
				# 	if j == 0:
				# 		if bottom_freeze_ticks > 0:
				# 			bottom_freeze_ticks -= 1
				# 		else:
				# 			bottom_freeze_ticks = 4
				# 			j = 1
				# 	else:
				# 		j = (j + 1) % max_j

				sleep(0.2)
			except Exception as exception:
				print('display service exception: ', exception)

	def update_to_write(self, changed, lock):
		while True:
			try:
				msg = self.write_queue.get()
				if msg[0] != self.strings_to_write[0] or msg[1] != self.strings_to_write[1]:
					with lock:
						self.strings_to_write[0], self.strings_to_write[1] = msg[0], msg[1]
						changed.value = True

				sleep(2)
			except Exception as exception:
				print('invalid message received by display process: ', exception)
示例#5
0
def main():
    try:
        lcd = CharLCD(pin_rs=11,
                      pin_rw=13,
                      pin_e=15,
                      pins_data=[12, 16, 20, 21],
                      numbering_mode=GPIO.BCM,
                      cols=16,
                      rows=4)
        lcd.clear()
        hour = -1
        min = -1
        while True:

            #lcd.write_string('Raspberry Pi')
            now = time.localtime()
            soilMoisture = readadc(SM, CLK, DOUT, DIN, CS)
            water_time = setUpWaterTime()  # dang datetime
            right_now = datetime.now()  # dang datetime
            lcd.cursor_pos = (0, 1)
            lcd.write_string(water_time.strftime("%H:%M %d/%m"))
            lcd.cursor_pos = (1, 1)
            lcd.write_string(str(soilMoisture) + " %")
            lcd.cursor_pos = (1, 7)
            lcd.write_string("weather")
            #noWaterHours = (right_now.day*24 + right_now.hour) -(water_time.day*24 + water_time.hour)
            delta = (right_now - water_time).total_seconds()
            noWaterHours = delta // 3600

            waterPy = AutoIrrigationSystem(soilMoisture, noWaterHours)
            #print("I'm here")
            if (now.tm_hour == 12
                    or now.tm_hour == 6) and (now.tm_hour != hour):
                print("Soil moisture: ", waterPy.soilMoisture, "|",
                      "water time: ", water_time)
                print("Your garden has not been watered for",
                      waterPy.noWaterHours, "hours")
                current = currentWeather()
                forecast = forecastWeather()

                if (waterPy.soilMoisture < threshold
                        and waterPy.noWaterHours >= 24
                        and waterPy.noWaterHours < 72):
                    if waterPy.isRain(current):
                        print("It's", current["description"],
                              ". No need to water right now")
                    elif waterPy.expectedRain(forecast) != "":
                        print("Expecting", waterPy.expectedRain(forecast),
                              ". No need to water right now")
                    else:
                        waterPy.watering(current)
                        print("It's", current["description"])
                        sendMail("WaterPy", "Your plant has been watered.")
                elif waterPy.noWaterHours >= 72:
                    print(current["description"])
                    print("It's over 3 days without water. Watering...")
                    waterPy.watering(current)
                    sendMail("WaterPy", "Your plant has been watered.")
                elif (waterPy.soilMoisture < threshold
                      and waterPy.noWaterHours < 24):
                    print(
                        "Soil moisture is %.1f, under threshold but your garden has been just  watered %d hours ago"
                        % (waterPy.soilMoisture, waterPy.noWaterHours))
                elif waterPy.soilMoisture > threshold:
                    print("Soil moisture is %.1f, above threshold" %
                          waterPy.soilMoisture)
                hour = now.tm_hour
            elif (now.tm_min % 30 == 0 and now.tm_min != min):
                soilMoisture = readadc(soilMoisture, CLK, DOUT, DIN, CS)
                current = currentWeather()
                forecast = forecastWeather()
                waterPy.saveCurrentWeather(current)
                waterPy.saveSoilMoisture()
                print(
                    "weather info and soil moisture values has been inserted into database"
                )
                min = now.tm_min
            time.sleep(1)
    except KeyboardInterrupt:
        GPIO.cleanup()
        lcd.clear()
示例#6
0
                    key_lookup = u'{}'.format(
                        dictionary.scancodes.get(
                            data.scancode)) or u'UNKNOWN:[{}]'.format(
                                data.scancode)  # Lookup or return UNKNOWN:XX
                if (data.scancode != 42) and (data.scancode != 28):
                    x += key_lookup
                if (data.scancode == 28):
                    return x


# START OF FUNCTIONALITY #############################################################################
startMessage()

internetConnected = False

roundsDisplay.clear()
roundsDisplay.write_string('Connecting to   Network...')

while (not internetConnected):
    try:
        response = urllib.request.urlopen("https://google.com", timeout=1)
        internetConnected = True
    except urllib.request.URLError:
        continue

roundsDisplay.clear()
roundsDisplay.write_string('Connected to    Network!')
time.sleep(2)

timestamp = str(int(time.time()))
preHash = cfg.path + timestamp + cfg.secret
示例#7
0
class RaspberryPi(IODevice):
    def __init__(self,
                 shutdown_system=False,
                 output_rows=2,
                 output_columns=16):
        logger.debug(f"{FUNCTION_CALL_MSG}, {__class__}")
        super().__init__(shutdown_system=shutdown_system,
                         output_rows=output_rows,
                         output_columns=output_columns)
        GPIO.setwarnings(False)

        self.front_button_gpio = 4
        self.back_button_gpio = 3
        self.back_led_gpio = 14  # power LED
        self.bit_mode = 4
        self.pin_modes = {
            4: [33, 31, 29, 23],
            8: [40, 38, 36, 32, 33, 31, 29, 23]
        }

        self.lcd = CharLCD(
            numbering_mode=GPIO.BOARD,
            cols=self.output_columns,
            rows=self.output_rows,
            pin_rs=37,
            pin_e=35,
            pins_data=self.pin_modes[self.bit_mode],
        )

        self.print_cleanup_method = self.print_cleanup_method_override
        self.print_method = self.print_method_override

        smiley = (
            0b00000,
            0b01010,
            0b01010,
            0b00000,
            0b10001,
            0b10001,
            0b01110,
            0b00000,
        )
        self.lcd.create_char(0, smiley)
        self.smiley = chr(0)

        self.front_button = ButtonWrapper(pin=self.front_button_gpio,
                                          bounce_time=0.01,
                                          hold_time=1,
                                          hold_repeat=True)

        self.front_button.when_pressed = self.front_button__when_pressed
        self.front_button.when_held = self.front_button__when_held
        self.front_button.when_released = self.front_button__when_released

        self.back_button = ButtonWrapper(pin=self.back_button_gpio,
                                         bounce_time=0.01,
                                         hold_time=1,
                                         hold_repeat=True)

        self.back_button.when_pressed = self.back_button__when_pressed
        self.back_button.when_held = self.back_button__when_held
        self.back_button.when_released = self.back_button__when_released

        self.back_led = LED(self.back_led_gpio)

        self.startup_method = self.set_startup_method

    def print_cleanup_method_override(self):
        logger.debug(FUNCTION_CALL_MSG)
        self.lock.acquire()
        self.lcd.home()
        self.lcd.clear()
        self.lock.release()

    def print_method_override(self, framebuffer):
        for row in framebuffer:
            try:
                self.lcd.write_string(row)
                self.lcd.crlf()
            except Exception as e:
                print("Something went wrong:")
                print(e)
                return

    def shutdown(self):
        logger.debug(FUNCTION_CALL_MSG)
        if self.shutdown_system:
            logger.debug("Shutting down system")
            self.back_led.on()
            os.system("sudo poweroff")
        else:
            raise NotImplementedError
            # logger.debug("Shutting down Pi process")
            # This throws some gpiozero related error on exit, but oh well
            # os.kill(self.pid, signal.SIGUSR1)

    # TODO: Keeping this around for the blinking logic that I need to reimplement
    # def shutdown_old(self, hold_time=6):
    #     logger.debug(FUNCTION_CALL_MSG)
    #     # find how long the button has been held
    #     p = self.back_button.pressed_time
    #     logger.debug(f"Held for {p} seconds")
    #     # blink rate will increase the longer we hold
    #     # the button down. E.g., at 2 seconds, use 1/4 second rate.
    #     self.back_led.blink(on_time=0.5 / p, off_time=0.5 / p)
    #     if p > hold_time:
    #         # Depending on system, either shutdown
    #         # whole system, or just the object process
    #         if self.shutdown_system:
    #             logger.debug("Shutting down system")
    #             self.back_led.on()
    #             os.system("sudo poweroff")
    #         else:
    #             raise NotImplementedError
    #             # logger.debug("Shutting down Pi process")
    #             # # This throws some gpiozero related error on exit, but oh well
    #             # os.kill(self.pid, signal.SIGUSR1)

    def default_splash_screen(self):
        lines = [
            f"{self.smiley*3}RASPBERRY{self.smiley*4}",
            f"{self.smiley*7}PI{self.smiley*7}"
        ]
        self.stream_lines(lines)

    def default_startup_text(self):
        startup_steps_lines = [['Loading', '.'], ['Loading', '..'],
                               ['Loading', '...']]
        self.stream_multiples_of_lines(startup_steps_lines)

    # TODO: Rename this
    def set_startup_method(self):
        self.default_startup_text()
        self.default_splash_screen()

    def front_button__when_pressed(self):
        logger.debug(FUNCTION_CALL_MSG)

    def front_button__when_held(self):
        logger.debug(FUNCTION_CALL_MSG)

    def front_button__when_released(self):
        logger.debug(FUNCTION_CALL_MSG)

    def back_button__when_pressed(self):
        logger.debug(FUNCTION_CALL_MSG)

    def back_button__when_held(self):
        logger.debug(FUNCTION_CALL_MSG)

    def back_button__when_released(self):
        logger.debug(FUNCTION_CALL_MSG)
        self.back_led.off()

    def run(self):
        self.print_cleanup_method()
        self.startup_method()
        super().run()
class RpiInterface:
    def __init__(self, music_logic):
        self.music_logic = music_logic

    def draw_screen(self):
        self.clear_screen()
        self.write_to_screen(self.music_logic.get_current_bank().name, line=0)
        self.write_to_screen(f"RS: {self.music_logic.repeat_style.name}",
                             line=1)

    def draw_screen_async(self):
        p = Process(target=self.draw_screen)
        p.start()

    def write_to_screen(self, text, line=None):
        written_characters = 0
        total_available_characters = 0

        if line in range(SCREEN_ROWS):
            total_available_characters = SCREEN_COLUMNS
            self._lcd.cursor_pos = (line, 0)
        elif line is None:
            total_available_characters = SCREEN_COLUMNS * SCREEN_ROWS
            self._lcd.home()
        else:
            raise AttributeError(
                f"line must be between 0 and {SCREEN_COLUMNS}")

        trimmed_text = text[:total_available_characters]
        self._lcd.write_string(trimmed_text)

    def clear_screen(self):
        self._lcd.clear()

    def start(self):
        os.putenv('SDL_VIDEODRIVER', 'fbcon')
        pygame.display.init()

        GPIO.setmode(GPIO.BCM)
        self._lcd = CharLCD(pin_rs=17,
                            pin_e=27,
                            pins_data=[22, 10, 9, 11],
                            numbering_mode=GPIO.BCM,
                            cols=SCREEN_COLUMNS,
                            rows=SCREEN_ROWS)
        self._lcd.clear()
        self._lcd.write_string('Welcome to\r\nSoundFloored')
        time.sleep(1)
        self.draw_screen_async()

        control_button_1_pin = 2
        control_button_2_pin = 26

        GPIO.setup(control_button_1_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.add_event_detect(
            control_button_1_pin,
            GPIO.FALLING,
            callback=lambda channel: self.music_logic.decrement_bank(),
            bouncetime=200)
        GPIO.setup(control_button_2_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.add_event_detect(
            control_button_2_pin,
            GPIO.FALLING,
            callback=lambda channel: self.music_logic.increment_bank(),
            bouncetime=200)

        audio_clip_button_pins = [14, 15, 20, 21]

        # Used to discard the channel value that is automatically provided by
        # add_event_detect to the callback function
        callback_wrapper = lambda index, channel: self.music_logic.play_clip(
            index)

        for index, audio_clip_button_pin in enumerate(audio_clip_button_pins):
            GPIO.setup(audio_clip_button_pin,
                       GPIO.IN,
                       pull_up_down=GPIO.PUD_UP)
            GPIO.add_event_detect(audio_clip_button_pin,
                                  GPIO.FALLING,
                                  callback=partial(callback_wrapper, index),
                                  bouncetime=200)

        self.music_logic.after_state_change_functions.append(
            self.draw_screen_async)
        try:
            while True:
                for index, audio_clip_button_pin in enumerate(
                        audio_clip_button_pins):
                    if GPIO.input(audio_clip_button_pin
                                  ) == INPUT_VALUE_WHEN_BUTTON_PRESSED:
                        # Sleep for just long enough to give the event detector a chance to
                        # execute the callback, rather than stacking multiple calls
                        # to play_clip at the same time
                        time.sleep(0.01)
                        self.music_logic.play_clip(index,
                                                   is_distinct_trigger=False)
        except KeyboardInterrupt:
            pass
        finally:
            self._lcd.close(clear=True)
            GPIO.cleanup()
示例#9
0
	thread = threading.Thread(target=listener.output)
	thread.daemon = True
	listener.connect()
	thread.start()
	listener.run_forever()

'''
Only start the client if its called as standalone and not loaded as a module.
Parse arguments for host, port or use the defaults
'''
if __name__ == '__main__':
	try:
		parser = argparse.ArgumentParser()
		parser.add_argument('-c', '--console', metavar='console', default=False, type=bool, help='If the data should be outputted to console instead')
		parser.add_argument('-n', '--host', metavar='HOST', default='127.0.0.1', help='the host to connect to')
		parser.add_argument('-p', '--port', help='the port to connect to', default=9000, type=int)
		args = parser.parse_args()

		lcd = None
		if using_rpi and not args.console:
			lcd = CharLCD(pin_rs=26, pin_rw=7, pin_e=19, pins_data=[13, 6, 5, 11], numbering_mode=GPIO.BCM, cols=CHARACTERS_PER_LINE, rows=2)
		else:
			lcd = ConsoleLCD()

		lcd.clear()
		client_init(lcd, args.host, args.port)
	finally:
		lcd.clear()
		if using_rpi:
			GPIO.cleanup()
示例#10
0
class LCD_SYS_1:
    def __init__(self):
        
        if gv.SYSTEM_MODE == 1 and (gv.USE_HD44780_16x2_LCD or gv.USE_HD44780_20x4_LCD or gv.USE_I2C_16X2DISPLAY):

            # Timing constants
            self.E_PULSE = 0.0005
            self.E_DELAY = 0.0005

            self.display_called = False
            self.temp_display = False

            if gv.IS_DEBIAN:
                self.thread_sleep = 0.05
            else:
                self.thread_sleep = 0.1

            self.timeout_init = 2  # default timeout reset time
            self.timeout_length = self.timeout_init  # initial timeout length (timeout_custom will override)

            self.STRING_1 = ''
            self.STRING_2 = ''
            self.STRING_3 = ''
            self.STRING_4 = ''
            self.STRING_1_PRIORITY = ''
            self.STRING_2_PRIORITY = ''
            self.STRING_3_PRIORITY = ''
            self.STRING_4_PRIORITY = ''

            self.loop_alive = True

            if gv.IS_DEBIAN:
                import RPi.GPIO as GPIO
                import RPLCD

                if (gv.USE_HD44780_16x2_LCD or gv.USE_HD44780_20x4_LCD):
                    from RPLCD.gpio import CharLCD
                    self.lcd = CharLCD(pin_rs=gv.GPIO_LCD_RS, pin_rw=None, pin_e=gv.GPIO_LCD_E,
                                       pins_data=[gv.GPIO_LCD_D4, gv.GPIO_LCD_D5, gv.GPIO_LCD_D6, gv.GPIO_LCD_D7],
                                       numbering_mode=GPIO.BCM, cols=gv.LCD_COLS, rows=gv.LCD_ROWS, charmap='A00')
                
                elif (gv.USE_I2C_16X2DISPLAY):
                    from RPLCD.i2c import CharLCD
#                    print 'Addr: ' + str(gv.I2C_16x2DISPLAY_ADDR)
#                    self.lcd = CharLCD('PCF8574', gv.I2C_16x2DISPLAY_ADDR)
                    self.lcd = CharLCD(i2c_expander='PCF8574', address=gv.I2C_16x2DISPLAY_ADDR, port=1,
                                       cols=16, rows=2, dotsize=8,
                                       charmap='A00',
                                       auto_linebreaks=True,
                                       backlight_enabled=True)
#                    self.lcd.write_string('Hello world')

                self.lcd.clear()

                # Hide the cursor
#                self.lcd._set_cursor_mode(CursorMode.hide)
                self.lcd.cursor_mode = 'hide'

                # Fill the display with blank spaces
                for i in xrange(1, gv.LCD_ROWS+1):
                    self.lcd_string(' ', i)

                # Write custom codes to the LCD
                self.lcd.create_char(1, lcdcc.block)
                self.lcd.create_char(2, lcdcc.pause)
                self.lcd.create_char(3, lcdcc.voice_button_on)
                self.lcd.create_char(4, lcdcc.voice_button_off)
                self.lcd.create_char(5, lcdcc.block2)
                self.lcd.create_char(6, lcdcc.loading_1)
                self.lcd.create_char(7, lcdcc.loading_2)
                self.lcd.create_char(0, lcdcc.loading_3)

        self.LCDThread = threading.Thread(target=self.lcd_main)
        self.LCDThread.daemon = True
        self.LCDThread.start()

    def reset_after_timeout(self):
        self.display_called = False
        self.temp_display = False
        self.timeout_start = time.time()

    def lcd_main(self):

        if gv.USE_HD44780_20x4_LCD and gv.IS_DEBIAN:
            self.lcd.clear()

        # if gv.USE_HD44780_16x2_LCD:
        #     self.lcd_string("WELCOME TO".center(gv.LCD_COLS, ' '), 1)
        #     self.lcd_string("SAMPLERBOX".center(gv.LCD_COLS, ' '), 2)
        # elif gv.USE_HD44780_20x4_LCD:
        #     self.lcd_string(unichr(1) * gv.LCD_COLS, 1)
        #     self.lcd_string("WELCOME TO".center(gv.LCD_COLS, ' '), 2)
        #     self.lcd_string("SAMPLERBOX".center(gv.LCD_COLS, ' '), 3)
        #     self.lcd_string(unichr(1) * gv.LCD_COLS, 4)
        # time.sleep(0.6)

        self.timeout_start = time.time()
        print_message = ''

        while self.loop_alive:
            if self.display_called:

                now = time.time()

                if (now - self.timeout_start) > self.timeout_length:
                    self.reset_after_timeout()

                if (self.temp_display or gv.displayer.menu_mode == gv.displayer.DISP_UTILS_MODE):
                    self.lcd_string(self.STRING_1, 1)
                    self.lcd_string(self.STRING_2, 2)
                    print_message = "\r%s||%s" % (self.STRING_1[:gv.LCD_COLS], self.STRING_2[:gv.LCD_COLS])
                    if gv.USE_HD44780_20x4_LCD:
                        self.lcd_string(self.STRING_3, 3)
                        self.lcd_string(self.STRING_4, 4)
                        print_message = "\r%s||%s||%s" % (print_message, self.STRING_3[:gv.LCD_COLS], self.STRING_4[:gv.LCD_COLS])

                elif gv.displayer.menu_mode == gv.displayer.DISP_PRESET_MODE:
                    self.lcd_string(self.STRING_1_PRIORITY, 1)
                    self.lcd_string(self.STRING_2_PRIORITY, 2)
                    print_message = "\r%s||%s" % (self.STRING_1_PRIORITY[:gv.LCD_COLS], self.STRING_2_PRIORITY[:gv.LCD_COLS])
                    if gv.USE_HD44780_20x4_LCD:
                        self.lcd_string(self.STRING_3_PRIORITY, 3)
                        self.lcd_string(self.STRING_4_PRIORITY, 4)
                        print_message = "\r%s||%s||%s" % (print_message, self.STRING_3_PRIORITY[:gv.LCD_COLS], self.STRING_4_PRIORITY[:gv.LCD_COLS])
                elif gv.displayer.menu_mode == gv.displayer.DISP_MENU_MODE:
                    self.lcd_string(self.STRING_1_PRIORITY, 1)
                    self.lcd_string(self.STRING_2_PRIORITY, 2)
                    print_message = "\r%s||%s" % (self.STRING_1_PRIORITY[:gv.LCD_COLS], self.STRING_2_PRIORITY[:gv.LCD_COLS])
                    if gv.USE_HD44780_20x4_LCD:
                        self.lcd_string(self.STRING_3_PRIORITY, 3)
                        self.lcd_string(self.STRING_4_PRIORITY, 4)
                        print_message = "\r%s||%s||%s" % (print_message, self.STRING_3_PRIORITY[:gv.LCD_COLS], self.STRING_4_PRIORITY[:gv.LCD_COLS])
                if gv.PRINT_LCD_MESSAGES:
                    sys.stdout.write(print_message)
                    sys.stdout.flush()
                    gui_message = print_message.replace('\r', '')
                    gui_message = gui_message.replace('||', '\r')
                    if gv.USE_GUI and not gv.IS_DEBIAN: gv.gui.output['text'] = gui_message

            time.sleep(self.thread_sleep)

    def lcd_string(self, message, line):

        message = message[:gv.LCD_COLS]
        message = message.ljust(gv.LCD_COLS, " ")

        if (gv.USE_HD44780_16x2_LCD or gv.USE_HD44780_20x4_LCD or gv.USE_I2C_16X2DISPLAY) and gv.IS_DEBIAN:

            self.lcd.write_string(message[:gv.LCD_COLS])

    def display(self, message, line=1, is_priority=False, timeout_custom=None):

        message += ' ' * gv.LCD_COLS

        # Send string to display

        if line == 1:
            self.STRING_1 = message
            if is_priority:
                self.STRING_1_PRIORITY = message
            else:
                self.temp_display = True
        if line == 2:
            self.STRING_2 = message
            if is_priority:
                self.STRING_2_PRIORITY = message
            else:
                self.temp_display = True
        if line == 3:
            self.STRING_3 = message
            if is_priority:
                self.STRING_3_PRIORITY = message
            else:
                self.temp_display = True
        if line == 4:
            self.STRING_4 = message
            if is_priority:
                self.STRING_4_PRIORITY = message
            else:
                self.temp_display = True

        if timeout_custom != None:
            self.timeout_length = timeout_custom
        else:
            self.timeout_length = self.timeout_init

        self.timeout_start = time.time()

        self.display_called = True

    def stop(self):
        self.lcd.close()
        self.loop_alive = False