Commit e4678a49 authored by unknown's avatar unknown
Browse files

Merge branch 'master' of https://git.omegav.no/ov/neokomp

parents 2225b18a d76abf29
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ from frames.Cart import Cart
from frames.Search import Search
from frames.Receipt import Receipt
from frames.Balance import Balance
from frames.FrameBase import TimerMessageBox

import api_communication as API

@@ -92,6 +93,11 @@ class NeoKomp(QtWidgets.QMainWindow):
    def cart_has_items(self):
        return self.frames['Cart'].has_items()

    def show_error(self, error_message):
            warning = TimerMessageBox(message=error_message, parent=self)
            warning.setIcon(QtWidgets.QMessageBox.Warning)
            warning.show()

    @QtCore.pyqtSlot("PyQt_PyObject")
    def ble_button_pressed(self, location):
        self.frames['Cart'].add_item_from_location(location)
+30 −23
Original line number Diff line number Diff line
@@ -2,11 +2,11 @@ import os
import subprocess
import re
import gatt
import parse
from PyQt5 import QtCore, QtGui, QtWidgets

SERVICE_UUID = "00001523-1212-efde-1523-785feabcd123"
BUTTON_UUID =  "00001524-1212-efde-1523-785feabcd123"
LED_UUID =     "00001525-1212-efde-1523-785feabcd123"
RX_UUID =  "6e400002-b5a3-f393-e0a9-e50e24dcca9e"
TX_UUID =  "6e400003-b5a3-f393-e0a9-e50e24dcca9e"

class BLEThread(QtCore.QThread):
    # This signal will be emitted each time the BLE manager receives a button
@@ -74,28 +74,35 @@ class ModuleDevice(gatt.Device):
        print("[%s] Resolved services" % (self.mac_address))
        for service in self.services:
            for characteristic in service.characteristics:
                if characteristic.uuid == BUTTON_UUID:
                    dbus_value = characteristic.read_value()
                    print(dbus_value)
                    values = [int(v) for v in dbus_value]
                    print(values)
                    order = {}
                    if values != None and len(values) == 4:

                        order['rom'] = 'OV'
                        order['seksjon'] = self.parent.device_mapping[self.mac_address.upper()]
                        order['hylle'] =   values[0]
                        order['rad'] =     values[1]
                        order['kolonne'] = values[2]
                        order['dybde'] =   values[3]

                        self.parent.ble_order_position(order)

                    else:
                        print("Failed to fetch values")
                # Always read an order when connecting
                if characteristic.uuid == TX_UUID: 
                    self.read_order(characteristic)

        # DBus is taking its time getting back with a reply on self.disconnect(), which blocks
        # the whole process, so we offload this work to a different process.
        # TODO: Find a nicer way of doing this.
        #self.disconnect()
        subprocess.Popen(["/usr/bin/bt-device", "--remove=%s" % self.mac_address])

    def read_order(self, characteristic):
        # Enable notifications before getting values
        characteristic.enable_notifications()
        dbus_value = characteristic.read_value()

        # Parse characteristic value into order
        order_str = ''.join([str(v) for v in dbus_value])
        order_format = "S{seksjon}H{hylle}R{rad}C{kolonne}D{dybde}"
        order_result = parse.parse(order_format, order_str)
        if order_result:
            order = order_result.named
            order['rom'] = 'OV'

            # Send order
            self.parent.ble_order_position(order)
        else:
            error_str = "Failed to parse order '{}' from module.".format(order_str)
            print(error_str)
            self.parent.parent.show_error(error_str)

+1 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ def main():
    else:
        neokomp = NeoKomp.NeoKomp()
    neokomp.setWindowTitle("NeoKomp")
    neokomp.setFixedSize(1280,1024)
    neokomp.show()
    neokomp.showFullScreen()
    app.exec_()