diff --git a/control/app/picadae_api.py b/control/app/picadae_api.py index fb70241..0e119e6 100644 --- a/control/app/picadae_api.py +++ b/control/app/picadae_api.py @@ -16,7 +16,8 @@ class TinyOp(Enum): setReadAddr = 4 writeOp = 5 writeTableOp = 6 - invalidOp = 7 + holdDelayOp = 7 + invalidOp = 8 class TinyRegAddr(Enum): @@ -36,6 +37,9 @@ class TinyRegAddr(Enum): kPwmDivAddr = 13 kStateAddr = 14 kErrorCodeAddr = 15 + kMaxAllowTmrAddr = 16 + kDelayCoarseAddr = 17 + kDelayFineAddr = 18 class TinyConst(Enum): kRdRegSrcId = TinyRegAddr.kRdRegAddrAddr.value # 0 @@ -184,6 +188,7 @@ class Picadae: return self.write_tiny_reg( self._pitch_to_i2c_addr( midi_pitch ), op_code, argL ) def set_read_addr( self, i2c_addr, mem_id, addr ): + # mem_id: 0=reg_array 1=vel_table 2=eeprom return self.write_tiny_reg(i2c_addr, TinyOp.setReadAddr.value,[ mem_id, addr ]) def read_request( self, i2c_addr, reg_addr, byteOutN ): @@ -246,6 +251,19 @@ class Picadae: return self.call_op( midi_pitch, TinyOp.noteOffOp.value, [0] ) # TODO: sending a dummy byte because we can't handle sending a command with no data bytes. + def set_hold_delay( self, midi_pitch, pulse_usec ): + return self.call_op( midi_pitch, TinyOp.holdDelayOp.value, list(self._usec_to_coarse_and_fine(pulse_usec)) ) + + def get_hold_delay( self, midi_pitch, time_out_ms=250 ): + + res = self.block_on_picadae_read_reg( midi_pitch, TinyRegAddr.kDelayCoarseAddr.value, byteOutN=2, time_out_ms=time_out_ms ) + + if len(res.value) == 2: + res.value = [ self.prescaler_usec*255*res.value[0] + self.prescaler_usec*res.value[1] ] + + return res + + def set_velocity_map( self, midi_pitch, midi_vel, pulse_usec ): coarse,fine = self._usec_to_coarse_and_fine( pulse_usec ) src = TinyConst.kWrAddrFl.value | TinyConst.kWrTableDstId.value @@ -258,7 +276,7 @@ class Picadae: def set_pwm_duty( self, midi_pitch, duty_cycle_pct ): if 0 <= duty_cycle_pct and duty_cycle_pct <= 100: - duty_cycle_pct = 100.0 - duty_cycle_pct + # duty_cycle_pct = 100.0 - duty_cycle_pct return self.call_op( midi_pitch, TinyOp.setPwmOp.value, [ int( duty_cycle_pct * 255.0 /100.0 )]) else: return Result(msg="Duty cycle (%f) out of range 0-100." % (duty_cycle_pct)) @@ -279,6 +297,15 @@ class Picadae: def get_pwm_div( self, midi_pitch, time_out_ms=250 ): return self.block_on_picadae_read_reg( midi_pitch, TinyRegAddr.kPwmDivAddr.value, time_out_ms=time_out_ms ) + def set_pwm_div( self, midi_pitch, div, time_out_ms=250 ): + res = self.get_pwm_duty( midi_pitch ) + if res: + duty = res.value[0] + res = self.get_pwm_freq( midi_pitch ) + if res: + res = self.call_op( midi_pitch, TinyOp.setPwmOp.value, [ int(duty), int(res.value[0]), int(div) ]) + return res + def write_table( self, midi_pitch, time_out_ms=250 ): # TODO: sending a dummy byte because we can't handle sending a command with no data bytes. return self.call_op( midi_pitch, TinyOp.writeTableOp.value,[0]) diff --git a/control/app/picadae_shell.py b/control/app/picadae_shell.py index 78ba15a..3894afb 100644 --- a/control/app/picadae_shell.py +++ b/control/app/picadae_shell.py @@ -10,25 +10,27 @@ class PicadaeShell: def __init__( self, cfg ): self.p = None self.parseD = { - 'q':{ "func":None, "minN":0, "maxN":0, "help":"quit"}, - '?':{ "func":"_help", "minN":0, "maxN":0, "help":"Print usage text."}, - 'w':{ "func":"_write", "minN":-1, "maxN":-1,"help":"write ... "}, - 'r':{ "func":"_read", "minN":4, "maxN":4, "help":"read "}, - 'v':{ "func":"note_on_vel", "minN":2, "maxN":2, "help":"note-on "}, - 'u':{ "func":"note_on_us", "minN":2, "maxN":3, "help":"note-on (1=1, 2=8, 3=64,(4)=256 16us, 5=1024)"}, - 'o':{ "func":"note_off", "minN":1, "maxN":1, "help":"note-off "}, - 'T':{ "func":"set_vel_map", "minN":3, "maxN":3, "help":"table "}, - 't':{ "func":"get_vel_map", "minN":2, "maxN":2, "help":"table "}, - 'D':{ "func":"set_pwm_duty", "minN":2, "maxN":4, "help":"duty { {
}} " }, - 'd':{ "func":"get_pwm_duty", "minN":1, "maxN":1, "help":"duty "}, - 'F':{ "func":"set_pwm_freq", "minN":2, "maxN":2, "help":"freq 254=~123Hz"}, - 'f':{ "func":"get_pwm_freq", "minN":1, "maxN":1, "help":"freq "}, - 'I':{ "func":"set_pwm_div", "minN":2, "maxN":2, "help":"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"}, - 'i':{ "func":"get_pwm_div", "minN":1, "maxN":1, "help":"div "}, - 'W':{ "func":"write_table", "minN":1, "maxN":1, "help":"write_table "}, - 'N':{ "func":"make_note", "minN":3, "maxN":3, "help":"note "}, - 'S':{ "func":"make_seq", "minN":5, "maxN":5, "help":"seq "}, - 'L':{ "func":"set_log_level","minN":1, "maxN":1, "help":"log (0-1)."} + 'q':{ "func":None, "minN":0, "maxN":0, "help":"quit"}, + '?':{ "func":"_help", "minN":0, "maxN":0, "help":"Print usage text."}, + 'w':{ "func":"_write", "minN":-1, "maxN":-1,"help":"write ... "}, + 'r':{ "func":"_read", "minN":4, "maxN":4, "help":"read src: 0=reg_array 1=vel_table 2=eeprom"}, + 'v':{ "func":"note_on_vel", "minN":2, "maxN":2, "help":"note-on "}, + 'u':{ "func":"note_on_us", "minN":2, "maxN":3, "help":"note-on (1=1, 2=8 .5us, 3=64 4us,(4)=256 16us, 5=1024 64us)"}, + 'o':{ "func":"note_off", "minN":1, "maxN":1, "help":"note-off "}, + 'T':{ "func":"set_vel_map", "minN":3, "maxN":3, "help":"table "}, + 't':{ "func":"get_vel_map", "minN":2, "maxN":2, "help":"table "}, + 'D':{ "func":"set_pwm_duty", "minN":2, "maxN":4, "help":"duty { {
}} " }, + 'd':{ "func":"get_pwm_duty", "minN":1, "maxN":1, "help":"duty "}, + 'H':{ "func":"set_hold_delay", "minN":2, "maxN":2, "help":"hold delay "}, + 'h':{ "func":"get_hold_delay", "minN":1, "maxN":1, "help":"hold delay "}, + 'F':{ "func":"set_pwm_freq", "minN":2, "maxN":2, "help":"pwm freq 254=~123Hz"}, + 'f':{ "func":"get_pwm_freq", "minN":1, "maxN":1, "help":"pwm freq "}, + 'I':{ "func":"set_pwm_div", "minN":2, "maxN":2, "help":"pwm 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"}, + 'i':{ "func":"get_pwm_div", "minN":1, "maxN":1, "help":"pwm div "}, + 'W':{ "func":"write_table", "minN":1, "maxN":1, "help":"write_table "}, + 'N':{ "func":"make_note", "minN":3, "maxN":3, "help":"note "}, + 'S':{ "func":"make_seq", "minN":5, "maxN":5, "help":"seq "}, + 'L':{ "func":"set_log_level", "minN":1, "maxN":1, "help":"log (0-1)."} } def _help( self, _=None ): @@ -40,8 +42,8 @@ class PicadaeShell: def _write( self, argL ): return self.p.write(argL[0], argL[1], argL[2:]) - def _read( self, argL ): - return self.p.block_on_picadae_read(argL[0], argL[1], argL[2], argL[3]) + def _read( self, i2c_addr, src_id, reg_addr, byteN ): + return self.p.block_on_picadae_read(i2c_addr, src_id, reg_addr, byteN) def _syntaxError( self, msg ): print("Syntax Error: " + msg )