app/picadae_api.py, picadae_shell.py : Added set/get_hold_delay(). Fixed shell._read().
This commit is contained in:
parent
78e533a61f
commit
5008c67002
@ -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])
|
||||
|
@ -13,22 +13,24 @@ class PicadaeShell:
|
||||
'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 <i2c_addr> <reg_addr> <data0> ... <dataN>"},
|
||||
'r':{ "func":"_read", "minN":4, "maxN":4, "help":"read <i2c_addr> <src> <reg_addr> <byteN>"},
|
||||
'r':{ "func":"_read", "minN":4, "maxN":4, "help":"read <i2c_addr> <src> <reg_addr> <byteN> src: 0=reg_array 1=vel_table 2=eeprom"},
|
||||
'v':{ "func":"note_on_vel", "minN":2, "maxN":2, "help":"note-on <pitch> <vel>"},
|
||||
'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)"},
|
||||
'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)"},
|
||||
'o':{ "func":"note_off", "minN":1, "maxN":1, "help":"note-off <pitch>"},
|
||||
'T':{ "func":"set_vel_map", "minN":3, "maxN":3, "help":"table <pitch> <vel> <usec>"},
|
||||
't':{ "func":"get_vel_map", "minN":2, "maxN":2, "help":"table <pitch> <vel>"},
|
||||
'D':{ "func":"set_pwm_duty", "minN":2, "maxN":4, "help":"duty <pitch> <percent> {<hz> {<div>}} " },
|
||||
'd':{ "func":"get_pwm_duty", "minN":1, "maxN":1, "help":"duty <pitch>"},
|
||||
'F':{ "func":"set_pwm_freq", "minN":2, "maxN":2, "help":"freq <pitch> <hz> 254=~123Hz"},
|
||||
'f':{ "func":"get_pwm_freq", "minN":1, "maxN":1, "help":"freq <pitch>"},
|
||||
'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"},
|
||||
'i':{ "func":"get_pwm_div", "minN":1, "maxN":1, "help":"div <pitch>"},
|
||||
'H':{ "func":"set_hold_delay", "minN":2, "maxN":2, "help":"hold delay <pitch> <usec>"},
|
||||
'h':{ "func":"get_hold_delay", "minN":1, "maxN":1, "help":"hold delay <pitch>"},
|
||||
'F':{ "func":"set_pwm_freq", "minN":2, "maxN":2, "help":"pwm freq <pitch> <hz> 254=~123Hz"},
|
||||
'f':{ "func":"get_pwm_freq", "minN":1, "maxN":1, "help":"pwm freq <pitch>"},
|
||||
'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"},
|
||||
'i':{ "func":"get_pwm_div", "minN":1, "maxN":1, "help":"pwm div <pitch>"},
|
||||
'W':{ "func":"write_table", "minN":1, "maxN":1, "help":"write_table <pitch>"},
|
||||
'N':{ "func":"make_note", "minN":3, "maxN":3, "help":"note <pitch> <atkUs> <durMs>"},
|
||||
'S':{ "func":"make_seq", "minN":5, "maxN":5, "help":"seq <pitch> <atkUs> <durMs> <deltaUs> <note_count>"},
|
||||
'L':{ "func":"set_log_level","minN":1, "maxN":1, "help":"log <level> (0-1)."}
|
||||
'L':{ "func":"set_log_level", "minN":1, "maxN":1, "help":"log <level> (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 )
|
||||
|
Loading…
Reference in New Issue
Block a user