Browse Source

app/picadae_api.py, picadae_shell.py : Added set/get_hold_delay(). Fixed shell._read().

master
kevin 3 years ago
parent
commit
5008c67002
2 changed files with 52 additions and 23 deletions
  1. 29
    2
      control/app/picadae_api.py
  2. 23
    21
      control/app/picadae_shell.py

+ 29
- 2
control/app/picadae_api.py View File

@@ -16,7 +16,8 @@ class TinyOp(Enum):
16 16
     setReadAddr  = 4
17 17
     writeOp      = 5
18 18
     writeTableOp = 6
19
-    invalidOp    = 7
19
+    holdDelayOp  = 7
20
+    invalidOp    = 8
20 21
     
21 22
 
22 23
 class TinyRegAddr(Enum):
@@ -36,6 +37,9 @@ class TinyRegAddr(Enum):
36 37
     kPwmDivAddr      = 13
37 38
     kStateAddr       = 14
38 39
     kErrorCodeAddr   = 15
40
+    kMaxAllowTmrAddr = 16
41
+    kDelayCoarseAddr = 17
42
+    kDelayFineAddr   = 18
39 43
 
40 44
 class TinyConst(Enum):
41 45
     kRdRegSrcId    = TinyRegAddr.kRdRegAddrAddr.value    # 0
@@ -184,6 +188,7 @@ class Picadae:
184 188
         return self.write_tiny_reg( self._pitch_to_i2c_addr( midi_pitch ), op_code, argL )                          
185 189
 
186 190
     def set_read_addr( self, i2c_addr, mem_id, addr ):
191
+        # mem_id: 0=reg_array 1=vel_table 2=eeprom
187 192
         return self.write_tiny_reg(i2c_addr, TinyOp.setReadAddr.value,[ mem_id, addr ])
188 193
                 
189 194
     def read_request( self, i2c_addr, reg_addr, byteOutN ):
@@ -246,6 +251,19 @@ class Picadae:
246 251
         return self.call_op( midi_pitch, TinyOp.noteOffOp.value,
247 252
                            [0] )  # TODO: sending a dummy byte because we can't handle sending a command with no data bytes.
248 253
 
254
+    def set_hold_delay( self, midi_pitch, pulse_usec ):
255
+        return  self.call_op( midi_pitch, TinyOp.holdDelayOp.value, list(self._usec_to_coarse_and_fine(pulse_usec)) )
256
+
257
+    def get_hold_delay( self, midi_pitch, time_out_ms=250 ):
258
+
259
+        res = self.block_on_picadae_read_reg( midi_pitch, TinyRegAddr.kDelayCoarseAddr.value, byteOutN=2, time_out_ms=time_out_ms )
260
+
261
+        if len(res.value) == 2:
262
+            res.value = [ self.prescaler_usec*255*res.value[0] + self.prescaler_usec*res.value[1] ]
263
+        
264
+        return res
265
+        
266
+    
249 267
     def set_velocity_map( self, midi_pitch, midi_vel, pulse_usec ):
250 268
         coarse,fine = self._usec_to_coarse_and_fine( pulse_usec )
251 269
         src         = TinyConst.kWrAddrFl.value | TinyConst.kWrTableDstId.value
@@ -258,7 +276,7 @@ class Picadae:
258 276
 
259 277
     def set_pwm_duty( self, midi_pitch, duty_cycle_pct ):
260 278
         if 0 <= duty_cycle_pct and duty_cycle_pct <= 100:
261
-            duty_cycle_pct = 100.0 - duty_cycle_pct
279
+            # duty_cycle_pct = 100.0 - duty_cycle_pct
262 280
             return self.call_op( midi_pitch, TinyOp.setPwmOp.value, [ int( duty_cycle_pct * 255.0 /100.0 )])
263 281
         else:
264 282
             return Result(msg="Duty cycle (%f) out of range 0-100." % (duty_cycle_pct))
@@ -279,6 +297,15 @@ class Picadae:
279 297
     def get_pwm_div( self, midi_pitch, time_out_ms=250 ):
