Browse Source

cleanup and change midi.py:error

micha 10 months ago
parent
commit
085c540fa3
4 changed files with 91 additions and 47 deletions
  1. 31 26
      _LibreLightDesk.py
  2. 27 6
      lib/fifo.py
  3. 8 2
      tksdl/fix.py
  4. 25 13
      tksdl/midi.py

+ 31 - 26
_LibreLightDesk.py

@@ -354,8 +354,11 @@ import lib.fifo as FIFO
 if __name__ == "__main__":
     # external GUI
     f_server = FIFO.read_loop() #chat.Server(port=30003,cb=JSBC.JSCB)
-    f_server.loop()
-    def f_server_loop():
+    f_server.loop(sleep=1)
+
+    def f_server_read_loop():
+        time.sleep(10)
+        print("FIFO read_loop() __ ")
         while 1:
             try:
                 data = f_server.read()
@@ -377,13 +380,15 @@ if __name__ == "__main__":
 
                         master.preset_go(exec_nr-1,xfade=None,val=val)
                 else:
-                    time.sleep(0.01)
+                    time.sleep(0.02)
             except KeyboardInterrupt as e:
                 raise e
             except Exception as e:
-                print("ERR1",e)
+                print("FIFO ERR1",e)
+    
+    thread.start_new_thread(f_server_read_loop,()) # SERVER
+
 
-    thread.start_new_thread(f_server_loop,()) # SERVER
 # read memcachd
 memcache = None
 try:
@@ -1406,25 +1411,25 @@ class Xevent():
 
     def _encoder(self,event):
         global _shift_key
-        if 1: #self.mode == "ENCODER" or self.mode == "ENCODER2":
-            cprint("-- Xevent","_ENC",self.fix,self.attr,self.mode)
-            cprint("-- SHIFT_KEY",_shift_key,"??????????")
-            #cprint(self.data)
-            val=""
-            if event.num == 1:
-                val ="click"
-            elif event.num == 4:
-                val ="++"
-                if _shift_key:
-                    val = "+"
-            elif event.num == 5:
-                val ="--"
-                if _shift_key:
-                    val = "-"
-            #print("SHIFT",val,_shift_key)
-            if val:
-                FIXTURES.encoder(fix=self.fix,attr=self.attr,xval=val)
-                return 1       
+
+        cprint("-- Xevent","_ENC",self.fix,self.attr,self.mode)
+        cprint("-- SHIFT_KEY",_shift_key,"??????????")
+        #cprint(self.data)
+        val=""
+        if event.num == 1:
+            val ="click"
+        elif event.num == 4:
+            val ="++"
+            if _shift_key:
+                val = "+"
+        elif event.num == 5:
+            val ="--"
+            if _shift_key:
+                val = "-"
+        #print("SHIFT",val,_shift_key)
+        if val:
+            FIXTURES.encoder(fix=self.fix,attr=self.attr,xval=val)
+            return 1       
 
 
             
@@ -2805,8 +2810,8 @@ class WindowManager():
 
         if name in self.window_init_buffer:
             c = self.window_init_buffer[name] 
-            print(c)
-            print(dir(c))
+            #print("",c)
+            #print(dir(c))
             w,obj,cb_ok = c.create()
             window_manager.update(w,name,obj)
 

+ 27 - 6
lib/fifo.py

@@ -3,6 +3,7 @@ cmd="mkfifo backpipe"
 fname = "/home/user/backpipe" # fifo named pipe
 import json
 import sys
+import os
 import time
 import _thread as thread
 
@@ -27,7 +28,13 @@ class read_loop():
         self.s = time.time()
         self.buf = []
         self.lock = thread.allocate_lock()
-    def loop(self):
+        self.sleep = 0
+    def loop(self,sleep=0):
+        print(self,self.fname)
+        if sleep:
+            time.sleep(sleep)
+            self.sleep=sleep
+
         thread.start_new_thread(self._loop,())
     def read(self):
         #print("read",self)
@@ -40,15 +47,29 @@ class read_loop():
         finally:
             self.lock.release()
         return out
+    def check_pipe(self):
+        r=os.popen("file {}".format(self.fname))
+        for i in r.readlines():
+            #print([i])
+            if ": fifo " in i:
+                return 1
 
     def _loop(self):
-
-        print("start._loop",self)
+        if self.sleep:
+            time.sleep(self.sleep)
+        #print("loop_start __ "*100)
+        #print()
+        #print("start._loop",self)
+        #print(self.fname)
         while 1:
             #print(2)
