Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean Up Bitmasking Operations in Device Configuration #221

Open
kb1lqc opened this issue Jul 2, 2017 · 0 comments
Open

Clean Up Bitmasking Operations in Device Configuration #221

kb1lqc opened this issue Jul 2, 2017 · 0 comments

Comments

@kb1lqc
Copy link
Member

kb1lqc commented Jul 2, 2017

Summary

deviceconfiguration.py brute forces GPIO bitmask operations. This should be converted into a pragmatic function to reuse code and make the code cleaner to read.

Problem Explanation

This is being implemented in PR #219 so the link above will only work when that is pulled in. An example of the brute force includes the gpio variable fconfig.get() and fconfig.set() lines. This can be pragmatically cleaned up with a function that can arbitrarily change GPIO P3, GPIO P4, or GPIO P5 values.

# Detect and set GPIO P3 settings, create bitmask
if args.gpiop3on >= 0 and args.gpiop3on <= 7:
    if args.gpiop3on is not None:
        fconfig.set('BASIC', 'GPIO_P3_' + str(args.gpiop3on), 1)
if args.gpiop3off >= 0 and args.gpiop3off <= 7:
    if args.gpiop3off is not None:
        fconfig.set('BASIC', 'GPIO_P3_' + str(args.gpiop3off), 0)

gpiomask = [0] * 8
if not args.gpiop3clear:
    gpio0 = fconfig.get('BASIC', 'GPIO_P3_0')
    gpio1 = fconfig.get('BASIC', 'GPIO_P3_1')
    gpio2 = fconfig.get('BASIC', 'GPIO_P3_2')
    gpio3 = fconfig.get('BASIC', 'GPIO_P3_3')
    gpio4 = fconfig.get('BASIC', 'GPIO_P3_4')
    gpio5 = fconfig.get('BASIC', 'GPIO_P3_5')
    gpio6 = fconfig.get('BASIC', 'GPIO_P3_6')
    gpio7 = fconfig.get('BASIC', 'GPIO_P3_7')
    gpiomask = [gpio7, gpio6, gpio5, gpio4, gpio3, gpio2, gpio1, gpio0]
if args.gpiop3clear:
    fconfig.set('BASIC', 'GPIO_P3_0', 0)
    fconfig.set('BASIC', 'GPIO_P3_1', 0)
    fconfig.set('BASIC', 'GPIO_P3_2', 0)
    fconfig.set('BASIC', 'GPIO_P3_3', 0)
    fconfig.set('BASIC', 'GPIO_P3_4', 0)
    fconfig.set('BASIC', 'GPIO_P3_5', 0)
    fconfig.set('BASIC', 'GPIO_P3_6', 0)
    fconfig.set('BASIC', 'GPIO_P3_7', 0)

gpiop3bitmask = eightBitListToInt(gpiomask)
fconfig.set('BASIC', 'GPIO_P3', gpiop3bitmask)

Environment

Software

Master branch Faraday Software after PR #219 is pulled in.

Hardware

N/A

Supporting Information

N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant