Commits

Gordon McGregor committed e79483b

MIDI SysEx programmer test over serial working

Comments (0)

Files changed (5)

+#!/usr/bin/env python
+import serial
+class Arduino():
+ 
+  def __init__(self, path='/dev/tty.usbserial', baud=9600):
+    self.serial = serial.Serial(path, baud)   
+ 
+  def send(self, data):
+    self.serial.write(data)
+ 
+  def read(self, bytes):
+    while (1):
+      if (self.serial.inWaiting() > bytes-1):
+        return self.serial.read(bytes)
+ 
+  def flush(self):
+    self.serial.flushInput()
+
+if __name__ == '__main__':
+  # drop to console for test with python -i 
+  a = Arduino('/dev/tty.usbmodem24371', 31250)
+
+bank:
+- switch:
+  - state0_message: [0xb1, 1, 0]
+    state1_message: [0xb1, 2, 0x7f]
+    toggle_not_immediate: 1
+  - state0_message: [0xb1, 3, 0]
+    state1_message: [0xb1, 4, 0x7f]
+    toggle_not_immediate: 1
+  - state0_message: [0xb1, 5, 0]
+    state1_message: [0xb1, 6, 0x7f]
+    toggle_not_immediate: 1
+  - state0_message: [0xb1, 7, 0]
+    state1_message: [0xb1, 8, 0x7f]
+    toggle_not_immediate: 1
+- switch:
+  - state0_message: [0xb1, 9, 0]
+    state1_message: [0xb1, 10, 0x7f]
+    toggle_not_immediate: 0
+  - state0_message: [0xb1, 11, 0]
+    state1_message: [0xb1, 12, 0x7f]
+    toggle_not_immediate: 0
+  - state0_message: [0xb1, 13, 0]
+    state1_message: [0xb1, 14, 0x7f]
+    toggle_not_immediate: 0
+  - state0_message: [0xb1, 15, 0]
+    state1_message: [0xb1, 16, 0x7f]
+    toggle_not_immediate: 0
+import argparse
+import yaml
+import time
+import pdb
+import midi_tester
+
+STARTUP_DELAY = 1.5
+
+from arduino import Arduino
+
+#   0xF0 0x78 0xCMD 0xBANK 0xSWITCH 0xTOGGLE 0xS00 0xS01 0xS02 0xS10 0xS11 0xS12 0xF7
+SYSEX_PREAMBLE='\xf0\x78\x00'
+SYSEX_POSTAMBLE='\xf7'
+
+def upload_config(data, arduino):
+  for b in xrange(len(data['bank'])):
+    for s in xrange(len(data['bank'][b]['switch'])):
+      switch= data['bank'][b]['switch'][s]
+      print switch
+      command = build_sysex_command(b, s, switch['toggle_not_immediate'], switch['state0_message'], switch['state1_message'])
+      print 'Configuring bank %d switch %d' % (b, s)
+      a.flush()
+      arduino.send(command)
+      
+def build_sysex_command(bank, switch, toggle, message0, message1):
+  command = SYSEX_PREAMBLE
+  command += chr(bank) + chr(switch) + chr(toggle) 
+  m0 = ''.join( [chr(m) for m in message0] )
+  m1 = ''.join( [chr(m) for m in message1] )
+  command += m0 + m1 + SYSEX_POSTAMBLE
+  return command
+  
+
+if __name__ == '__main__':
+  a = Arduino('/dev/tty.usbmodem24371', 31250)
+  time.sleep(STARTUP_DELAY)
+  f=open('config.yaml', 'r')
+  
+  data = yaml.load(f)
+
+  upload_config(data, a)
+
+  midi_tester.test_midi(a) 

full_default.yaml

+bank:
+- switch:
+  - state0_message: [247, 11, 0]
+    state1_message: [247, 11, 247]
+    toggle_not_immediate: 1
+  - state0_message: [247, 12, 0]
+    state1_message: [247, 12, 247]
+    toggle_not_immediate: 1
+  - state0_message: [247, 13, 0]
+    state1_message: [247, 13, 247]
+    toggle_not_immediate: 1
+  - state0_message: [247, 14, 0]
+    state1_message: [247, 14, 247]
+    toggle_not_immediate: 1
+- switch:
+  - state0_message: [247, 15, 0]
+    state1_message: [247, 15, 247]
+    toggle_not_immediate: 0
+  - state0_message: [247, 16, 0]
+    state1_message: [247, 16, 247]
+    toggle_not_immediate: 0
+  - state0_message: [247, 17, 0]
+    state1_message: [247, 17, 247]
+    toggle_not_immediate: 0
+  - state0_message: [247, 18, 0]
+    state1_message: [247, 18, 247]
+    toggle_not_immediate: 0
 #!/usr/bin/env python
 import serial
+from arduino import Arduino
 
-class Arduino():
- 
-  def __init__(self, path='/dev/tty.usbserial', baud=9600):
-    self.serial = serial.Serial(path, baud)   
- 
-  def send(self, data):
-    self.serial.write(data)
- 
-  def read(self, bytes):
-    while (1):
-      if (self.serial.inWaiting() > bytes-1):
-        return self.serial.read(bytes)
- 
-  def flush(self):
-    self.serial.flushInput()
+def test_midi(a):
 
+  command= "foo"
 
-def decode_command(command):
-  pass
+  while (ord(command[1]) != 0xf):
+    command = a.read(3)
+    print hex(ord(command[0])), hex(ord(command[1])), hex(ord(command[2]))
 
 if __name__ == '__main__':
   # drop to console for test with python -i 
   a = Arduino('/dev/tty.usbmodem24371', 31250)
 
-  cnt = 0
   command= "foo"
 
-  while (ord(command[1]) != 0xf):
-    command = a.read(3)
-    print hex(ord(command[0])), hex(ord(command[1])), hex(ord(command[2]))
-    if(cnt == 0):
-      a.send('\xf0\x78\x00\x01\x00\x00\xb1\x02\x63\xb1\x03\x61\xf7')
-      cnt = 1
+  test_midi(a)
+  
+  a.send('\xf0\x78\x00\x01\x00\x00\xb1\x02\x63\xb1\x03\x61\xf7')
+  test_midi(a)