File save-g203.diff of Package g213colors-gui

diff -Naur G213Colors-0.5.orig/G213Colors.py G213Colors-0.5/G213Colors.py
--- G213Colors-0.5.orig/G213Colors.py	2018-11-14 20:19:35.138032438 +0100
+++ G213Colors-0.5/G213Colors.py	2018-11-14 23:31:16.480388042 +0100
@@ -36,11 +36,12 @@
                   "G203": 0xc084} # The id of the G203
 
 #  The USB controll transfer parameters
-bmRequestType  = 0x21
-bmRequest      = 0x09
-wValue         = {"G213": 0x0211,
-                  "G203": 0x0210}
-wIndex         = 0x0001
+bEndpointAddress = 0x82
+bmRequestType    = 0x21
+bmRequest        = 0x09
+wValue           = {"G213": 0x0211,
+                    "G203": 0x0210}
+wIndex           = 0x0001
 
 # binary commands in hex format
 colorCommand   = {"G213": "11ff0c3a{}01{}0200000000000000000000",
@@ -54,7 +55,8 @@
 productName    = ""               # e.g. G213, G203
 isDetached     = {"G213": False,  # If kernel driver needs to be reattached
                   "G203": False}
-confFile       = "/etc/G213Colors.conf"
+confFile       = {"G213": "/etc/G213Colors-G213.conf",
+                  "G203": "/etc/G213Colors-G203.conf"}
 
 
 def connectG(Name):
@@ -102,6 +104,8 @@
     try:
         device.ctrl_transfer(bmRequestType, bmRequest, wValue[productName], wIndex, binascii.unhexlify(data))
     finally:
+        # read back one 20-byte word, otherwise commands may not be completely executed
+        device.read(bEndpointAddress, 20)
         usb.util.release_interface(device,wIndex)
 
 def sendColorCommand(colorHex, field=0):
@@ -120,7 +124,8 @@
     global productName
     sendData(cycleCommand[productName].format(str(format(speed, '04x'))))
 
-def saveData(data):
-    file = open(confFile, "w")
+def saveData(data,product):
+    print("Saving %s to %s..." % (data, confFile[product]))
+    file = open(confFile[product], "w")
     file.write(data)
     file.close()
diff -Naur G213Colors-0.5.orig/main.py G213Colors-0.5/main.py
--- G213Colors-0.5.orig/main.py	2018-11-14 20:19:35.138032438 +0100
+++ G213Colors-0.5/main.py	2018-11-14 23:10:19.379394682 +0100
@@ -34,30 +34,34 @@
 
     def sendStatic(self, product):
         myG = G213Colors
+        myG.saveData(myG.colorCommand[product].format(str(format(0, '02x')), self.btnGetHex(self.staticColorButton)), product)
         myG.connectG(product)
         myG.sendColorCommand(self.btnGetHex(self.staticColorButton))
-        if product == "G213":
-            myG.saveData(myG.colorCommand[product].format(str(format(0, '02x')), self.btnGetHex(self.staticColorButton)))
         myG.disconnectG()
 
     def sendBreathe(self, product):
+        # Only the keyboard supports segments
+        if product != "G213":
+            return
         myG = G213Colors
+        myG.saveData(myG.breatheCommand[product].format(self.btnGetHex(self.breatheColorButton), str(format(self.sbGetValue(self.sbBCycle), '04x'))), product)
         myG.connectG(product)
         myG.sendBreatheCommand(self.btnGetHex(self.breatheColorButton), self.sbGetValue(self.sbBCycle))
-        if product == "G213":
-            myG.saveData(myG.breatheCommand[product].format(self.btnGetHex(self.breatheColorButton), str(format(self.sbGetValue(self.sbBCycle), '04x'))))
         myG.disconnectG()
 
     def sendCycle(self, product):
         myG = G213Colors
+        myG.saveData(myG.cycleCommand[product].format(str(format(self.sbGetValue(self.sbCycle), '04x'))), product)
         myG.connectG(product)
         myG.sendCycleCommand(self.sbGetValue(self.sbCycle))
-        if product == "G213":
-            myG.saveData(myG.cycleCommand[product].format(str(format(self.sbGetValue(self.sbCycle), '04x'))))
         myG.disconnectG()
 
     def sendSegments(self, product):
+        # Only the keyboard supports segments
+        if product != "G213":
+            return
         myG = G213Colors
+        myG.saveData(data)
         myG.connectG(product)
         data = ""
         for i in range(1, 6):
@@ -70,8 +74,6 @@
             data += myG.colorCommand[product].format(str(format(i, '02x')), self.btnGetHex(self.segmentColorBtns[i -1])) + "\n"
             sleep(0.01)
         myG.disconnectG()
-        if product == "G213":
-            myG.saveData(data)
 
     def sendManager(self, product):
         if product == "all":
@@ -166,23 +168,20 @@
 
 if "-t" in option:
     myG = G213Colors
-    myG.connectG("G213")
-
-    with open(myG.confFile, "r") as file:
-
-        for command in file:
-            print(command)
-            command = command.strip()
-            if command and "," not in command:
-                myG.sendData(command)
-                myG.receiveData()
-                sleep(0.01)
-
-            if "," in command:
-                print("\",\" is not supported in the config file.")
-                print("If you apply a color scheme with segments, please re-apply it or replace all \",\" with new lines in \"/etc/G213Colors.conf\".")
-
-    myG.disconnectG()
+    for product in PRODUCTS:
+        myG.connectG(product)
+        with open(myG.confFile[product], "r") as file:
+            for command in file:
+                print(command)
+                command = command.strip()
+                if command and "," not in command:
+                    myG.sendData(command)
+                    myG.receiveData()
+                    sleep(0.01)
+                if "," in command:
+                    print("\",\" is not supported in the config file.")
+                    print("If you apply a color scheme with segments, please re-apply it or replace all \",\" with new lines in \"/etc/G213Colors.conf\".")
+        myG.disconnectG()
     sys.exit(0)
 
 win = Window()
diff -Naur G213Colors-0.5.orig/makefile G213Colors-0.5/makefile
--- G213Colors-0.5.orig/makefile	2018-11-14 20:19:35.122032295 +0100
+++ G213Colors-0.5/makefile	2018-11-14 20:44:04.503679161 +0100
@@ -3,7 +3,8 @@
 install:
 	install -D -m755 G213Colors.py $(DESTDIR)/usr/bin/G213Colors.py
 	install -D -m755 main.py $(DESTDIR)/usr/bin/g213colors-gui
-	install -D -m644 default.conf $(DESTDIR)/etc/G213Colors.conf
+	install -D -m644 default.conf $(DESTDIR)/etc/G213Colors-G203.conf
+	install -D -m644 default.conf $(DESTDIR)/etc/G213Colors-G213.conf
 	install -D -m644 g213colors.service $(DESTDIR)$(UNITDIR)/g213colors.service
 	install -D -m644 icons/G213Colors-16.png $(DESTDIR)/usr/share/icons/hicolor/16x16/apps/g213colors.png
 	install -D -m644 icons/G213Colors-24.png $(DESTDIR)/usr/share/icons/hicolor/24x24/apps/g213colors.png
@@ -16,6 +17,8 @@
 	rm $(DESTDIR)/usr/bin/G213Colors.py
 	rm $(DESTDIR)/usr/bin/g213colors-gui
 	rm $(DESTDIR)/etc/G213Colors.conf
+	rm $(DESTDIR)/etc/G213Colors-G203.conf
+	rm $(DESTDIR)/etc/G213Colors-G213.conf
 	rm $(DESTDIR)$(UNITSDIR)/g213colors.service
 	rm $(DESTDIR)/usr/share/icons/hicolor/16x16/apps/g213colors.png
 	rm $(DESTDIR)/usr/share/icons/hicolor/24x24/apps/g213colors.png
openSUSE Build Service is sponsored by