Esempio n. 1
0
 def __init__(self):
     self.lcd = Adafruit_CharLCDPlate()
     self.lcd.begin(16, 2)
     sleep(0.5)
     self.colors = (('red', self.lcd.RED), ('yellow', self.lcd.YELLOW),
                    ('green', self.lcd.GREEN), ('teal', self.lcd.TEAL),
                    ('blue', self.lcd.BLUE), ('violet', self.lcd.VIOLET),
                    ('off', self.lcd.OFF), ('on', self.lcd.ON))
     self.buttons = ((self.lcd.SELECT, 'Select'), (self.lcd.LEFT, 'Left'),
                     (self.lcd.UP, 'Up'), (self.lcd.DOWN, 'Down'),
                     (self.lcd.RIGHT, 'Right'))
     self.lcd.backlight(self.lcd.BLUE)
     self.color = self.lcd.BLUE
     self.lcd.clear()
Esempio n. 2
0
 def __init__(self):
     self.lcd = Adafruit_CharLCDPlate()
     self.lcd.begin(16, 2)
     sleep(0.5)
     self.colors = (
         ("red", self.lcd.RED),
         ("yellow", self.lcd.YELLOW),
         ("green", self.lcd.GREEN),
         ("teal", self.lcd.TEAL),
         ("blue", self.lcd.BLUE),
         ("violet", self.lcd.VIOLET),
         ("off", self.lcd.OFF),
         ("on", self.lcd.ON),
     )
     self.buttons = (
         (self.lcd.SELECT, "Select"),
         (self.lcd.LEFT, "Left"),
         (self.lcd.UP, "Up"),
         (self.lcd.DOWN, "Down"),
         (self.lcd.RIGHT, "Right"),
     )
     self.lcd.backlight(self.lcd.BLUE)
     self.color = self.lcd.BLUE
     self.lcd.clear()
Esempio n. 3
0
class MachineLogic:

    rfid = 0
    grams = 0
    charge = 0
    balance = 0

    lcd = Adafruit_CharLCDPlate.Adafruit_CharLCDPlate()
    prev = -1
    btn = ((lcd.SELECT, 'Select'), (lcd.LEFT, 'Left'), (lcd.UP, 'Up'),
           (lcd.DOWN, 'Down'), (lcd.RIGHT, 'Right'))
    authService = None
    lastpush = datetime.datetime.now()

    #set up the hardware
    def Setup(self, authService):
        self.authService = authService
        io.setmode(io.BCM)
        self.lcd.begin(16, 2)
        self.LCDRefresh = True
        self.currentstate = "IDLE"
        self.lcd.backlight(0)

    #unauthorized work involves the things before the RFID is swiped. That means using the buttons to adjust the weight.
    #if the buttons haven't been pressed for 30 seconds, we assume the user abandoned the job and we reset
    def DoUnAuthorizedContinuousWork(self):
        self.CheckButton()
        self.UpdateLCD()
        timelapse = (datetime.datetime.now() - self.lastpush)
        self.lcd.backlight2(1)
        if (timelapse.seconds > 30):
            self.grams = 0
            self.lcd.backlight2(0)
            self.LCDRefresh = True
            self.currentstate = "IDLE"
            self.lastpush = datetime.datetime.now() + datetime.timedelta(
                days=10)

    #after the user swipes and the use of the machine is authorized, we charge the user and thank them
    def DoAuthorizedWork(self, rfid):
        self.rfid = rfid
        user = self.authService.GetUserByRFID(self.rfid)
        self.fullname = user["message"]["display_name"]
        results = self.authService.AddMachinePayment(int(self.rfid),
                                                     self.grams)
        self.charge = results["message"]["charge"]
        self.balance = results["message"]["balance"]
        self.currentstate = "PAYMENT"
        self.LCDRefresh = True

    #basically a state machine for the UI.
    def UpdateLCD(self):
        if self.LCDRefresh == True:
            if self.grams > 0:
                self.lcd.clear()
                self.lcd.message("grams:" + "{0}".format(self.grams))
            if self.currentstate == "PAYMENT":
                self.lcd.clear()
                self.lcd.message("  Thank You   \n" + self.fullname)
                self.grams = 0
                self.lastpush = datetime.datetime.now() + datetime.timedelta(
                    days=10)
                time.sleep(2)
                self.lcd.clear()
                self.lcd.message("Charged:" + "{0}".format(self.charge) +
                                 "\nBalance:" +
                                 "{0}".format(round(self.balance, 2)))
                time.sleep(5)
                self.LCDRefresh = True
                self.currentstate = "IDLE"
                self.lcd.clear()
                self.lcd.message(" Push Up/Down \nTo Set Weight ")
            elif self.currentstate == "ON":
                self.lcd.clear()
                self.lcd.message("  Please Swipe  \n    RFID Tag   ")
            elif self.currentstate == "IDLE":
                self.lcd.clear()
                self.lcd.message(" Push Up/Down \nTo Set Weight ")
            elif self.currentstate == "UNAUTHORIZED":
                self.lcd.clear()
                self.lcd.message("  Unauthorized \n   RFID Tag  ")
                self.LCDRefresh = True
                self.currentstate = "ON"
                self.lastpush = datetime.datetime.now() + datetime.timedelta(
                    days=10)
                time.sleep(10)
                self.lcd.clear()
                self.lcd.message("grams:" + "{0}".format(self.grams))
            self.LCDRefresh = False

    def SetUnauthorizedError(self):
        self.LCDRefresh = True
        self.currentstate = "UNAUTHORIZED"

    #when the buttons are pressed (only up/down do anything) it adjusts the weight to charge.
    def CheckButton(self):
        for self.b in self.btn:
            if self.lcd.buttonPressed(self.b[0]):
                #if self.b is not self.prev:
                print(self.b[1])
                if self.b[1] == "Down":
                    if (self.grams != 0):
                        self.grams = self.grams - 1
                        print(self.grams)
                    self.lastpush = datetime.datetime.now()
                    self.LCDRefresh = True
                if self.b[1] == "Up":
                    self.grams = self.grams + 1
                    print(self.grams)
                    self.lastpush = datetime.datetime.now()
                    self.LCDRefresh = True
                #self.prev = self.b
                self.LCDRefresh = True
                self.currentstate = "INUSE"
