def getfortune():
    #Initiates necessary printer functions
    uart = serial.Serial(
        "/dev/USB0", baudrate=9600, timeout=3000
    )  #Modified the parameters for Adafruit's USB thermal printer - usually /dev/usb0
    ThermalPrinter = adafruit_thermal_printer.get_printer_class(2.69)
    printer = ThermalPrinter(
        uart,
        auto_warm_up=False)  #Defining comm protocol, deactivating auto warmup
    printer.warm_up()  #Warming up the printer

    #Edit the text below to adjust the receipt design
    printer.feed(2)  #Blank line
    printer.underline = adafruit_thermal_printer.UNDERLINE_THIN  #Add a thin underline
    printer.justify = adafruit_thermal_printer.JUSTIFY_CENTER  #Center the text
    printer.print(' *.. Quote 2 Go ..* ')  #We got a title!
    printer.feed(2)  #Blank line
    printer.underline = None  #Removes underline
    printer.justify = adafruit_thermal_printer.JUSTIFY_LEFT  #Left alight text
    printer.print(
        random.choice(fortunes))  #Second line of text will be a random fortune
    printer.feed(2)  #Blank line
    printer.feed(2)  #Blank line
    #os.system("lpr -P zj-58 file_name.txt") #Testing printing out a picture through the OS command line via Python. Thank you os module!
    print(
        "Button was pushed!")  #Tell the world that the button has been pushed!
Esempio n. 2
0
def today(lpt=None, speak=False):
    creds = config.get_creds_file('credentials.json')
    date = datetime.date.today()
    forecast = wx.forecast(creds)
    events_today = cal.get_events(date)
    events_tomorrow = cal.get_events(date + datetime.timedelta(days=1))
    todos = todo.get_todo_list(creds)

    if lpt:
        printer_text = today_for_printing(date, forecast, events_today,
                                          events_tomorrow, todos)
        if lpt == 'stdout':
            print(printer_text)
        else:
            uart = serial.Serial(port=lpt, baudrate=19200, timeout=3000)
            lpr = adafruit_thermal_printer.get_printer_class(2.68)(uart)
            lpr.print(printer_text)
            lpr.feed(2)

    if speak:
        speech.init()
        script = today_for_speaking(date, forecast, events_today,
                                    events_tomorrow, todos)
        speech.ENGINE.say(script)
        speech.ENGINE.runAndWait()
Esempio n. 3
0
def get_printer():
    # TODO: print a test page & verify printer class & bandrate
    ThermalPrinter = adafruit_thermal_printer.get_printer_class(2.69)
    uart = busio.UART(TX, RX, baudrate=19200)

    printer = ThermalPrinter(uart, auto_warm_up=False)
    printer.warm_up()

    printer.upside_down = True
    printer.size = adafruit_thermal_printer.SIZE_SMALL
    printer.justify = adafruit_thermal_printer.JUSTIFY_LEFT

    return printer
Esempio n. 4
0
def setup():
    global uart
    global ThermalPrinter
    global printer
    global prototxt
    global model
    global confidence_voulue
    global CLASSES
    global COLORS
    global net
    global vs

    # Configuration GPIO
    GPIO.setmode(GPIO.BOARD)
    GPIO.setwarnings(False)

    # Allumage LED
    GPIO.setup(40, GPIO.OUT)
    GPIO.output(40, GPIO.HIGH)
    GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP)

    # Configuration de l'imprimante
    uart = serial.Serial("/dev/serial0", baudrate=9600, timeout=3000)
    ThermalPrinter = adafruit_thermal_printer.get_printer_class(1.11)
    printer = ThermalPrinter(uart)

    # Fichiers d'apprentissage
    prototxt = "/home/pi/Documents/reconnaissance_objets/MobileNetSSD_deploy.prototxt.txt"
    model = "/home/pi/Documents/reconnaissance_objets/MobileNetSSD_deploy.caffemodel"
    confidence_voulue = 0.5

    # Initialisation de la liste des objets entrainés par MobileNet SSD
    CLASSES = [
        "arriere-plan", "avion", "velo", "oiseau", "bateau", "bouteille",
        "autobus", "voiture", "chat", "chaise", "vache", "table", "chien",
        "cheval", "moto", "personne", "plante en pot", "mouton", "sofa",
        "train", "moniteur"
    ]

    # Création du contour de détection avec une couleur attribuée au hasard pour chaque objet
    COLORS = np.random.uniform(0, 255, size=(len(CLASSES), 3))

    # Chargement des fichiers depuis le répertoire de stockage
    print("Chargement du modèle...")
    net = cv2.dnn.readNetFromCaffe(prototxt, model)

    # Initialisation de la caméra, attendre 0.5s pour la mise au point
    print("Démarrage de la PiCamera...")
    vs = VideoStream(usePiCamera=True, resolution=(1024, 768)).start()
    time.sleep(1)
 def __init__(self,url,title,reponame) :
      ThermalPrinter = adafruit_thermal_printer.get_printer_class(2.69)
      uart = serial.Serial("/dev/ttyS0", baudrate=19200, timeout=3000)
      self._printer = ThermalPrinter(uart)
      self._printer.warm_up()
      shortener = Shortener(tokens=tokens_pool, max_cache_size=8192)
      urls = [url]
      self._urlshort = shortener.shorten_urls(urls)
      self._last = url.rfind('/')
      self._n_issue = url[self._last+1:len(url)]
      qrcode_image = qrcode.make(self._urlshort[0])
      self._qrcode_logo = '/home/pi/qrcode.png'
      qrcode_image.save(self._qrcode_logo)
      self._title = title
      self._repository = reponame
