summaryrefslogtreecommitdiffstats
path: root/utils/nwztools/plattools/nwz_lib.h
blob: 1dd7b4c85b9c018ea6c23d7b0f69f0881b0d7a41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2016 Amaury Pouly
 *
 * This program 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; either version 2
 * of the License, or (at your option) any later version.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/
#ifndef _NWZLIB_H_
#define _NWZLIB_H_

#include <stdio.h>
#include <stdbool.h>
#include <stdarg.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <linux/input.h>
#include <fcntl.h>
#include <string.h>

#include "nwz_keys.h"
#include "nwz_fb.h"
#include "nwz_adc.h"
#include "nwz_ts.h"
#include "nwz_power.h"

/* run a program and exit with nonzero status in case of error
 * argument list must be NULL terminated */
void nwz_run(const char *file, const char *args[], bool wait);

/* invoke /usr/bin/lcdmsg to display a message using the small font, optionally
 * clearing the screen before */
void nwz_lcdmsg(bool clear, int x, int y, const char *msg);
void nwz_lcdmsgf(bool clear, int x, int y, const char *format, ...);

/* open icx_key input device and return file descriptor */
int nwz_key_open(void);
void nwz_key_close(int fd);
/* return HOLD status: 0 or 1, or -1 on error */
int nwz_key_get_hold_status(int fd);
/* wait for an input event (and return 1), or a timeout (return 0), or error (-1)
 * set the timeout to -1 to block */
int nwz_key_wait_event(int fd, long tmo_us);
/* read an event from the device (may block unless you waited for an event before),
 * return 1 on success, <0 on error */
int nwz_key_read_event(int fd, struct input_event *evt);
/* return keycode from event */
int nwz_key_event_get_keycode(struct input_event *evt);
/* return press/released status from event */
bool nwz_key_event_is_press(struct input_event *evt);
/* return HOLD status from event */
bool nwz_key_event_get_hold_status(struct input_event *evt);
/* get keycode name */
const char *nwz_key_get_name(int keycode);

/* open framebuffer device */
int nwz_fb_open(bool lcd);
/* close framebuffer device */
void nwz_fb_close(int fb);
/* get backlight brightness (return -1 on error, 1 on success) */
int nwz_fb_get_brightness(int fd, struct nwz_fb_brightness *bl);
/* set backlight brightness (return -1 on error, 1 on success) */
int nwz_fb_set_brightness(int fd, struct nwz_fb_brightness *bl);

/* open adc device */
int nwz_adc_open(void);
/* close adc device */
void nwz_adc_close(int fd);
/* get channel name */
const char *nwz_adc_get_name(int ch);
/* read channel value, return -1 on error */
int nwz_adc_get_val(int fd, int ch);

/* open touchscreen device */
int nwz_ts_open(void);
/* close touchscreen device */
void nwz_ts_close(int fd);
/* structure to track touch state */
struct nwz_ts_state_t
{
    int x, y; /* current position (valid is touch is true) */
    int max_x, max_y; /* maximum possible values */
    int pressure, tool_width; /* current pressure and tool width */
    int max_pressure, max_tool_width; /* maximum possible values */
    bool touch; /* is the user touching the screen? */
    bool flick; /* was the action a flick? */
    int flick_x, flick_y; /* if so, this is the flick direction */
};
/* get touchscreen information and init state, return -1 on error, 1 on success */
int nwz_ts_state_init(int fd, struct nwz_ts_state_t *state);
/* update state with an event, return -1 on unhandled event, >=0 on handled:
 * 1 if sync event, 0 otherwise */
int nwz_ts_state_update(struct nwz_ts_state_t *state, struct input_event *evt);
/* update state after a sync event to prepare for next round of events */
int nwz_ts_state_post_syn(struct nwz_ts_state_t *state);
/* read at most N events from touch screen, and return the number of events */
int nwz_ts_read_events(int fd, struct input_event *evts, int nr_evts);

/* wait for events on several file descriptors, return a bitmap of active ones
 * or 0 on timeout, the timeout can be -1 to block */
long nwz_wait_fds(int *fds, int nr_fds, long timeout_us);

/* open power device */
int nwz_power_open(void);
/* close power device */
void nwz_power_close(int fd);
/* get power status (return -1 on error, bitmap on success) */
int nwz_power_get_status(int fd);
/* get vbus adval (or -1 on error) */
int nwz_power_get_vbus_adval(int fd);
/* get vbus voltage in mV (or -1 on error) */
int nwz_power_get_vbus_voltage(int fd);
/* get vbus current limit (or -1 on error) */
int nwz_power_get_vbus_limit(int fd);
/* get charge switch (or -1 on error) */
int nwz_power_get_charge_switch(int fd);
/* get charge current (or -1 on error) */
int nwz_power_get_charge_current(int fd);
/* get battery gauge (or -1 on error) */
int nwz_power_get_battery_gauge(int fd);
/* get battery adval (or -1 on error) */
int nwz_power_get_battery_adval(int fd);
/* get battery voltage in mV (or -1 on error) */
int nwz_power_get_battery_voltage(int fd);
/* get vbat adval (or -1 on error) */
int nwz_power_get_vbat_adval(int fd);
/* get vbat voltage (or -1 on error) */
int nwz_power_get_vbat_voltage(int fd);
/* get sample count (or -1 on error) */
int nwz_power_get_sample_count(int fd);
/* get vsys adval (or -1 on error) */
int nwz_power_get_vsys_adval(int fd);
/* get vsys voltage in mV (or -1 on error) */
int nwz_power_get_vsys_voltage(int fd);
/* get accessory charge mode */
int nwz_power_get_acc_charge_mode(int fd);
/* is battery fully charged? (or -1 on error) */
int nwz_power_is_fully_charged(int fd);

#endif /* _NWZLIB_H_ */