+            if not self.check_pipe():
+                #print("FIFO PIPE ERR:",fname,"is not a pipe")
+                time.sleep(1)
+                continue
+
             self.lock.acquire()
             self.f = open(self.fname,"r")
-            #print(1)
             txt="null"
             try:
                 txt = self.f.read()
@@ -59,8 +80,8 @@ class read_loop():
             except KeyboardInterrupt as e:
                 raise e
             except Exception as e:
-                print("TXT",[txt])
-                print("ERR",e)
+                print("FIFO TXT",[txt])
+                print("FIFO ERR",e)
             finally:
                 self.lock.release()
             time.sleep(0.01)

+ 8 - 2
tksdl/fix.py

@@ -675,6 +675,12 @@ while 1:
                 fr = font18.render("ACTIVE:{}:{} ({:0.01f})".format(active_fix,active_attr,active_ratio) ,1, [255,255,0]) #(200,200,200))
                 window.blit(fr,(300,5))
 
+                if SHIFT_FINE:
+                    fr = font18.render("ENCODER:±0.25" ,1, [255,255,0])
+                else:
+                    fr = font18.render("ENCODER:±5.00" ,1, [255,255,0])
+                window.blit(fr,(420,5))
+
 
         if 0: #show line number +scroll_pos
             bxc = sdl_elm.Button(window,pos=[-11+10,(0*23),50,10])
@@ -698,10 +704,10 @@ while 1:
                 print(event.dict,event.type)
                 if event.scancode == 50:
                     if event.type == 2: # press
-                        pg.display.set_caption(CAPTION+ " SHIFT/FINE")
+                        #pg.display.set_caption(CAPTION+ " SHIFT/FINE")
                         SHIFT_FINE = 1
                     if event.type == 3: # release
-                        pg.display.set_caption(CAPTION)
+                        #pg.display.set_caption(CAPTION)
                         SHIFT_FINE = 0
 
                 if event.scancode == 9:

+ 25 - 13
tksdl/midi.py

@@ -88,6 +88,7 @@ font   = pygame.font.SysFont("freemonobold",22)
 font10 = pygame.font.SysFont("freemonobold",10)
 font12 = pygame.font.SysFont("freemonobold",12)
 font15 = pygame.font.SysFont("freemonobold",15)
+font20 = pygame.font.SysFont("freemonobold",20)
 font22 = pygame.font.SysFont("FreeSans",22)
 #font  = pygame.font.SysFont(None,30)
 
@@ -326,27 +327,38 @@ while 1:
     _blink =0 
     _is_open  =0
     try:
-        rgb = [10,10,10]
+        rgb = [90,180,10]
         if apc_main.blink:
-            rgb = [110,110,110]
+            rgb = [110,210,10]
         _blink = apc_main.blink
         _is_open  = apc_main.is_open
     
     except Exception as e:
         pass #print(e)
-
+    
+    con_err = "connect to apcmini ??"
+    con_ok = "connect to apcmini OK"
     if _is_open == 0:
-        buf  = []
-        buf2 =  ["connect to apcmini ..."]
-        buf_exec = []
-        msgs = []
-
-    pygame.draw.rect(window,rgb,[200,r,60,25])
-    fr = font15.render("BLINK:"+str(_blink)  ,1, (200,200,200))
-    window.blit(fr,(200,r ))
+        #buf  = []
+        if len(buf2):
+            if buf2[-1] != con_err:
+                buf2.append(con_err)
+        else:
+            buf2.append(con_err)
+        rgb = [210,110,10]
+        #buf_exec = []
+        #msgs = []
+    else:
+        if len(buf2):
+            if buf2[-1] == con_err:
+                buf2.append(con_ok)
+
+    pygame.draw.rect(window,rgb,[200-3,r,60,25])
+    fr = font15.render("BLINK:"+str(_blink)  ,1, (0,0,0))
+    #window.blit(fr,(200,r+2 ))
     r+=10
-    fr = font15.render("open:"+str(_is_open)  ,1, (200,200,200))
-    window.blit(fr,(200,r ))
+    fr = font20.render("open:"+str(_is_open)  ,1, (0,0,0))
+    window.blit(fr,(200+5,r-5 ))
 
     r = 10
     fr = font15.render("EXEC:"  ,1, (200,100,200))