Esempio n. 4
0
import Adafruit_CharLCDPlate
from Adafruit_I2C import Adafruit_I2C
import time
import SemaphoreClient

lcd = Adafruit_CharLCDPlate.Adafruit_CharLCDPlate()

prev = -1
btn = ((lcd.SELECT, 'Select'), (lcd.LEFT, 'Left'), (lcd.UP, 'Up'),
       (lcd.DOWN, 'Down'), (lcd.RIGHT, 'Right'))
lcd.begin(16, 2)

lcd.setCursor(15, 0)
lcd.message('0')
time.sleep(0.1)
lcd.setCursor(15, 0)
lcd.message('-')
time.sleep(0.1)

if SemaphoreClient.GetSemaphore('LCDRefresh') == True:
    if self.accruingDue > 0.00:
        lcd.clear()
        lcd.message("Due:$" + "{0:0.2f}".format(
            float(SemaphoreClient.GetSemaphore('AccruingDue')) + "\n" +
            SemaphoreClient.GetSemaphore('Fullname')))
    elif SemaphoreClient.GetSemaphore('Machine') == "ENABLED":
        lcd.clear()
        lcd.message("  Current User  \n" +
                    SemaphoreClient.GetSemaphore('Fullname'))
    elif sSemaphoreClient.GetSemaphore('Machine') == "ON":
        lcd.clear()
Esempio n. 5
0
 def CharLCDPlate(self):
     self.LCD = LCD.Adafruit_CharLCDPlate()
     self.LCD.begin(16, 2)
Esempio n. 6
0
class LCD:
    def __init__(self):
        self.lcd = Adafruit_CharLCDPlate()
        self.lcd.begin(16, 2)
        sleep(0.5)
        self.colors = (('red', self.lcd.RED), ('yellow', self.lcd.YELLOW),
                       ('green', self.lcd.GREEN), ('teal', self.lcd.TEAL),
                       ('blue', self.lcd.BLUE), ('violet', self.lcd.VIOLET),
                       ('off', self.lcd.OFF), ('on', self.lcd.ON))
        self.buttons = ((self.lcd.SELECT, 'Select'), (self.lcd.LEFT, 'Left'),
                        (self.lcd.UP, 'Up'), (self.lcd.DOWN, 'Down'),
                        (self.lcd.RIGHT, 'Right'))
        self.lcd.backlight(self.lcd.BLUE)
        self.color = self.lcd.BLUE
        self.lcd.clear()

    def get_color(self, color):
        for color_main in self.colors:
            if color == color_main[0]:
                return color_main[1]

    def set_color(self, color):
        self.lcd.backlight(self.get_color(color.lower()))

    def display(self, message, duration=0, color=None):
        if color is not None and color != self.color:
            self.lcd.backlight(self.get_color(color))
        self.lcd.clear()
        self.lcd.message(message)
        if duration != 0:
            sleep(duration)
            self.lcd.clear()

    def wipe(self):
        self.lcd.backlight(self.color)
        self.lcd.clear()

    def color_cycle(self):
        for color in self.colors:
            self.lcd.backlight(color[1])
            sleep(0.1)

    def get_button_press(self, block=True):
        sleep(0.5)
        while True:
            for button in self.buttons:
                if self.lcd.buttonPressed(button[0]):
                    return button[1]
            if not block:
                break
