|
| 1 | +#!/usr/bin/python |
| 2 | +# |
| 3 | +# Script decode 'screen data' from Zoom G1Four |
| 4 | +# (c) Simon Wood, 10 Dec 2020 |
| 5 | +# |
| 6 | +# read with: |
| 7 | +# $ amidi -p hw:1,0,0 -S 'F0 52 00 6e 64 02 00 09 00 F7' -r temp.bin -t 2 |
| 8 | +# |
| 9 | + |
| 10 | +from construct import * |
| 11 | + |
| 12 | +#-------------------------------------------------- |
| 13 | +# Define ZPTC file format using Construct (v2.9) |
| 14 | +# requires: |
| 15 | +# https://github.com/construct/construct |
| 16 | + |
| 17 | +Type = Struct( |
| 18 | + Enum(Byte, |
| 19 | + VALUE = 0x00, |
| 20 | + NAME = 0x01, |
| 21 | + INVERT = 0x07, |
| 22 | + ), |
| 23 | +) |
| 24 | + |
| 25 | +Info = Struct( |
| 26 | + "screen1" / Byte, |
| 27 | + "param1" / Byte, |
| 28 | + "type1" / Embedded(Type), |
| 29 | + "invert1" / Byte, |
| 30 | + "value" / PaddedString(10, "ascii"), |
| 31 | + |
| 32 | + "screen2" / Byte, |
| 33 | + "param2" / Byte, |
| 34 | + "type2" / Embedded(Type), |
| 35 | + "invert2" / Byte, |
| 36 | + "name" / PaddedString(10, "ascii"), |
| 37 | +) |
| 38 | + |
| 39 | +Screen = Struct( |
| 40 | + "info" / Array(6, Info), |
| 41 | +) |
| 42 | + |
| 43 | +Display = Struct( |
| 44 | + GreedyRange(Const(b"\x00")), # get rid of leading zeros |
| 45 | + Const(b"\xf0\x52\x00\x6e\x64\x01"), |
| 46 | + "screens" / GreedyRange(Screen), |
| 47 | + #Const(b"\xf7"), # not seen if we ask for too |
| 48 | + # many screens worth of data |
| 49 | +) |
| 50 | + |
| 51 | +#-------------------------------------------------- |
| 52 | +def main(): |
| 53 | + from optparse import OptionParser |
| 54 | + |
| 55 | + usage = "usage: %prog [options] FILENAME" |
| 56 | + parser = OptionParser(usage) |
| 57 | + parser.add_option("-d", "--dump", |
| 58 | + help="dump configuration to text", |
| 59 | + action="store_true", dest="dump") |
| 60 | + |
| 61 | + (options, args) = parser.parse_args() |
| 62 | + |
| 63 | + if len(args) != 1: |
| 64 | + parser.error("FILE not specified") |
| 65 | + |
| 66 | + infile = open(args[0], "rb") |
| 67 | + if not infile: |
| 68 | + sys.exit("Unable to open FILE for reading") |
| 69 | + else: |
| 70 | + data = infile.read() |
| 71 | + infile.close() |
| 72 | + |
| 73 | + if data: |
| 74 | + config = Display.parse(data) |
| 75 | + if options.dump: |
| 76 | + print(config) |
| 77 | + |
| 78 | + for screen in config['screens']: |
| 79 | + for info in screen['info']: |
| 80 | + if info['param1'] == 0: |
| 81 | + if info['name'] == "Dummy": |
| 82 | + on_off = None |
| 83 | + else: |
| 84 | + if info['value'] == "1": |
| 85 | + on_off = "On" |
| 86 | + else: |
| 87 | + on_off = "Off" |
| 88 | + print("---") |
| 89 | + elif info['param1'] == 1: |
| 90 | + if on_off: |
| 91 | + print("Effect: %s (%s)" % (info['name'], on_off)) |
| 92 | + else: |
| 93 | + if info['name'] != "Dummy": |
| 94 | + print("%s : %s" % (info['name'], info['value'])) |
| 95 | + |
| 96 | + |
| 97 | +if __name__ == "__main__": |
| 98 | + main() |
| 99 | + |
0 commit comments