mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-22 19:42:40 -05:00
nwztools/plattools: rework/clean and add an all-in-one tool
This new tool (all_tools) embeds all the other tools and provides a menu to choose which one to run. Change-Id: I0e07864dd46559a7079b0f942c25155e6fa07112
This commit is contained in:
parent
ad9a2d5241
commit
0a2290653b
13 changed files with 325 additions and 27 deletions
|
|
@ -5,13 +5,17 @@ CFLAGS=-std=gnu99 -Wall -O2
|
|||
INCLUDES=-I.
|
||||
|
||||
LIB_FILES=nwz_lib.c nwz_lib_devlist.c
|
||||
ALL_BUT_LIB=$(patsubst %.c,%.elf,$(filter-out $(LIB_FILES),$(wildcard *.c)))
|
||||
TOOL_FILES=dest_tool.c test_adc.c test_adc.c test_bl.c test_display.c \
|
||||
test_keys.c test_power.c test_ts.c
|
||||
ALL_ELF=$(patsubst %.c,%.elf,$(TOOL_FILES)) all_tools.elf
|
||||
|
||||
all: $(ALL_BUT_LIB)
|
||||
all: $(ALL_ELF)
|
||||
|
||||
%.elf: %.c $(LIB_FILES)
|
||||
$(CC) $(CFLAGS) $(INCLUDES) -o $@ $^
|
||||
|
||||
clean:
|
||||
rm -rf $(ALL_BUT_LIB)
|
||||
all_tools.elf: all_tools.c $(TOOL_FILES) $(LIB_FILES)
|
||||
$(CC) $(CFLAGS) -DNWZ_EMBED_TOOLS $(INCLUDES) -o $@ $^
|
||||
|
||||
clean:
|
||||
rm -rf $(ALL_ELF)
|
||||
|
|
|
|||
132
utils/nwztools/plattools/all_tools.c
Normal file
132
utils/nwztools/plattools/all_tools.c
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2011 by Amaury Pouly
|
||||
*
|
||||
* Based on Rockbox iriver bootloader by Linus Nielsen Feltzing
|
||||
* and the ipodlinux bootloader by Daniel Palffy and Bernard Leach
|
||||
*
|
||||
* 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"
|
||||
#include "nwz_plattools.h"
|
||||
|
||||
#define TOOL_LIST \
|
||||
TOOL(dest_tool) \
|
||||
TOOL(test_adc) \
|
||||
TOOL(test_bl) \
|
||||
TOOL(test_display) \
|
||||
TOOL(test_keys) \
|
||||
TOOL(test_power) \
|
||||
TOOL(test_ts)
|
||||
|
||||
typedef int (*nwz_tool_main_t)(int argc, char **argv);
|
||||
|
||||
struct nwz_tool_t
|
||||
{
|
||||
const char *name;
|
||||
nwz_tool_main_t main;
|
||||
};
|
||||
|
||||
/* create list of extern definition */
|
||||
#define TOOL(name) extern int NWZ_TOOL_MAIN(name)(int argc, char **argv);
|
||||
TOOL_LIST
|
||||
#undef TOOL
|
||||
|
||||
/* create actual list */
|
||||
#define TOOL(name) { #name, NWZ_TOOL_MAIN(name) },
|
||||
static struct nwz_tool_t g_tools[] =
|
||||
{
|
||||
TOOL_LIST
|
||||
};
|
||||
#undef TOOL
|
||||
|
||||
#define NR_TOOLS (sizeof(g_tools) / sizeof(g_tools[0]))
|
||||
|
||||
static void hello(void)
|
||||
{
|
||||
/* clear screen and display welcome message */
|
||||
nwz_lcdmsg(true, 0, 0, "all_tools");
|
||||
nwz_lcdmsg(false, 0, 2, "BACK: quit");
|
||||
nwz_lcdmsg(false, 0, 2, "LEFT/RIGHT: change tool");
|
||||
nwz_lcdmsg(false, 0, 3, "PLAY: run tool");
|
||||
}
|
||||
|
||||
/* this tool itself can be embedded in the dualboot */
|
||||
#ifdef NWZ_DUALBOOT
|
||||
int NWZ_TOOL_MAIN(all_tools)(int argc, char **argv)
|
||||
#else
|
||||
int main(int argc, char **argv)
|
||||
#endif
|
||||
{
|
||||
hello();
|
||||
/* open input device */
|
||||
int input_fd = nwz_key_open();
|
||||
if(input_fd < 0)
|
||||
{
|
||||
nwz_lcdmsg(false, 3, 5, "Cannot open input device");
|
||||
sleep(2);
|
||||
return 1;
|
||||
}
|
||||
/* main loop */
|
||||
int cur_tool = 0;
|
||||
while(true)
|
||||
{
|
||||
/* print tools */
|
||||
int line = 5;
|
||||
for(size_t i = 0; i < NR_TOOLS; i++)
|
||||
{
|
||||
nwz_lcdmsgf(false, 0, line++, "%c %s", (i == cur_tool) ? '>' : ' ',
|
||||
g_tools[i].name);
|
||||
}
|
||||
/* wait for event (1000ms) */
|
||||
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;
|
||||
/* only act on key release */
|
||||
if(nwz_key_event_is_press(&evt))
|
||||
continue;
|
||||
int keycode = nwz_key_event_get_keycode(&evt);
|
||||
if(keycode == NWZ_KEY_LEFT)
|
||||
{
|
||||
cur_tool--;
|
||||
if(cur_tool == -1)
|
||||
cur_tool += NR_TOOLS;
|
||||
}
|
||||
else if(keycode == NWZ_KEY_RIGHT)
|
||||
{
|
||||
cur_tool++;
|
||||
if(cur_tool == NR_TOOLS)
|
||||
cur_tool = 0;
|
||||
}
|
||||
else if(keycode == NWZ_KEY_PLAY)
|
||||
{
|
||||
/* close input */
|
||||
nwz_key_close(input_fd);
|
||||
g_tools[cur_tool].main(argc, argv);
|
||||
/* reopen input and clear the screen */
|
||||
input_fd = nwz_key_open();
|
||||
hello();
|
||||
}
|
||||
else if(keycode == NWZ_KEY_BACK)
|
||||
break;
|
||||
}
|
||||
nwz_key_close(input_fd);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -21,10 +21,11 @@
|
|||
#include "nwz_lib.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "nwz_plattools.h"
|
||||
|
||||
extern char **environ;
|
||||
|
||||
const char *white_list[] =
|
||||
static const char *white_list[] =
|
||||
{
|
||||
"NWZ-E463", "NWZ-E464", "NWZ-E465",
|
||||
"NWZ-A863", "NWZ-A864", "NWZ-A865", "NWZ-A866", "NWZ-A867",
|
||||
|
|
@ -32,7 +33,7 @@ const char *white_list[] =
|
|||
};
|
||||
|
||||
/* get model id from ICX_MODEL_ID environment variable */
|
||||
unsigned long find_model_id(void)
|
||||
static unsigned long find_model_id(void)
|
||||
{
|
||||
const char *mid = getenv("ICX_MODEL_ID");
|
||||
if(mid == NULL)
|
||||
|
|
@ -45,12 +46,12 @@ unsigned long find_model_id(void)
|
|||
return v;
|
||||
}
|
||||
|
||||
unsigned long read32(unsigned char *buf)
|
||||
static unsigned long read32(unsigned char *buf)
|
||||
{
|
||||
return buf[0] | buf[1] << 8 | buf[2] << 16 | buf[3] << 24;
|
||||
}
|
||||
|
||||
void write32(unsigned char *buf, unsigned long value)
|
||||
static void write32(unsigned char *buf, unsigned long value)
|
||||
{
|
||||
buf[0] = value & 0xff;
|
||||
buf[1] = (value >> 8) & 0xff;
|
||||
|
|
@ -58,7 +59,7 @@ void write32(unsigned char *buf, unsigned long value)
|
|||
buf[3] = (value >> 24) & 0xff;
|
||||
}
|
||||
|
||||
struct
|
||||
static struct
|
||||
{
|
||||
unsigned long dest;
|
||||
const char *name;
|
||||
|
|
@ -84,7 +85,7 @@ struct
|
|||
|
||||
#define NR_DEST (sizeof(g_dest_list) / sizeof(g_dest_list[0]))
|
||||
|
||||
int get_dest_index(unsigned long dest)
|
||||
static int get_dest_index(unsigned long dest)
|
||||
{
|
||||
for(size_t i = 0; i < NR_DEST; i++)
|
||||
if(g_dest_list[i].dest == dest)
|
||||
|
|
@ -92,16 +93,16 @@ int get_dest_index(unsigned long dest)
|
|||
return -1;
|
||||
}
|
||||
|
||||
const char *get_dest_name(unsigned long dest)
|
||||
static const char *get_dest_name(unsigned long dest)
|
||||
{
|
||||
int index = get_dest_index(dest);
|
||||
return index < 0 ? "NG" : g_dest_list[index].name;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int NWZ_TOOL_MAIN(dest_tool)(int argc, char **argv)
|
||||
{
|
||||
/* clear screen and display welcome message */
|
||||
nwz_lcdmsg(true, 0, 0, "destination tool");
|
||||
nwz_lcdmsg(true, 0, 0, "dest_tool");
|
||||
/* open input device */
|
||||
int input_fd = nwz_key_open();
|
||||
if(input_fd < 0)
|
||||
|
|
@ -113,6 +114,7 @@ int main(int argc, char **argv)
|
|||
unsigned long model_id = find_model_id();
|
||||
if(model_id == 0)
|
||||
{
|
||||
nwz_key_close(input_fd);
|
||||
nwz_lcdmsg(false, 3, 4, "Cannot get model ID");
|
||||
sleep(2);
|
||||
return 1;
|
||||
|
|
@ -214,5 +216,6 @@ int main(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
/* finish nicely */
|
||||
nwz_key_close(input_fd);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -483,3 +483,22 @@ int nwz_power_is_fully_charged(int fd)
|
|||
return -1;
|
||||
return status;
|
||||
}
|
||||
|
||||
int nwz_pminfo_open(void)
|
||||
{
|
||||
return open(NWZ_PMINFO_DEV, O_RDONLY);
|
||||
}
|
||||
|
||||
void nwz_pminfo_close(int fd)
|
||||
{
|
||||
close(fd);
|
||||
}
|
||||
|
||||
unsigned int nwz_pminfo_get_factor(int fd)
|
||||
{
|
||||
unsigned int val;
|
||||
if(ioctl(fd, NWZ_PMINFO_GET_FACTOR, &val) < 0)
|
||||
return 0;
|
||||
else
|
||||
return val;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -158,4 +158,11 @@ 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);
|
||||
|
||||
/* open pminfo device */
|
||||
int nwz_pminfo_open(void);
|
||||
/* close pminfo device */
|
||||
void nwz_pminfo_close(int fd);
|
||||
/* get pminfo factor (or 0 on error) */
|
||||
unsigned int nwz_pminfo_get_factor(int fd);
|
||||
|
||||
#endif /* _NWZLIB_H_ */
|
||||
|
|
|
|||
37
utils/nwztools/plattools/nwz_plattools.h
Normal file
37
utils/nwztools/plattools/nwz_plattools.h
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2011 by Amaury Pouly
|
||||
*
|
||||
* Based on Rockbox iriver bootloader by Linus Nielsen Feltzing
|
||||
* and the ipodlinux bootloader by Daniel Palffy and Bernard Leach
|
||||
*
|
||||
* 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_PLATTOOLS_H__
|
||||
#define __NWZ_PLATTOOLS_H__
|
||||
|
||||
/** Platform tools can be either built individually, or be included in a
|
||||
* single build (or even dualboot code) for easy testing. Thus, each tool must
|
||||
* use the following macros to support all scenarios. */
|
||||
|
||||
#ifdef NWZ_EMBED_TOOLS
|
||||
#define NWZ_TOOL_MAIN(tool) tool##_main
|
||||
#else
|
||||
#define NWZ_TOOL_MAIN(tool) main
|
||||
#endif
|
||||
|
||||
#endif /* __NWZ_PLATTOOLS_H__ */
|
||||
|
|
@ -21,6 +21,8 @@
|
|||
#ifndef __NWZ_POWER_H__
|
||||
#define __NWZ_POWER_H__
|
||||
|
||||
/** power */
|
||||
|
||||
#define NWZ_POWER_DEV "/dev/icx_power"
|
||||
|
||||
#define NWZ_POWER_TYPE 'P'
|
||||
|
|
@ -79,4 +81,35 @@
|
|||
#define NWZ_POWER_ACC_CHARGE_VBAT 1
|
||||
#define NWZ_POWER_ACC_CHARGE_VSYS 2
|
||||
|
||||
/** pminfo
|
||||
*
|
||||
* This driver seems to collect the state of the device on boot. Thus one
|
||||
* can know if a key was pressed when booting for example.
|
||||
*/
|
||||
|
||||
#define NWZ_PMINFO_DEV "/dev/icx_pminfo"
|
||||
|
||||
#define NWZ_PMINFO_TYPE 'b'
|
||||
|
||||
/* ioctl request */
|
||||
|
||||
#define NWZ_PMINFO_GET_FACTOR _IOR(NWZ_PMINFO_TYPE, 0, unsigned int *)
|
||||
#define NWZ_PMINFO_CLR_DETRSTFLG _IO(NWZ_PMINFO_TYPE, 1)
|
||||
|
||||
/* NWZ_PMINFO_GET_FACTOR bitmap
|
||||
* WARNING this information may not apply to all players and some bits do not
|
||||
* exists on some players */
|
||||
#define ICX_PMINFO_FACTOR_RTC_WAL 0x20000000 /* RTC Weekly Alarm */
|
||||
#define ICX_PMINFO_FACTOR_RTC_DAL 0x10000000 /* RTC Daily Alarm */
|
||||
#define ICX_PMINFO_FACTOR_VBUS 0x08000000 /* VBUS in/out */
|
||||
#define ICX_PMINFO_FACTOR_DC_POWER 0x04000000 /* AC Adaptor in/out */
|
||||
#define ICX_PMINFO_FACTOR_USB_WAKE 0x01000000 /* USB Wake */
|
||||
#define ICX_PMINFO_FACTOR_CHARGE 0x00400000 /* Charge */
|
||||
#define ICX_PMINFO_FACTOR_CRADLE 0x00080000 /* Cradle in/out */
|
||||
#define ICX_PMINFO_FACTOR_AB_EV 0x00008000 /* ab event */
|
||||
#define ICX_PMINFO_FACTOR_NC_SW 0x00004000 /* nc switch */
|
||||
#define ICX_PMINFO_FACTOR_HOLD_SW 0x00002000 /* hold switch */
|
||||
#define ICX_PMINFO_FACTOR_KEY_PAD 0x00001000 /* keypad */
|
||||
#define ICX_PMINFO_FACTOR_KEY_CODE 0x00000FFF /* keycode */
|
||||
|
||||
#endif /* __NWZ_POWER_H__ */
|
||||
|
|
|
|||
|
|
@ -19,8 +19,9 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
#include "nwz_lib.h"
|
||||
#include "nwz_plattools.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int NWZ_TOOL_MAIN(test_adc)(int argc, char **argv)
|
||||
{
|
||||
/* clear screen and display welcome message */
|
||||
nwz_lcdmsg(true, 0, 0, "test_adc");
|
||||
|
|
@ -37,6 +38,7 @@ int main(int argc, char **argv)
|
|||
int adc_fd = nwz_adc_open();
|
||||
if(adc_fd < 0)
|
||||
{
|
||||
nwz_key_close(input_fd);
|
||||
nwz_lcdmsg(false, 3, 4, "Cannot open adc device");
|
||||
sleep(2);
|
||||
return 1;
|
||||
|
|
@ -59,6 +61,7 @@ int main(int argc, char **argv)
|
|||
break;
|
||||
}
|
||||
/* finish nicely */
|
||||
nwz_key_close(input_fd);
|
||||
nwz_adc_close(adc_fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,8 +19,9 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
#include "nwz_lib.h"
|
||||
#include "nwz_plattools.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int NWZ_TOOL_MAIN(test_bl)(int argc, char **argv)
|
||||
{
|
||||
/* clear screen and display welcome message */
|
||||
nwz_lcdmsg(true, 0, 0, "test_bl");
|
||||
|
|
@ -39,6 +40,7 @@ int main(int argc, char **argv)
|
|||
int fb_fd = nwz_fb_open(true);
|
||||
if(fb_fd < 0)
|
||||
{
|
||||
nwz_key_close(input_fd);
|
||||
nwz_lcdmsg(false, 3, 7, "Cannot open framebuffer device");
|
||||
sleep(2);
|
||||
return 1;
|
||||
|
|
@ -103,9 +105,8 @@ int main(int argc, char **argv)
|
|||
nwz_fb_set_brightness(fb_fd, &bl);
|
||||
}
|
||||
/* close input device */
|
||||
close(input_fd);
|
||||
nwz_key_close(input_fd);
|
||||
nwz_fb_close(fb_fd);
|
||||
/* finish nicely */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -19,8 +19,9 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
#include "nwz_lib.h"
|
||||
#include "nwz_plattools.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int NWZ_TOOL_MAIN(test_display)(int argc, char **argv)
|
||||
{
|
||||
/* clear screen and display welcome message */
|
||||
nwz_lcdmsg(true, 0, 0, "test_display");
|
||||
|
|
|
|||
|
|
@ -19,12 +19,13 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
#include "nwz_lib.h"
|
||||
#include "nwz_plattools.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int NWZ_TOOL_MAIN(test_keys)(int argc, char **argv)
|
||||
{
|
||||
/* clear screen and display welcome message */
|
||||
nwz_lcdmsg(true, 0, 0, "test_keys");
|
||||
nwz_lcdmsg(false, 0, 2, "hold BACK for 3 seconds to quit");
|
||||
nwz_lcdmsg(false, 0, 2, "BACK: hold 3 seconds to quit");
|
||||
/* open input device */
|
||||
int input_fd = nwz_key_open();
|
||||
if(input_fd < 0)
|
||||
|
|
@ -35,6 +36,10 @@ int main(int argc, char **argv)
|
|||
}
|
||||
/* display input state in a loop */
|
||||
int back_pressed = 0; /* 0 = no pressed, >0 = number of seconds pressed - 1 */
|
||||
#define FIRST_LINE 7
|
||||
#define LAST_LINE 17
|
||||
int event_line = FIRST_LINE;
|
||||
int prev_evt_line = -1;
|
||||
while(1)
|
||||
{
|
||||
/* display HOLD status */
|
||||
|
|
@ -52,18 +57,49 @@ int main(int argc, char **argv)
|
|||
struct input_event evt;
|
||||
if(nwz_key_read_event(input_fd, &evt) != 1)
|
||||
continue;
|
||||
nwz_lcdmsgf(false, 2, 6, "%s %s (HOLD=%d) ",
|
||||
/* erase last '>' indicator */
|
||||
if(prev_evt_line != -1)
|
||||
nwz_lcdmsg(false, 0, prev_evt_line, " ");
|
||||
prev_evt_line = event_line;
|
||||
char buffer[32];
|
||||
int len = sprintf(buffer, "> %s %s (HOLD=%d)",
|
||||
nwz_key_get_name(nwz_key_event_get_keycode(&evt)),
|
||||
nwz_key_event_is_press(&evt) ? "pressed" : "released",
|
||||
nwz_key_event_get_hold_status(&evt));
|
||||
/* pad with spaces to erase old stuff */
|
||||
while(len + 1 < sizeof(buffer))
|
||||
buffer[len++] = ' ';
|
||||
buffer[len] = 0;
|
||||
/* print line */
|
||||
nwz_lcdmsg(false, 0, event_line, buffer);
|
||||
/* compute next line */
|
||||
event_line++;
|
||||
if(event_line == LAST_LINE)
|
||||
event_line = FIRST_LINE;
|
||||
/* handle quit */
|
||||
if(nwz_key_event_get_keycode(&evt) == NWZ_KEY_BACK && nwz_key_event_is_press(&evt))
|
||||
back_pressed = 1;
|
||||
else
|
||||
back_pressed = 0;
|
||||
}
|
||||
/* wait until back is released, to avoid messing with all_tools (if embedded) */
|
||||
nwz_lcdmsg(true, 0, 0, "test_keys");
|
||||
nwz_lcdmsg(false, 0, 2, "BACK: release to quit");
|
||||
while(1)
|
||||
{
|
||||
/* wait for event */
|
||||
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;
|
||||
/* handle quit */
|
||||
if(nwz_key_event_get_keycode(&evt) == NWZ_KEY_BACK && !nwz_key_event_is_press(&evt))
|
||||
break;
|
||||
}
|
||||
/* close input device */
|
||||
close(input_fd);
|
||||
nwz_key_close(input_fd);
|
||||
/* finish nicely */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
#include "nwz_lib.h"
|
||||
#include "nwz_plattools.h"
|
||||
|
||||
static const char *charge_status_name(int chgstat)
|
||||
{
|
||||
|
|
@ -59,7 +60,7 @@ static const char *acc_charge_mode_name(int mode)
|
|||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int NWZ_TOOL_MAIN(test_power)(int argc, char **argv)
|
||||
{
|
||||
/* clear screen and display welcome message */
|
||||
nwz_lcdmsg(true, 0, 0, "test_power");
|
||||
|
|
@ -76,10 +77,21 @@ int main(int argc, char **argv)
|
|||
int power_fd = nwz_power_open();
|
||||
if(power_fd < 0)
|
||||
{
|
||||
nwz_key_close(input_fd);
|
||||
nwz_lcdmsg(false, 3, 4, "Cannot open power device");
|
||||
sleep(2);
|
||||
return 1;
|
||||
}
|
||||
/* open pminfo device */
|
||||
int pminfo_fd = nwz_pminfo_open();
|
||||
if(pminfo_fd < 0)
|
||||
{
|
||||
nwz_key_close(power_fd);
|
||||
nwz_key_close(input_fd);
|
||||
nwz_lcdmsg(false, 3, 4, "Cannot open pminfo device");
|
||||
sleep(2);
|
||||
return 1;
|
||||
}
|
||||
/* display input state in a loop */
|
||||
while(1)
|
||||
{
|
||||
|
|
@ -119,6 +131,9 @@ int main(int argc, char **argv)
|
|||
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);
|
||||
/* pminfo */
|
||||
line++;
|
||||
nwz_lcdmsgf(false, 0, line++, "pminfo: %#x ", nwz_pminfo_get_factor(pminfo_fd));
|
||||
/* wait for event (1s) */
|
||||
int ret = nwz_key_wait_event(input_fd, 1000000);
|
||||
if(ret != 1)
|
||||
|
|
@ -130,5 +145,8 @@ int main(int argc, char **argv)
|
|||
break;
|
||||
}
|
||||
/* finish nicely */
|
||||
nwz_key_close(power_fd);
|
||||
nwz_key_close(input_fd);
|
||||
nwz_pminfo_close(pminfo_fd);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,9 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
#include "nwz_lib.h"
|
||||
#include "nwz_plattools.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int NWZ_TOOL_MAIN(test_ts)(int argc, char **argv)
|
||||
{
|
||||
/* clear screen and display welcome message */
|
||||
nwz_lcdmsg(true, 0, 0, "test_ts");
|
||||
|
|
@ -36,6 +37,7 @@ int main(int argc, char **argv)
|
|||
int ts_fd = nwz_ts_open();
|
||||
if(ts_fd < 0)
|
||||
{
|
||||
nwz_key_close(key_fd);
|
||||
nwz_lcdmsg(false, 3, 4, "Cannot open touch screen device");
|
||||
sleep(2);
|
||||
return 1;
|
||||
|
|
@ -44,6 +46,8 @@ int main(int argc, char **argv)
|
|||
struct nwz_ts_state_t ts_state;
|
||||
if(nwz_ts_state_init(ts_fd, &ts_state) < 0)
|
||||
{
|
||||
nwz_key_close(key_fd);
|
||||
nwz_ts_close(ts_fd);
|
||||
nwz_lcdmsg(false, 3, 4, "Cannot init touch screen device");
|
||||
sleep(2);
|
||||
return 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue