From www.AA6E.net
Jump to: navigation, search

Protocol for using the FlexRadio Systems FlexControl via /dev/ttyACM0 on Linux. (See also my blog post.)

FlexControl codes
AA6E 1/2015

Send to host:
All terminate with ';'
U - knob CW -- U02, U03, U04, etc - fast CW
D - know CCW-- D02, D03, D04, etc - fast CCW
S - short press, main knob
L - long press
C - fast double click

XnS - short press, key n=1,2,3
XnL - long press
XnC - fast double click

Send to flexcontrol

Ixyz;  where x,y,z = 1/0, LED 0, 1, 2 on/off
e.g.
I001; set right hand LED on
I000; set all LEDs off

A little Python program that uses the LEDs to count knob ticks.

#!/usr/bin/env python

# flexcounter.py
# A simple program to show reading & writing to FlexControl

DEVICE = "/dev/ttyACM0"

print "FlexControl Python demo - Martin Ewing AA6E 1/2015"
print "Spin the big knob!"

inf = open(DEVICE,'rb')
ouf = open(DEVICE,'wb')
count = 0
# Initialize LEDs off
ouf.write('I000;')
ouf.flush()

while True:
    # Collect a ;-terminated data chunk from FlexControl
    c = cmd = ''
    while c != ';':
        c = inf.read(1)
        cmd += c
    # Check type of data: U up or D down, ignore others
    x1 = cmd[0]
    drn = 0
    if x1 == 'U':
        drn = 1
    elif x1 == 'D':
        drn = -1
    if drn != 0:
        # Step the counter up or down, allowing for multiple counts like U02;
        step = 1
        if len(cmd)>2:
            step = int(cmd[1:3])
        count += step*drn
        # Convert count to binary string, using low order 3 bits
        bcount = '{0:03b}'.format(count)[-3:]
        print "%6d, %s" % (count, bcount)
        ouf.write("I%s;" % bcount)
        ouf.flush()