Esempio n. 7
0
class LCD:
    def __init__(self):
        self.lcd = Adafruit_CharLCDPlate()
        self.lcd.begin(16, 2)
        sleep(0.5)
        self.colors = (
            ("red", self.lcd.RED),
            ("yellow", self.lcd.YELLOW),
            ("green", self.lcd.GREEN),
            ("teal", self.lcd.TEAL),
            ("blue", self.lcd.BLUE),
            ("violet", self.lcd.VIOLET),
            ("off", self.lcd.OFF),
            ("on", self.lcd.ON),
        )
        self.buttons = (
            (self.lcd.SELECT, "Select"),
            (self.lcd.LEFT, "Left"),
            (self.lcd.UP, "Up"),
            (self.lcd.DOWN, "Down"),
            (self.lcd.RIGHT, "Right"),
        )
        self.lcd.backlight(self.lcd.BLUE)
        self.color = self.lcd.BLUE
        self.lcd.clear()

    def get_color(self, color):
        for color_main in self.colors:
            if color == color_main[0]:
                return color_main[1]

    def set_color(self, color):
        self.lcd.backlight(self.get_color(color.lower()))

    def display(self, message, duration=0, color=None):
        if color is not None and color != self.color:
            self.lcd.backlight(self.get_color(color))
        self.lcd.clear()
        self.lcd.message(message)
        if duration != 0:
            sleep(duration)
            self.lcd.clear()

    def wipe(self):
        self.lcd.backlight(self.color)
        self.lcd.clear()

    def color_cycle(self):
        for color in self.colors:
            self.lcd.backlight(color[1])
            sleep(0.1)

    def get_button_press(self, block=True):
        sleep(0.5)
        while True:
            for button in self.buttons:
                if self.lcd.buttonPressed(button[0]):
                    return button[1]
            if not block:
                break
