1
0
Fork 0
forked from len0rd/rockbox

nwztools/plattools: add test_power, rework input, add test_ts (touchscreen)

Change-Id: I55ca29627801b5e760d1dbe407d96cd055f659ab
This commit is contained in:
Amaury Pouly 2016-10-20 18:21:00 +02:00
parent fed083cf06
commit d42b43c786
8 changed files with 685 additions and 17 deletions

View file

@ -21,7 +21,7 @@
#ifndef __NWZ_KEYS_H__ #ifndef __NWZ_KEYS_H__
#define __NWZ_KEYS_H__ #define __NWZ_KEYS_H__
#define NWZ_KEY_DEV "/dev/input/event0" #define NWZ_KEY_NAME "icx_key"
/* The Sony icx_key driver reports keys via the /dev/input/event0 device and /* The Sony icx_key driver reports keys via the /dev/input/event0 device and
* abuses the standard struct input_event. The input_event.code is split into * abuses the standard struct input_event. The input_event.code is split into

View file

@ -69,9 +69,29 @@ void nwz_lcdmsgf(bool clear, int x, int y, const char *format, ...)
nwz_lcdmsg(clear, x, y, buffer); nwz_lcdmsg(clear, x, y, buffer);
} }
int nwz_input_open(const char *requested_name)
{
/* try all /dev/input/eventX, there can't a lot of them */
for(int index = 0; index < 8; index++)
{
char buffer[32];
sprintf(buffer, "/dev/input/event%d", index);
int fd = open(buffer, O_RDWR);
if(fd < 0)
continue; /* try next one */
/* query name */
char name[256];
if(ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0 &&
strcmp(name, requested_name) == 0)
return fd;
close(fd);
}
return -1;
}
int nwz_key_open(void) int nwz_key_open(void)
{ {
return open(NWZ_KEY_DEV, O_RDONLY); return nwz_input_open(NWZ_KEY_NAME);
} }
void nwz_key_close(int fd) void nwz_key_close(int fd)
@ -89,20 +109,7 @@ int nwz_key_get_hold_status(int fd)
int nwz_key_wait_event(int fd, long tmo_us) int nwz_key_wait_event(int fd, long tmo_us)
{ {
fd_set rfds; return nwz_wait_fds(&fd, 1, tmo_us);
struct timeval tv;
struct timeval *tv_ptr = NULL;
/* watch the input device */
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
/* setup timeout */
if(tmo_us >= 0)
{
tv.tv_sec = 0;
tv.tv_usec = tmo_us;
tv_ptr = &tv;
}
return select(fd + 1, &rfds, NULL, NULL, tv_ptr);
} }
int nwz_key_read_event(int fd, struct input_event *evt) int nwz_key_read_event(int fd, struct input_event *evt)
@ -219,3 +226,250 @@ int nwz_adc_get_val(int fd, int ch)
else else
return val; return val;
} }
int nwz_ts_open(void)
{
return nwz_input_open(NWZ_TS_NAME);
}
void nwz_ts_close(int fd)
{
close(fd);
}
int nwz_ts_state_init(int fd, struct nwz_ts_state_t *state)
{
memset(state, 0, sizeof(struct nwz_ts_state_t));
struct input_absinfo info;
if(ioctl(fd, EVIOCGABS(ABS_X), &info) < 0)
return -1;
state->max_x = info.maximum;
if(ioctl(fd, EVIOCGABS(ABS_Y), &info) < 0)
return -1;
state->max_y = info.maximum;
if(ioctl(fd, EVIOCGABS(ABS_PRESSURE), &info) < 0)
return -1;
state->max_pressure = info.maximum;
if(ioctl(fd, EVIOCGABS(ABS_TOOL_WIDTH), &info) < 0)
return -1;
state->max_tool_width = info.maximum;
return 1;
}
int nwz_ts_state_update(struct nwz_ts_state_t *state, struct input_event *evt)
{
switch(evt->type)
{
case EV_SYN:
return 1;
case EV_REL:
if(evt->code == REL_RX)
state->flick_x = evt->value;
else if(evt->code == REL_RY)
state->flick_y = evt->value;
else
return -1;
state->flick = true;
break;
case EV_ABS:
if(evt->code == ABS_X)
state->x = evt->value;
else if(evt->code == ABS_Y)
state->y = evt->value;
else if(evt->code == ABS_PRESSURE)
state->pressure = evt->value;
else if(evt->code == ABS_TOOL_WIDTH)
state->tool_width = evt->value;
else
return -1;
break;
case EV_KEY:
if(evt->code == BTN_TOUCH)
state->touch = evt->value;
else
return -1;
break;
default:
return -1;
}
return 0;
}
int nwz_ts_state_post_syn(struct nwz_ts_state_t *state)
{
state->flick = false;
return 1;
}
int nwz_ts_read_events(int fd, struct input_event *evts, int nr_evts)
{
int ret = read(fd, evts, nr_evts * sizeof(struct input_event));
if(ret < 0)
return -1;
return ret / sizeof(struct input_event);
}
long nwz_wait_fds(int *fds, int nr_fds, long tmo_us)
{
fd_set rfds;
struct timeval tv;
struct timeval *tv_ptr = NULL;
/* watch the input device */
FD_ZERO(&rfds);
int max_fd = 0;
for(int i = 0; i < nr_fds; i++)
{
FD_SET(fds[i], &rfds);
if(fds[i] > max_fd)
max_fd = fds[i];
}
/* setup timeout */
if(tmo_us >= 0)
{
tv.tv_sec = 0;
tv.tv_usec = tmo_us;
tv_ptr = &tv;
}
int ret = select(max_fd + 1, &rfds, NULL, NULL, tv_ptr);
if(ret <= 0)
return ret;
long bitmap = 0;
for(int i = 0; i < nr_fds; i++)
if(FD_ISSET(fds[i], &rfds))
bitmap |= 1 << i;
return bitmap;
}
int nwz_power_open(void)
{
return open(NWZ_POWER_DEV, O_RDWR);
}
void nwz_power_close(int fd)
{
close(fd);
}
int nwz_power_get_status(int fd)
{
int status;
if(ioctl(fd, NWZ_POWER_GET_STATUS, &status) < 0)
return -1;
return status;
}
static int nwz_power_adval_to_mv(int adval, int ad_base)
{
if(adval == -1)
return -1;
/* the AD base corresponds to the millivolt value if adval was 255 */
return (adval * ad_base) / 255;
}
int nwz_power_get_vbus_adval(int fd)
{
int status;
if(ioctl(fd, NWZ_POWER_GET_VBUS_ADVAL, &status) < 0)
return -1;
return status;
}
int nwz_power_get_vbus_voltage(int fd)
{
return nwz_power_adval_to_mv(nwz_power_get_vbus_adval(fd), NWZ_POWER_AD_BASE_VBUS);
}
int nwz_power_get_vbus_limit(int fd)
{
int status;
if(ioctl(fd, NWZ_POWER_GET_VBUS_LIMIT, &status) < 0)
return -1;
return status;
}
int nwz_power_get_charge_switch(int fd)
{
int status;
if(ioctl(fd, NWZ_POWER_GET_CHARGE_SWITCH, &status) < 0)
return -1;
return status;
}
int nwz_power_get_charge_current(int fd)
{
int status;
if(ioctl(fd, NWZ_POWER_GET_CHARGE_CURRENT, &status) < 0)
return -1;
return status;
}
int nwz_power_get_battery_gauge(int fd)
{
int status;
if(ioctl(fd, NWZ_POWER_GET_BAT_GAUGE, &status) < 0)
return -1;
return status;
}
int nwz_power_get_battery_adval(int fd)
{
int status;
if(ioctl(fd, NWZ_POWER_GET_BAT_ADVAL, &status) < 0)
return -1;
return status;
}
int nwz_power_get_battery_voltage(int fd)
{
return nwz_power_adval_to_mv(nwz_power_get_battery_adval(fd), NWZ_POWER_AD_BASE_VBAT);
}
int nwz_power_get_vbat_adval(int fd)
{
int status;
if(ioctl(fd, NWZ_POWER_GET_VBAT_ADVAL, &status) < 0)
return -1;
return status;
}
int nwz_power_get_vbat_voltage(int fd)
{
return nwz_power_adval_to_mv(nwz_power_get_vbat_adval(fd), NWZ_POWER_AD_BASE_VBAT);
}
int nwz_power_get_sample_count(int fd)
{
int status;
if(ioctl(fd, NWZ_POWER_GET_SAMPLE_COUNT, &status) < 0)
return -1;
return status;
}
int nwz_power_get_vsys_adval(int fd)
{
int status;
if(ioctl(fd, NWZ_POWER_GET_VSYS_ADVAL, &status) < 0)
return -1;
return status;
}
int nwz_power_get_vsys_voltage(int fd)
{
return nwz_power_adval_to_mv(nwz_power_get_vsys_adval(fd), NWZ_POWER_AD_BASE_VSYS);
}
int nwz_power_get_acc_charge_mode(int fd)
{
int status;
if(ioctl(fd, NWZ_POWER_GET_ACCESSARY_CHARGE_MODE, &status) < 0)
return -1;
return status;
}
int nwz_power_is_fully_charged(int fd)
{
int status;
if(ioctl(fd, NWZ_POWER_IS_FULLY_CHARGED, &status) < 0)
return -1;
return status;
}

