# mk_config.py # # Translate default FF.CFG into a C header. # # Written & released by Keir Fraser # # This is free and unencumbered software released into the public domain. # See the file COPYING for more details, or visit . import re, sys def main(argv): in_f = open(argv[1], "r") out_f = open(argv[2], "w") out_f.write("/* Autogenerated by " + argv[0] + " */\n") for line in in_f: match = re.match("[ \t]*([A-Za-z0-9-]+)[ \t]*=[ \t]*" "([A-Za-z0-9-,]+|\".*\")", line) if match: opt = match.group(1) val = match.group(2) if opt == "interface": val = "FINTF_" + val.upper().replace("-","_") elif opt == "pin02" or opt == "pin34": val = "PIN_" + val elif opt == "track-change": val = "TRKCHG_" + val elif opt == "write-drain": val = "WDRAIN_" + val elif opt == "host": val = "HOST_" + val elif opt == "oled-font": val = "FONT_" + val elif opt == "display-type": opts = [] for x in val.split("-"): size = re.match("([0-9]+)x([0-9]+)", x) if size: w = int(size.group(1)) h = int(size.group(2)) if w == 128 and h == 64: opts += ['DISPLAY_oled_64'] elif h >= 2 and h <= 4 and w >= 16 and w <= 40: opts += ['DISPLAY_lcd_columns(%d)' % w] opts += ['DISPLAY_lcd_rows(%d)' % h] else: opts += ['DISPLAY_' + x] val = '|'.join(opts) elif opt == "notify-volume": opts = [] for x in val.split(","): vol = re.match("([0-9]+)", x) if vol: opts.append(vol.group(1)) else: opts.append('NOTIFY_' + x) val = '|'.join(opts) elif opt == "display-order" or opt == "osd-display-order": if val == "default": val = "DORD_" + val else: v = 0 sh = 0 for x in val.split(","): o = re.match("([0-9])(d?)", x) v |= int(o.group(1)) << sh if o.group(2) == "d": v |= 8 << sh sh += 4 while sh < 16: v |= 7 << sh sh += 4 val = str(v) elif opt == "image-on-startup": val = "IMGS_" + val elif opt == "rotary": opts = [] for x in val.split(","): opts += ['ROT_' + x] val = '|'.join(opts) elif opt == "twobutton-action": opts = [] for x in val.split(","): opts += ['TWOBUTTON_' + x.replace("-","_")] val = '|'.join(opts) elif opt == "nav-mode": val = "NAVMODE_" + val elif opt == "folder-sort": val = "SORT_" + val elif opt == "sort-priority": val = "SORTPRI_" + val elif opt == "display-on-activity": val = "DISPON_" + val elif opt == "motor-delay": if val == 'ignore': val = "MOTOR_" + val else: val = (int(val) + 9) // 10 elif opt == "chgrst": delay = re.match("delay-([0-9]+)", val) if delay: val = 'delay(%d)' % int(delay.group(1)) val = "CHGRST_" + val else: val = { 'no': 'FALSE', 'yes': 'TRUE' }.get(val,val) out_f.write("x(%s, %s, %s)\n" % (opt, re.sub('-','_',opt), val)) if __name__ == "__main__": main(sys.argv)