[Armadeus-commitlog] armadeus branch, master, updated. armadeus-5.2-214-gb0082e5
Brought to you by:
sszy
|
From: SebR <se...@us...> - 2013-03-28 18:19:46
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "armadeus".
The branch, master has been updated
via b0082e5ebb26d5f478dd1238930e5f5d20648598 (commit)
from 2d500d401ef64a8f713ab561e6bee3800e9c4c0d (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit b0082e5ebb26d5f478dd1238930e5f5d20648598
Author: Sebastien Royen <seb...@ar...>
Date: Thu Mar 28 19:18:41 2013 +0100
[as_devices] add basic power_supply interface (limited)
-----------------------------------------------------------------------
Summary of changes:
target/packages/as_devices/c/Makefile | 1 +
target/packages/as_devices/c/as_power_supply.c | 153 ++++++++++++++++++++++++
target/packages/as_devices/c/as_power_supply.h | 90 ++++++++++++++
3 files changed, 244 insertions(+), 0 deletions(-)
create mode 100644 target/packages/as_devices/c/as_power_supply.c
create mode 100644 target/packages/as_devices/c/as_power_supply.h
diff --git a/target/packages/as_devices/c/Makefile b/target/packages/as_devices/c/Makefile
index b4cd6c0..53ba79a 100644
--- a/target/packages/as_devices/c/Makefile
+++ b/target/packages/as_devices/c/Makefile
@@ -26,6 +26,7 @@ OBJ += as_max5821.o
OBJ += as_backlight.o
OBJ += as_i2c_eeprom.o
OBJ += as_helpers.o
+OBJ += as_power_supply.o
LIBRARY=as_devices
LIB_VERS=1
diff --git a/target/packages/as_devices/c/as_power_supply.c b/target/packages/as_devices/c/as_power_supply.c
new file mode 100644
index 0000000..4f0083c
--- /dev/null
+++ b/target/packages/as_devices/c/as_power_supply.c
@@ -0,0 +1,153 @@
+/*
+ ** C wrapper for GPIOs usage.
+ **
+ ** Copyright (C) 2013 The Armadeus Project - ARMadeus Systems
+ ** Sébastien Royen <seb...@ar...>
+ **
+ ** This library is free software; you can redistribute it and/or
+ ** modify it under the terms of the GNU Lesser General Public
+ ** License as published by the Free Software Foundation; either
+ ** version 2.1 of the License, or (at your option) any later version.
+ **
+ ** This library 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
+ ** Lesser General Public License for more details.
+ **
+ ** You should have received a copy of the GNU Lesser General Public
+ ** License along with this library; if not, write to the Free Software
+ ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h> /* for close() */
+#include <errno.h>
+
+#define DEBUG
+#include "as_helpers.h"
+#include "as_power_supply.h"
+
+#define SYS_CLASS_POWER_SUPPLY_PATH "/sys/class/power_supply"
+
+/*------------------------------------------------------------------------------*/
+
+struct as_power_supply_device *as_power_supply_open(char *a_power_supply_name)
+{
+ struct as_power_supply_device *dev;
+ char buf[128];
+ char *fake_root;
+
+ fake_root = as_helpers_get_root();
+
+ dev = malloc(sizeof(struct as_power_supply_device));
+ if (dev == NULL) {
+ ERROR("Can't allocate as_power_supply_device structure\n");
+ } else {
+ snprintf(dev->power_supply_name, sizeof(dev->power_supply_name), "%s", a_power_supply_name);
+
+ snprintf(buf, sizeof(buf), "%s"SYS_CLASS_POWER_SUPPLY_PATH"/%s/online",
+ fake_root, dev->power_supply_name);
+ dev->file_online = open(buf, O_RDONLY);
+ if (dev->file_online < 0) {
+ ERROR("Can't open %s\n", buf);
+ }
+
+ snprintf(buf, sizeof(buf), "%s"SYS_CLASS_POWER_SUPPLY_PATH"/%s/status",
+ fake_root, dev->power_supply_name);
+ dev->file_status = open(buf, O_RDONLY);
+ if (dev->file_status < 0) {
+ ERROR("Can't open %s\n", buf);
+ }
+
+ snprintf(buf, sizeof(buf), "%s"SYS_CLASS_POWER_SUPPLY_PATH"/%s/capacity",
+ fake_root, dev->power_supply_name);
+ dev->file_capacity = open(buf, O_RDONLY);
+ if (dev->file_capacity < 0) {
+ ERROR("Can't open %s\n", buf);
+ }
+ }
+ return dev;
+}
+
+/*------------------------------------------------------------------------------*/
+
+int32_t as_power_supply_close(struct as_power_supply_device *a_power_supply_dev)
+{
+ if(a_power_supply_dev == NULL){
+ ERROR("device is NULL\n");
+ return -1;
+ }
+ if (a_power_supply_dev->file_online >= 0)
+ close(a_power_supply_dev->file_online);
+ if (a_power_supply_dev->file_status >= 0)
+ close(a_power_supply_dev->file_status);
+ if (a_power_supply_dev->file_capacity >= 0)
+ close(a_power_supply_dev->file_capacity);
+ free(a_power_supply_dev);
+ return 0;
+}
+
+/*------------------------------------------------------------------------------*/
+
+int32_t as_power_supply_is_online(struct as_power_supply_device *a_power_supply_dev)
+{
+ int32_t value;
+ int32_t ret;
+
+ value = -1;
+ if (a_power_supply_dev->file_online != -1) {
+ ret = as_read_int(a_power_supply_dev->file_online, &value);
+ if (ret < 0) {
+ ERROR("Can't read input file\n");
+ value = -1;
+ }
+ }
+
+ return value;
+}
+
+/*------------------------------------------------------------------------------*/
+
+int32_t as_power_supply_get_status(struct as_power_supply_device *a_power_supply_dev,
+ char *a_buffer, uint32_t a_length)
+{
+ int32_t ret;
+
+ ret = -1;
+ if (a_power_supply_dev->file_status != -1) {
+ ret = as_read_buffer(a_power_supply_dev->file_status, a_buffer, a_length);
+ if (ret < 0) {
+ ERROR("Can't read input file\n");
+ } else {
+ if (ret < a_length)
+ a_buffer[ret] = 0;
+ else
+ a_buffer[a_length - 1] = 0;
+ }
+ }
+
+ return ret;
+}
+
+/*------------------------------------------------------------------------------*/
+
+int32_t as_power_supply_get_capacity(struct as_power_supply_device *a_power_supply_dev)
+{
+ int32_t value;
+ int32_t ret;
+
+ value = -1;
+ if (a_power_supply_dev->file_capacity != -1) {
+ ret = as_read_int(a_power_supply_dev->file_capacity, &value);
+ if (ret < 0) {
+ ERROR("Can't read input file\n");
+ value = -1;
+ }
+ }
+
+ return value;
+}
+
+/*------------------------------------------------------------------------------*/
diff --git a/target/packages/as_devices/c/as_power_supply.h b/target/packages/as_devices/c/as_power_supply.h
new file mode 100644
index 0000000..394452c
--- /dev/null
+++ b/target/packages/as_devices/c/as_power_supply.h
@@ -0,0 +1,90 @@
+/*
+** The ARMadeus Project
+**
+** Copyright (C) 2013 The armadeus systems team
+** Sébastien Royen <seb...@ar...>
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License as published by the Free Software Foundation; either
+** version 2.1 of the License, or (at your option) any later version.
+**
+** This library 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
+** Lesser General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public
+** License along with this library; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#ifndef __ASPOWERSUPPLY_H__
+#define __ASPOWERSUPPLY_H__
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+
+/**
+ * Store power supplier parameters
+ */
+struct as_power_supply_device {
+ char power_supply_name[32];
+ int file_online;
+ int file_capacity;
+ int file_status;
+};
+
+
+/** @brief Initialize power supply access
+ *
+ * @param a_power_supply_name char* name of the power supplier
+ *
+ * @return NULL on error
+ */
+struct as_power_supply_device *as_power_supply_open(char *a_power_supply_name);
+
+/** @brief Close power supply access
+ *
+ * @param a_power_supply_dev as_power_supply_device pointer structure
+ *
+ * @return error if negative
+ */
+int32_t as_power_supply_close(struct as_power_supply_device *a_led_dev);
+
+/** @brief Get online state
+ *
+ * @param a_power_supply_dev as_power_supply_device pointer structure
+ *
+ * @return 1 if power supply active, 0 otherwise
+ */
+int32_t as_power_supply_is_online(struct as_power_supply_device *a_power_supply_dev);
+
+/** @brief Get online state
+ *
+ * @param a_power_supply_dev as_power_supply_device pointer structure
+ * @param a_buffer char pointer to receive status as text
+ * @param a_length uint32_t buffer size
+ *
+ * @return -1 on error, 0 on success
+ */
+int32_t as_power_supply_get_status(struct as_power_supply_device *a_power_supply_dev,
+ char *a_buffer, uint32_t a_length);
+
+/** @brief Get capacity
+ *
+ * @param a_power_supply_dev as_power_supply_device pointer structure
+ *
+ * @return charge level in percent
+ */
+int32_t as_power_supply_get_capacity(struct as_power_supply_device *a_power_supply_dev);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __ASPOWERSUPPLY_H__ */
hooks/post-receive
--
armadeus
|