View file

@ -29,10 +29,13 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <linux/input.h> #include <linux/input.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h>
#include "nwz_keys.h" #include "nwz_keys.h"
#include "nwz_fb.h" #include "nwz_fb.h"
#include "nwz_adc.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 /* run a program and exit with nonzero status in case of error
* argument list must be NULL terminated */ * argument list must be NULL terminated */
@ -81,4 +84,70 @@ const char *nwz_adc_get_name(int ch);
/* read channel value, return -1 on error */ /* read channel value, return -1 on error */
int nwz_adc_get_val(int fd, int ch); 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_ */ #endif /* _NWZLIB_H_ */

View file

@ -0,0 +1,82 @@
/***************************************************************************
* __________ __ ___.
* 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 __NWZ_POWER_H__
#define __NWZ_POWER_H__
#define NWZ_POWER_DEV "/dev/icx_power"
#define NWZ_POWER_TYPE 'P'
/* ioctl request */
#define NWZ_POWER_GET_STATUS _IOR(NWZ_POWER_TYPE, 0, int *)
#define NWZ_POWER_SET_VBUS_LIMIT _IOW(NWZ_POWER_TYPE, 1, int *)
#define NWZ_POWER_GET_BAT_ADVAL _IOR(NWZ_POWER_TYPE, 2, int *)
#define NWZ_POWER_GET_BAT_GAUGE _IOR(NWZ_POWER_TYPE, 3, int *)
#define NWZ_POWER_ENABLE_CHARGER _IOW(NWZ_POWER_TYPE, 4, int *)
#define NWZ_POWER_ENABLE_DEBUG_PORT _IO (NWZ_POWER_TYPE, 5)
#define NWZ_POWER_IS_FULLY_CHARGED _IOR(NWZ_POWER_TYPE, 6, int *)
#define NWZ_POWER_AVG_VALUE _IO (NWZ_POWER_TYPE, 7)
#define NWZ_POWER_CONSIDERATION_CHARGE _IOW(NWZ_POWER_TYPE, 8, int)
#define NWZ_POWER_GET_VBUS_LIMIT _IOR(NWZ_POWER_TYPE, 9, int *)
#define NWZ_POWER_GET_CHARGE_SWITCH _IOR(NWZ_POWER_TYPE,10, int *)
#define NWZ_POWER_GET_SAMPLE_COUNT _IOR(NWZ_POWER_TYPE,11, int *)
#define NWZ_POWER_SET_CHARGE_CURRENT _IOW(NWZ_POWER_TYPE,12, int *)
#define NWZ_POWER_GET_CHARGE_CURRENT _IOR(NWZ_POWER_TYPE,13, int *)
#define NWZ_POWER_GET_VBUS_ADVAL _IOR(NWZ_POWER_TYPE,14, int *)
#define NWZ_POWER_GET_VSYS_ADVAL _IOR(NWZ_POWER_TYPE,15, int *)
#define NWZ_POWER_GET_VBAT_ADVAL _IOR(NWZ_POWER_TYPE,16, int *)
#define NWZ_POWER_CHG_VBUS_LIMIT _IOW(NWZ_POWER_TYPE,17, int *)
#define NWZ_POWER_SET_ACCESSARY_CHARGE_MODE _IOW(NWZ_POWER_TYPE,18, int *)
#define NWZ_POWER_GET_ACCESSARY_CHARGE_MODE _IOR(NWZ_POWER_TYPE,19, int *)
/* NWZ_POWER_GET_STATUS bitmap */
#define NWZ_POWER_STATUS_CHARGE_INIT 0x100 /* initializing charging */
#define NWZ_POWER_STATUS_CHARGE_STATUS 0x0c0 /* charging status mask */
#define NWZ_POWER_STATUS_VBUS_DET 0x020 /* vbus detected */
#define NWZ_POWER_STATUS_AC_DET 0x010 /* ac adapter detected */
#define NWZ_POWER_STATUS_CHARGE_LOW 0x001 /* full voltage of 4.1 instead of 4.2 */
/* NWZ_POWER_STATUS_CHARGING_MASK value */
#define NWZ_POWER_STATUS_CHARGE_STATUS_CHARGING 0xc0
#define NWZ_POWER_STATUS_CHARGE_STATUS_SUSPEND 0x80
#define NWZ_POWER_STATUS_CHARGE_STATUS_TIMEOUT 0x40
#define NWZ_POWER_STATUS_CHARGE_STATUS_NORMAL 0x00
/* base values to convert from adval to mV (represents mV for adval of 255) */
#define NWZ_POWER_AD_BASE_VBAT 4664
#define NWZ_POWER_AD_BASE_VBUS 7254
#define NWZ_POWER_AD_BASE_VSYS 5700
/* battery gauge */
#define NWZ_POWER_BAT_NOBAT -100 /* no battery */
#define NWZ_POWER_BAT_VERYLOW -99 /* very low */
#define NWZ_POWER_BAT_LOW 0 /* low */
#define NWZ_POWER_BAT_GAUGE0 1 /* ____ */
#define NWZ_POWER_BAT_GAUGE1 2 /* O___ */
#define NWZ_POWER_BAT_GAUGE2 3 /* OO__ */
#define NWZ_POWER_BAT_GAUGE3 4 /* OOO_ */
#define NWZ_POWER_BAT_GAUGE4 5 /* OOOO */
/* NWZ_POWER_GET_ACCESSARY_CHARGE_MODE */
#define NWZ_POWER_ACC_CHARGE_NONE 0
#define NWZ_POWER_ACC_CHARGE_VBAT 1
#define NWZ_POWER_ACC_CHARGE_VSYS 2
#endif /* __NWZ_POWER_H__ */