Esempio n. 8
0
class MachineLogic:

    rfid = 0
    prevRFID = 0
    billingRFID = 0
    cashRFID = 7898934
    machineID = 1  #4
    isbusy = False
    DebugMode = False
    fullname = ''
    accruingDue = 0.0
    linecuts = 0

    LASERPIN = 25  #// Laser power supply ACTIVE LOW
    LASERENABLEPIN1 = 23  #// Using two pins to trigger the relay to ensure enough current
    LASERENABLEPIN2 = 24  #// Using two pins to trigger the relay to ensure enough current
    LASERONPIN = 17
    JOB_END_TIME = 5  #//Time beam must be off before a job is ended and reported
    MIN_REPORT_TIME = 5  #//Minimum job length to generate a usage report

    state = ["DISABLED", "VERIFYING", "ENABLED", "ENROLLING"]
    currentstate = "DISABLED"
    laseron = False
    laseroff1 = False
    laseroff2 = False
    laseroff3 = False
    laserstarttime = time.localtime()
    lastlaserontime = datetime.datetime.now()
    lastlaserofftime = lastlaserontime  #datetime.datetime.now()# + datetime.timedelta(0,100000)
    jobRunning = False
    sleepTime = 0.05

    LCDRefresh = False

    jobtime = 0
    authService = SectorAdminSite.SectorAdmin()
    access = RFIDDataAccess.DataAccess()
    locale.setlocale(locale.LC_ALL, '')

    lcd = Adafruit_CharLCDPlate.Adafruit_CharLCDPlate()

    prev = -1
    btn = ((lcd.SELECT, 'Select'), (lcd.LEFT, 'Left'), (lcd.UP, 'Up'),
           (lcd.DOWN, 'Down'), (lcd.RIGHT, 'Right'))

    laserArray = [
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    ]
    laserReadIndex = 0

    #
    #0,0,0,0,0,0,0,0,0,0,
    #0,0,0,0,0,0,0,0,0,0,
    #0,0,0,0,0,0,0,0,0,0,
    #0,0,0,0,0,0,0,0,0,0,
    #0,0,0,0,0,0,0,0,0,0,
    #0,0,0,0,0,0,0,0,0,0,
    #0,0,0,0,0,0,0,0,0,0,
    #0,0,0,0,0,0,0,0,0,0,
    #0,0,0,0,0,0,0,0,0,0,
    #0,0,0,0,0,0,0,0,0,0,
    #0,0,0,0,0,0,0,0,0,0,
    #0,0,0,0,0,0,0,0,0,0,
    #0,0,0,0,0,0,0,0,0,0,
    #0,0,0,0,0,0,0,0,0,0,
    #0,0,0,0,0,0,0,0,0,0,
    #0,0,0,0,0,0,0,0,0,0,
    #0,0,0,0,0,0,0,0,0,0,

    def Busy(self):
        return self.isbusy

    def Setup(self):

        io.setmode(io.BCM)

        power_pin = 2
        pir_pin = 24
        io.setup(self.LASERPIN, io.IN)
        io.setup(self.LASERONPIN, io.IN)
        io.setup(self.LASERENABLEPIN1, io.OUT)
        io.setup(self.LASERENABLEPIN2, io.OUT)
        io.output(self.LASERENABLEPIN1, True)
        io.output(self.LASERENABLEPIN2, True)

        self.currentstate = "DISABLED"
        self.laseron = False
        self.laserstarttime = datetime.datetime.now()
        self.lastlaserontime = self.laserstarttime
        self.lastlaserofftime = self.lastlaserontime
        self.jobtime = 0
        self.jobRunning = False
        self.sleepTime = 0.05

        self.lcd.begin(16, 2)
        self.LCDRefresh = True

    def SetRFID(self, inRFID):
        self.prevRFID = self.rfid
        self.rfid = inRFID

    #// If a job has recently ended, report it
    def ReportJob(self):

        #newest = max(glob.iglob('/home/pi/ImageLog/*.jpg'), key=os.path.getctime)
        #print(newest)
        #jpgfile = open(newest).read()
        amount = 0

        try:
            amount = self.authService.AddMachinePayment(
                int(self.billingRFID), self.jobtime, self.machineID,
                'Laser cut time for {0}'.format(self.jobtime), '')
        except:
            print('internet connection failed')

    #print("{0:0.2f}".format(float(amount)))
        self.accruingDue += float(amount)
        self.LCDRefresh = True

    def CaptureImage(self):

        subprocess.call("/home/pi/grabPic.sh")

    def CheckBeam(self):

        if self.currentstate == "ENABLED":
            if io.input(
                    self.LASERPIN) == 0 and self.laseron == False and io.input(
                        self.LASERONPIN) == 1:
                print("beam on")
                self.laseron = True
                self.laserstarttime = datetime.datetime.now()
                self.jobRunning = True
                self.sleepTime = 0.05
                self.laserReadIndex = 0
                self.laserArray[self.laserReadIndex] = 1
                self.laserReadIndex += 1

            elif io.input(self.LASERPIN) == 0 and self.laseron == True and sum(
                    self.laserArray) <> 0:
                print(sum(self.laserArray))
                self.laserArray[self.laserReadIndex] = 1
                self.laserReadIndex += 1
                print('setting {0} value {1}'.format(self.laserReadIndex, 1))
                if self.laserReadIndex == 40:
                    self.laserReadIndex = 0

            elif io.input(self.LASERPIN) == 1 and self.laseron == True and sum(
                    self.laserArray) <> 0:
                self.laserArray[self.laserReadIndex] = 0
                self.laserReadIndex += 1
                print('setting {0} value {1}'.format(self.laserReadIndex, 0))
                if self.laserReadIndex == 40:
                    self.laserReadIndex = 0

            elif io.input(self.LASERPIN) == 1 and (
                    datetime.datetime.now() - self.laserstarttime
            ).seconds > self.MIN_REPORT_TIME and self.laseron == True and sum(
                    self.laserArray
            ) == 0:  # and (datetime.datetime.now()-self.laserstarttime).seconds > 5:
                self.sleepTime = 0.05
                #self.CaptureImage()
                self.laseron = False
                timelapse = (datetime.datetime.now() - self.laserstarttime)
                self.jobtime = (
                    float(timelapse.seconds) +
                    float(timelapse.microseconds) / float(1000000)) - 10
                print("job length of {0} seconds".format(self.jobtime))
                self.ReportJob()
                #print(self.linecuts)
                self.lastlaserontime = datetime.datetime.now()
                self.lastlaserofftime = self.lastlaserontime  #datetime.datetime.now() # + datetime.timedelta(0,100000)
                self.jobtime = 0.0
                self.linecuts = 0
                self.jobRunning = False

    def DoUnAuthorizedContinuousWork(self):
        self.CheckBeam()
        self.UpdateLCD()
        self.CheckButton()
        if io.input(self.LASERONPIN) == 1 and self.currentstate == "DISABLED":
            self.currentstate = "ON"
            self.LCDRefresh = True
        elif io.input(self.LASERONPIN) == 0 and self.currentstate == "ENABLED":
            self.isbusy = False
            self.currentstate = "DISABLED"
            io.output(self.LASERENABLEPIN1, True)
            io.output(self.LASERENABLEPIN2, True)
            print(self.currentstate)
            self.billingRFID = 0
            self.rfid = 0
            self.jobtime = 0.0
            self.accruingDue = 0
            self.LCDRefresh = True

        self.lcd.setCursor(15, 0)
        self.lcd.message('0')
        time.sleep(0.1)
        self.lcd.setCursor(15, 0)
        self.lcd.message('-')
        time.sleep(0.1)

        #print(self.currentstate)

    def DoAuthorizedWork(self):
        if self.currentstate == "ON":
            self.isbusy = True
            self.currentstate = "ENABLED"
            io.output(self.LASERENABLEPIN1, False)
            io.output(self.LASERENABLEPIN2, False)
            print(self.currentstate)
            self.billingRFID = self.rfid
            self.accruingDue = 0
            self.lcd.clear()
            #self.lcd.message("  Current User  \n" + self.fullname)
            self.lcd.message("     Please     \n       Wait     ")
            user = self.access.GetUserByRFID(self.rfid)
            #self.fullname = user
            self.LCDRefresh = True
            self.laserstarttime = datetime.datetime.now()
            self.lastlaserontime = self.laserstarttime
            self.lastlaserofftime = self.lastlaserontime
            self.jobRunning = False
        elif self.currentstate == "ENABLED" and self.laseron <> True:
            self.isbusy = False
            self.currentstate = "ON"
            io.output(self.LASERENABLEPIN1, True)
            io.output(self.LASERENABLEPIN2, True)
            print(self.currentstate)
            self.billingRFID = 0
            self.rfid = 0
            self.jobtime = 0.0
            self.accruingDue = 0
            self.LCDRefresh = True
            self.jobRunning = False

    def UpdateLCD(self):
        if self.LCDRefresh == True:
            if self.accruingDue > 0.00:
                self.lcd.clear()
                self.lcd.message("Due:$" +
                                 "{0:0.2f}".format(float(self.accruingDue)) +
                                 "\n" + self.fullname)
            elif self.currentstate == "ENABLED":
                self.lcd.clear()
                print(self.billingRFID)
                self.lcd.message("  Current User  \n" + self.fullname)
            elif self.currentstate == "ON":
                self.lcd.clear()
                self.lcd.message("  Please Swipe  \n    RFID Tag   ")
            elif self.currentstate == "DISABLED":
                self.lcd.clear()
                self.lcd.message("  Please Turn  \n  On Machine ")
                #self.lcd.message("  Please Swipe  \n    RFID Tag   ")
                #self.lcd.message("  Laser cutter  \n     Ready    ")

            self.LCDRefresh = False

        if self.DebugMode:
            self.lcd.clear()
            self.lcd.message("{0}".format(self.rfid) +
                             " {0}".format(self.billingRFID) +
                             "\n{0}".format(io.input(self.LASERPIN)) +
                             " {0}".format(self.laseron))

    def SetBillingAccount(self, rfid):
        #if self.currentstate == "ENABLED" and self.laseron <> True:
        #if self.cashRFID == rfid:
        #   self.fullname ="Cash"
        #   self.billingRFID = rfid
        #   self.lcd.clear()
        #   self.lcd.message("  Current User  \n      Cash")
        #else :
        self.fullname = ''
        try:
            data = self.authService.GetUserByRFID(rfid)
            self.fullname = data
            print(self.fullname)
            self.billingRFID = rfid
        except:
            print('cannot add billing user')

        self.LCDRefresh = True
        #self.lcd.clear()
        #self.lcd.message("  Current User  \n" + self.fullname)

    def CheckButton(self):
        for self.b in self.btn:
            if self.lcd.buttonPressed(self.b[0]):
                if self.b is not self.prev:
                    print(self.b[1])

                    if self.b[1] == "Down":
                        self.DebugMode = True
                    if self.b[1] == "Up":
                        self.DebugMode = False
                        self.LCDRefresh = True

                    self.prev = self.b