280 298
         return self.block_on_picadae_read_reg( midi_pitch, TinyRegAddr.kPwmDivAddr.value, time_out_ms=time_out_ms )
281 299
 
300
+    def set_pwm_div( self, midi_pitch, div, time_out_ms=250 ):
301
+        res = self.get_pwm_duty( midi_pitch )
302
+        if res:
303
+            duty = res.value[0]
304
+            res = self.get_pwm_freq( midi_pitch )
305
+            if res:
306
+                res = self.call_op( midi_pitch, TinyOp.setPwmOp.value, [ int(duty), int(res.value[0]), int(div) ])
307
+        return res
308
+    
282 309
     def write_table( self, midi_pitch, time_out_ms=250 ):
283 310
         # TODO: sending a dummy byte because we can't handle sending a command with no data bytes.
284 311
         return self.call_op( midi_pitch, TinyOp.writeTableOp.value,[0])

+ 23
- 21
control/app/picadae_shell.py View File

@@ -10,25 +10,27 @@ class PicadaeShell:
10 10
     def __init__( self, cfg ):
11 11
         self.p      = None
12 12
         self.parseD = {
13
-            'q':{ "func":None,           "minN":0,  "maxN":0, "help":"quit"},
14
-            '?':{ "func":"_help",        "minN":0,  "maxN":0, "help":"Print usage text."},
15
-            'w':{ "func":"_write",       "minN":-1, "maxN":-1,"help":"write <i2c_addr> <reg_addr> <data0> ... <dataN>"},
16
-            'r':{ "func":"_read",        "minN":4,  "maxN":4, "help":"read  <i2c_addr> <src> <reg_addr> <byteN>"},
17
-            'v':{ "func":"note_on_vel",  "minN":2,  "maxN":2, "help":"note-on <pitch> <vel>"},
18
-            'u':{ "func":"note_on_us",   "minN":2,  "maxN":3, "help":"note-on <pitch> <usec> <prescale> (1=1, 2=8, 3=64,(4)=256 16us, 5=1024)"},
19
-            'o':{ "func":"note_off",     "minN":1,  "maxN":1, "help":"note-off <pitch>"},
20
-            'T':{ "func":"set_vel_map",  "minN":3,  "maxN":3, "help":"table <pitch> <vel> <usec>"},
21
-            't':{ "func":"get_vel_map",  "minN":2,  "maxN":2, "help":"table <pitch> <vel>"},
22
-            'D':{ "func":"set_pwm_duty", "minN":2,  "maxN":4, "help":"duty <pitch> <percent> {<hz> {<div>}} " },
23
-            'd':{ "func":"get_pwm_duty", "minN":1,  "maxN":1, "help":"duty <pitch>"},
24
-            'F':{ "func":"set_pwm_freq", "minN":2,  "maxN":2, "help":"freq <pitch> <hz> 254=~123Hz"},
25
-            'f':{ "func":"get_pwm_freq", "minN":1,  "maxN":1, "help":"freq <pitch>"},
26
-            'I':{ "func":"set_pwm_div",  "minN":2,  "maxN":2, "help":"div <pitch> <div> div:2=2,3=4,4=8,5=16,6=32,7=64,8=128,9=256,(10)=512 32us, 11=1024,12=2048,13=4096,14=8192,15=16384"},
27
-            'i':{ "func":"get_pwm_div",  "minN":1,  "maxN":1, "help":"div <pitch>"},
28
-            'W':{ "func":"write_table",  "minN":1,  "maxN":1, "help":"write_table <pitch>"},
29
-            'N':{ "func":"make_note",    "minN":3,  "maxN":3, "help":"note <pitch> <atkUs> <durMs>"},
30
-            'S':{ "func":"make_seq",     "minN":5,  "maxN":5, "help":"seq  <pitch> <atkUs> <durMs> <deltaUs> <note_count>"}, 
31
-            'L':{ "func":"set_log_level","minN":1,  "maxN":1, "help":"log <level> (0-1)."}
13
+            'q':{ "func":None,             "minN":0,  "maxN":0, "help":"quit"},
14
+            '?':{ "func":"_help",          "minN":0,  "maxN":0, "help":"Print usage text."},
15
+            'w':{ "func":"_write",         "minN":-1, "maxN":-1,"help":"write <i2c_addr> <reg_addr> <data0> ... <dataN>"},
16
+            'r':{ "func":"_read",          "minN":4,  "maxN":4, "help":"read  <i2c_addr> <src> <reg_addr> <byteN>   src: 0=reg_array 1=vel_table 2=eeprom"},
17
+            'v':{ "func":"note_on_vel",    "minN":2,  "maxN":2, "help":"note-on <pitch> <vel>"},
18
+            'u':{ "func":"note_on_us",     "minN":2,  "maxN":3, "help":"note-on <pitch> <usec> <prescale> (1=1, 2=8 .5us, 3=64 4us,(4)=256 16us, 5=1024 64us)"},
19
+            'o':{ "func":"note_off",       "minN":1,  "maxN":1, "help":"note-off <pitch>"},
20
+            'T':{ "func":"set_vel_map",    "minN":3,  "maxN":3, "help":"table <pitch> <vel> <usec>"},
21
+            't':{ "func":"get_vel_map",    "minN":2,  "maxN":2, "help":"table <pitch> <vel>"},
22
+            'D':{ "func":"set_pwm_duty",   "minN":2,  "maxN":4, "help":"duty <pitch> <percent> {<hz> {<div>}} " },
23
+            'd':{ "func":"get_pwm_duty",   "minN":1,  "maxN":1, "help":"duty <pitch>"},
24
+            'H':{ "func":"set_hold_delay", "minN":2,  "maxN":2, "help":"hold delay <pitch> <usec>"},
25
+            'h':{ "func":"get_hold_delay", "minN":1,  "maxN":1, "help":"hold delay <pitch>"},
26
+            'F':{ "func":"set_pwm_freq",   "minN":2,  "maxN":2, "help":"pwm freq <pitch> <hz> 254=~123Hz"},
27
+            'f':{ "func":"get_pwm_freq",   "minN":1,  "maxN":1, "help":"pwm freq <pitch>"},
28
+            'I':{ "func":"set_pwm_div",    "minN":2,  "maxN":2, "help":"pwm div <pitch> <div> div:2=2,3=4,4=8,(5)=16 1us,6=32,7=64,8=128,9=256,10=512 32us, 11=1024,12=2048,13=4096,14=8192,15=16384"},
29
+            'i':{ "func":"get_pwm_div",    "minN":1,  "maxN":1, "help":"pwm div <pitch>"},
30
+            'W':{ "func":"write_table",    "minN":1,  "maxN":1, "help":"write_table <pitch>"},
31
+            'N':{ "func":"make_note",      "minN":3,  "maxN":3, "help":"note <pitch> <atkUs> <durMs>"},
32
+            'S':{ "func":"make_seq",       "minN":5,  "maxN":5, "help":"seq  <pitch> <atkUs> <durMs> <deltaUs> <note_count>"}, 
33
+            'L':{ "func":"set_log_level",  "minN":1,  "maxN":1, "help":"log <level> (0-1)."}
32 34
             }
33 35
 
34 36
     def _help( self, _=None ):
@@ -40,8 +42,8 @@ class PicadaeShell:
40 42
     def _write( self, argL ):
41 43
         return self.p.write(argL[0], argL[1], argL[2:])
42 44
     
43
-    def _read( self, argL ):
44
-        return self.p.block_on_picadae_read(argL[0], argL[1], argL[2], argL[3])
45
+    def _read( self, i2c_addr, src_id, reg_addr, byteN ):
46
+        return self.p.block_on_picadae_read(i2c_addr, src_id, reg_addr, byteN)
45 47
         
46 48
     def _syntaxError( self, msg ):
47 49
         print("Syntax Error: " + msg )

Loading…
Cancel
Save