View file

@ -0,0 +1,35 @@
/***************************************************************************
* __________ __ ___.
* 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 __NWZ_TS_H__
#define __NWZ_TS_H__
#define NWZ_TS_NAME "icx_touch_screen"
/* How touchscreen works:
*
* The touchscreen uses mostly the standard linux protocol, reporting ABS_X,
* ABS_Y, ABS_PRESSURE, TOOL_WIDTH and BTN_TOUCH with SYN to synchronize. The
* only nonstandard part is the use of REL_RX and REL_RY to report "flick"
* detection by the hardware. */
#endif /* __NWZ_TS_H__ */

View file

@ -29,7 +29,7 @@ int main(int argc, char **argv)
int input_fd = nwz_key_open(); int input_fd = nwz_key_open();
if(input_fd < 0) if(input_fd < 0)
{ {
nwz_lcdmsg(false, 3, 7, "Cannot open input device"); nwz_lcdmsg(false, 3, 4, "Cannot open input device");
sleep(2); sleep(2);
return 1; return 1;
} }

View file

@ -0,0 +1,134 @@
/***************************************************************************
* __________ __ ___.
* 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.
*
****************************************************************************/
#include "nwz_lib.h"
static const char *charge_status_name(int chgstat)
{
switch(chgstat)
{
case NWZ_POWER_STATUS_CHARGE_STATUS_CHARGING: return "charging";
case NWZ_POWER_STATUS_CHARGE_STATUS_SUSPEND: return "suspend";
case NWZ_POWER_STATUS_CHARGE_STATUS_TIMEOUT: return "timeout";
case NWZ_POWER_STATUS_CHARGE_STATUS_NORMAL: return "normal";
default: return "unknown";
}
}
static const char *get_batt_gauge_name(int gauge)
{
switch(gauge)
{
case NWZ_POWER_BAT_NOBAT: return "no batt";
case NWZ_POWER_BAT_VERYLOW: return "very low";
case NWZ_POWER_BAT_LOW: return "low";
case NWZ_POWER_BAT_GAUGE0: return "____";
case NWZ_POWER_BAT_GAUGE1: return "O___";
case NWZ_POWER_BAT_GAUGE2: return "OO__";
case NWZ_POWER_BAT_GAUGE3: return "OOO_";
case NWZ_POWER_BAT_GAUGE4: return "OOOO";
default: return "unknown";
}
}
static const char *acc_charge_mode_name(int mode)
{
switch(mode)
{
case NWZ_POWER_ACC_CHARGE_NONE: return "none";
case NWZ_POWER_ACC_CHARGE_VBAT: return "vbat";
case NWZ_POWER_ACC_CHARGE_VSYS: return "vsys";
default: return "unknown";
}
}
int main(int argc, char **argv)
{
/* clear screen and display welcome message */
nwz_lcdmsg(true, 0, 0, "test_power");
nwz_lcdmsg(false, 0, 2, "PWR OFF: quit");
/* open input device */
int input_fd = nwz_key_open();
if(input_fd < 0)
{
nwz_lcdmsg(false, 3, 4, "Cannot open input device");
sleep(2);
return 1;
}
/* open adc device */
int power_fd = nwz_power_open();
if(power_fd < 0)
{
nwz_lcdmsg(false, 3, 4, "Cannot open power device");
sleep(2);
return 1;
}
/* display input state in a loop */
while(1)
{
/* print status */
int line = 4;
int status = nwz_power_get_status(power_fd);
int chgstat = status & NWZ_POWER_STATUS_CHARGE_STATUS;
int acc_chg_mode = nwz_power_get_acc_charge_mode(power_fd);
nwz_lcdmsgf(false, 0, line++, "ac detected: %s ",
(status & NWZ_POWER_STATUS_AC_DET) ? "yes" : "no");
nwz_lcdmsgf(false, 0, line++, "vbus detected: %s ",
(status & NWZ_POWER_STATUS_VBUS_DET) ? "yes" : "no");
nwz_lcdmsgf(false, 0, line++, "vbus voltage: %d mV (AD=%d) ",
nwz_power_get_vbus_voltage(power_fd), nwz_power_get_vbus_adval(power_fd));
nwz_lcdmsgf(false, 0, line++, "vbus limit: %d mA ",
nwz_power_get_vbus_limit(power_fd));
nwz_lcdmsgf(false, 0, line++, "vsys voltage: %d mV (AD=%d) ",
nwz_power_get_vsys_voltage(power_fd), nwz_power_get_vsys_adval(power_fd));
nwz_lcdmsgf(false, 0, line++, "charge switch: %s ",
nwz_power_get_charge_switch(power_fd) ? "on" : "off");
nwz_lcdmsgf(false, 0, line++, "full voltage: %s V ",
(status & NWZ_POWER_STATUS_CHARGE_LOW) ? "4.1" : "4.2");
nwz_lcdmsgf(false, 0, line++, "current limit: %d mA ",
nwz_power_get_charge_current(power_fd));
nwz_lcdmsgf(false, 0, line++, "charge status: %s (%x) ",
charge_status_name(chgstat), chgstat);
nwz_lcdmsgf(false, 0, line++, "battery full: %s ",
nwz_power_is_fully_charged(power_fd) ? "yes" : "no");
nwz_lcdmsgf(false, 0, line++, "bat gauge: %s (%d) ",
get_batt_gauge_name(nwz_power_get_battery_gauge(power_fd)),
nwz_power_get_battery_gauge(power_fd));
nwz_lcdmsgf(false, 0, line++, "avg voltage: %d mV (AD=%d) ",
nwz_power_get_battery_voltage(power_fd), nwz_power_get_battery_adval(power_fd));
nwz_lcdmsgf(false, 0, line++, "sample count: %d ",
nwz_power_get_sample_count(power_fd));
nwz_lcdmsgf(false, 0, line++, "raw voltage: %d mV (AD=%d) ",
nwz_power_get_vbat_voltage(power_fd), nwz_power_get_vbat_adval(power_fd));
nwz_lcdmsgf(false, 0, line++, "acc charge mode: %s (%d) ",
acc_charge_mode_name(acc_chg_mode), acc_chg_mode);
/* wait for event (1s) */
int ret = nwz_key_wait_event(input_fd, 1000000);
if(ret != 1)
continue;
struct input_event evt;
if(nwz_key_read_event(input_fd, &evt) != 1)
continue;
if(nwz_key_event_get_keycode(&evt) == NWZ_KEY_OPTION && !nwz_key_event_is_press(&evt))
break;
}
/* finish nicely */
return 0;
}

