source: mainline/uspace/lib/c/generic/device/battery_dev.c@ dba3e2c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since dba3e2c was 917797f, checked in by Maurizio Lombardi <m.lombardi85@…>, 13 years ago

Add support to the battery interface, not tested yet

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 * Copyright (c) 2012 Maurizio Lombardi
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 /** @addtogroup libc
30 * @{
31 */
32/** @file
33 */
34
35#include <ipc/dev_iface.h>
36#include <device/battery_dev.h>
37#include <errno.h>
38#include <async.h>
39#include <time.h>
40
41/** Read the current battery status from the device
42 *
43 * @param sess Session of the device
44 * @param status Current status of the battery
45 *
46 * @return EOK on success or a negative error code
47 */
48int
49battery_status_get(async_sess_t *sess, battery_status_t *batt_status)
50{
51 sysarg_t status;
52
53 async_exch_t *exch = async_exchange_begin(sess);
54
55 int const rc = async_req_1_1(exch, DEV_IFACE_ID(BATTERY_DEV_IFACE),
56 BATTERY_STATUS_GET, &status);
57
58 async_exchange_end(exch);
59
60 if (rc == EOK)
61 *batt_status = (battery_status_t) status;
62
63 return rc;
64}
65
66/** Read the current battery charge level from the device
67 *
68 * @param sess Session of the device
69 * @param level Battery charge level (0 - 100)
70 *
71 * @return EOK on success or a negative error code
72 */
73int
74battery_charge_level_get(async_sess_t *sess, int *level)
75{
76 sysarg_t charge_level;
77
78 async_exch_t *exch = async_exchange_begin(sess);
79
80 int const rc = async_req_1_1(exch, DEV_IFACE_ID(BATTERY_DEV_IFACE),
81 BATTERY_CHARGE_LEVEL_GET, &charge_level);
82
83 async_exchange_end(exch);
84
85 if (rc == EOK)
86 *level = (int) charge_level;
87
88 return rc;
89}
90
91/** @}
92 */
93
Note: See TracBrowser for help on using the repository browser.