James Feist | 5744423 | 2018-03-08 13:36:32 -0800 | [diff] [blame^] | 1 | #!/usr/bin/python |
| 2 | """ |
| 3 | This script sets muxes back to default values so that |
| 4 | during device parsing we are not left with an invisible |
| 5 | mux before the mux has been added to device tree. |
| 6 | |
| 7 | If we find a better way to take care of this, we should |
| 8 | remove this file. |
| 9 | """ |
| 10 | |
| 11 | import os |
| 12 | import json |
| 13 | import subprocess |
| 14 | |
| 15 | |
| 16 | CONFIGURATION_FILE = '/var/configuration/system.json' |
| 17 | MUX_TYPES = ['PCA9543Mux', 'PCA9545Mux'] |
| 18 | |
| 19 | if not os.path.isfile(CONFIGURATION_FILE): |
| 20 | print('No Configuration') |
| 21 | exit(0) |
| 22 | |
| 23 | configuration = json.load(open(CONFIGURATION_FILE)) |
| 24 | |
| 25 | for _, entity in configuration.iteritems(): |
| 26 | for exposed in entity.get('exposes', []): |
| 27 | if exposed.get('type', None) in MUX_TYPES: |
| 28 | bus = exposed.get('bus', False) |
| 29 | address = exposed.get('address', False) |
| 30 | if bus and address: |
| 31 | subprocess.call('i2cset -y -f {} {} 0'.format(bus, address), |
| 32 | shell=True) |