View file

@ -0,0 +1,94 @@
/***************************************************************************
* __________ __ ___.
* 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.
*
****************************************************************************/
#include "nwz_lib.h"
int main(int argc, char **argv)
{
/* clear screen and display welcome message */
nwz_lcdmsg(true, 0, 0, "test_ts");
nwz_lcdmsg(false, 0, 2, "PWR OFF: quit");
/* open input device */
int key_fd = nwz_key_open();
if(key_fd < 0)
{
nwz_lcdmsg(false, 3, 4, "Cannot open key device");
sleep(2);
return 1;
}
int ts_fd = nwz_ts_open();
if(ts_fd < 0)
{
nwz_lcdmsg(false, 3, 4, "Cannot open touch screen device");
sleep(2);
return 1;
}
/* init state and print maximum information */
struct nwz_ts_state_t ts_state;
if(nwz_ts_state_init(ts_fd, &ts_state) < 0)
{
nwz_lcdmsg(false, 3, 4, "Cannot init touch screen device");
sleep(2);
return 1;
}
/* display static information */
nwz_lcdmsgf(false, 1, 6, "size: %d, %d ", ts_state.max_x, ts_state.max_y);
/* display input state in a loop */
while(1)
{
/* wait for event */
int fds[2] = {key_fd, ts_fd};
int ret = nwz_wait_fds(fds, 2, -1);
if(ret & 1) /* key_fd */
{
struct input_event evt;
if(nwz_key_read_event(key_fd, &evt) == 1)
{
if(nwz_key_event_get_keycode(&evt) == NWZ_KEY_OPTION &&
nwz_key_event_is_press(&evt))
break; /* quit */
}
}
if(ret & 2) /* ts_fd */
{
#define NR_TS_EVTS 16
struct input_event evts[NR_TS_EVTS];
int nr = nwz_ts_read_events(ts_fd, evts, NR_TS_EVTS);
for(int i = 0; i < nr; i++)
if(nwz_ts_state_update(&ts_state, &evts[i]) == 1)
{
nwz_lcdmsgf(false, 1, 7, "touch: %s ", ts_state.touch ? "yes" : "no");
nwz_lcdmsgf(false, 1, 8, "pos: %d, %d ", ts_state.x, ts_state.y);
nwz_lcdmsgf(false, 1, 9, "pressure: %d ", ts_state.pressure);
nwz_lcdmsgf(false, 1, 10, "width: %d ", ts_state.tool_width);
nwz_lcdmsgf(false, 1, 11, "flick: %s ", ts_state.flick ? "yes" : "no");
nwz_lcdmsgf(false, 1, 12, "flick vec: %d, %d ", ts_state.flick_x, ts_state.flick_y);
/* process touch */
nwz_ts_state_post_syn(&ts_state);
}
#undef NR_TS_EVTS
}
}
/* close input device */
nwz_key_close(key_fd);
nwz_ts_close(ts_fd);
/* finish nicely */
return 0;
}