Esempio n. 6
0
    def enable(self):
        # Use virtual to test iot functionality on computers without busio / sensors.
        if not self.island.virtual:
            import board
            import busio
            import adafruit_thermal_printer
            import datetime
            import serial

            # Pick which version thermal printer class to use depending on the version of
            # your printer.  Hold the button on the printer as it's powered on and it will
            # print a test page that displays the firmware version, like 2.64, 2.68, etc.
            # Use this version in the get_printer_class function below.
            ThermalPrinter = adafruit_thermal_printer.get_printer_class(2.16)

            # Define RX and TX pins for the board's serial port connected to the printer.
            # Only the TX pin needs to be configued, and note to take care NOT to connect
            # the RX pin if your board doesn't support 5V inputs.  If RX is left unconnected
            # the only loss in functionality is checking if the printer has paper--all other
            # functions of the printer will work.
            RX = board.RX
            TX = board.TX

            uart = serial.Serial("/dev/ttyS0", baudrate=19200, timeout=3000)
            self.printer = ThermalPrinter(uart)

            # Initialize the printer.  Note this will take a few seconds for the printer
            # to warm up and be ready to accept commands (hence calling it explicitly vs.
            # automatically in the initializer with the default auto_warm_up=True).
            print("Warming up")

            self.printer.warm_up()
            print("Warmed up")

            # Check if the printer has paper.  This only works if the RX line is connected
            # on your board (but BE CAREFUL as mentioned above this RX line is 5V!)
            # NOTE: THIS DOES NOT WORK
            # if printer.has_paper():
            # print("Printer has paper!")
            # else:
            # print("Printer might be out of paper, or RX is disconnected!")

            # TODO: Format links as QR codes
            # https://pypi.org/project/qrcode/

        self.island.iot.subscribe(topic="commands/printer",
                                  qos=mqtt.QoS.AT_LEAST_ONCE,
                                  callback=self.handle_print_request)
Esempio n. 7
0
def print_code(code, printer_port):
    qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_H)
    qr.add_data(code)

    qrdata = _2d_bitarray_to_array_of_bytes(qr.get_matrix(), scale=3)

    uart = serial.Serial(printer_port, 19200)

    ThermalPrinter = adafruit_thermal_printer.get_printer_class(3)
    printer = ThermalPrinter(uart, auto_warm_up=False)

    print_array_of_bytes(uart, side_by_side(
        qrdata, center_bitmap_height(string_characters(code), len(qrdata))))

    printer.feed(2)
    uart.close()
Esempio n. 8
0
def printOutFinalBill():
    ThermalPrinter = adafruit_thermal_printer.get_printer_class(2.67)
    uart = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=3000)
    printer = ThermalPrinter(uart)
    printer.warm_up()

    printer.size = adafruit_thermal_printer.SIZE_LARGE
    printer.justify = adafruit_thermal_printer.JUSTIFY_CENTER
    printer.underline = adafruit_thermal_printer.UNDERLINE_THICK

    printer.print('Garam Market!')

    printer.underline = None
    printer.size = adafruit_thermal_printer.SIZE_SMALL
    printer.justify = adafruit_thermal_printer.JUSTIFY_CENTER
    printer.underline = adafruit_thermal_printer.UNDERLINE_THICK
    printer.print('9700 Gilman Dr')
    printer.print('La Jolla, CA, 92093')

    printer.feed(2)

    printer.print(' Product       Price    Quantity')
    printer.feed(1)
    # printer.underline = adafruit_thermal_printer.UNDERLINE_THICK
    printer.print('-------------------------------')
    printer.justify = adafruit_thermal_printer.JUSTIFY_CENTER
    printer.print(bill.toString())
    printer.print('-------------------------------')

    printer.bold = True
    printer.justify = adafruit_thermal_printer.JUSTIFY_CENTER
    printer.print('Total: ')
    printer.bold = False

    printer.justify = adafruit_thermal_printer.JUSTIFY_RIGHT
    printer.print(str(round(bill.trxTotal(), 2)) + " TRX")

    printer.feed(2)
    script = ["python2.7", "src/PrintQRCode.py", user.address]
    process = subprocess.Popen(" ".join(script),
                               shell=True,
                               env={"PYTHONPATH": "."})
Esempio n. 9
0
    def print_address_privkey(self, address, privkey, print_privkey=True):

        # Intialize the printer
        uart = busio.UART(board.TX, board.RX, baudrate=19200)
        ThermalPrinter = adafruit_thermal_printer.get_printer_class(2.69)
        printer = ThermalPrinter(uart)

        printer.bold = True

        # Warm up and wait so we get the best print quality
        printer.warm_up()
        time.sleep(2)

        # Print the address information
        printer.feed(3)
        printer.print("Address:")
        printer.print(address)

        if print_privkey:
            printer.feed(3)
            printer.print("Private Key (WIF):")
            printer.print(privkey)

        printer.feed(3)
Esempio n. 10
0
import serial
import adafruit_thermal_printer
import RPi.GPIO as GPIO
import time
import random

#--------------------SETUP------------------------
#Set values for button
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)

#Initialize hardware serial connection to the printer
uart = serial.Serial("../../../dev/serial0", baudrate=19200, timeout=3000)

#Create Thermal Printer Class
ThermalPrinter = adafruit_thermal_printer.get_printer_class(2.68)
printer = ThermalPrinter(uart)

#-------------------------------------------------

while True:
    input_state = GPIO.input(18)
    if input_state == False:
        n = 0
        n = random.randint(1, 12)
        print('Button Pressed')
        print(n)
        time.sleep(0.4)

        if n == 1:
            printer.feed(2)