diff options
Diffstat (limited to 'meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_gpios.py')
-rw-r--r-- | meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_gpios.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_gpios.py b/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_gpios.py new file mode 100644 index 0000000..340c5c3 --- /dev/null +++ b/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_gpios.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +# +# Copyright 2014-present Facebook. All Rights Reserved. +# +# This program file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program in a file named COPYING; if not, write to the +# Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301 USA +# + +from rest_fruid import get_fruid + +WEDGES = ["Wedge-AC-F", "Wedge-DC-F"] + + +def read_gpio_sysfs(gpio): + with open('/sys/class/gpio/gpio%d/value' % gpio, 'r') as f: + val_string = f.read() + if val_string == '1\n': + return 1 + if val_string == '0\n': + return 0 + return None + + +def read_wedge_back_ports(): + bhinfo = { "port_1": { "pin_1": read_gpio_sysfs(120), + "pin_2": read_gpio_sysfs(121), + "pin_3": read_gpio_sysfs(122), + "pin_4": read_gpio_sysfs(123) + }, + "port_2": { "pin_1": read_gpio_sysfs(124), + "pin_2": read_gpio_sysfs(125), + "pin_3": read_gpio_sysfs(126), + "pin_4": read_gpio_sysfs(52) + } + } + return bhinfo + + +def get_gpios(): + fruinfo = get_fruid() + gpioinfo = {} + if fruinfo["Information"]["Product Name"] in WEDGES: + gpioinfo["back_ports"] = read_wedge_back_ports() + return gpioinfo |