mirror of https://github.com/nirenjan/libx52.git
Export vendor command interface
The vendor command interface allows the user to write a vendor request packet using the known vendor interface. However, it is not intended for regular use, since the existing API is better suited to abstract it away from the user. Rather, the prime goal is for a test harness interface that can be used to debug problems seen during regular library accesses.pull/7/head
parent
cd4fca0d2e
commit
f8a7257b54
|
@ -4,7 +4,7 @@ lib_LTLIBRARIES = libx52.la
|
|||
libx52_la_SOURCES = src/x52_common.h src/x52_commands.h src/libx52.h \
|
||||
src/x52_control.c src/x52_core.c \
|
||||
src/x52_date_time.c src/x52_mfd_led.c
|
||||
libx52_la_LDFLAGS = -version-info 1:0:0 -lusb-1.0
|
||||
libx52_la_LDFLAGS = -version-info 2:0:1 -lusb-1.0
|
||||
pkginclude_HEADERS = src/libx52.h
|
||||
|
||||
bin_PROGRAMS = x52cli x52test
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
AC_INIT([libx52], [1.0.0], [nirenjan@gmail.com])
|
||||
AC_INIT([libx52], [1.1.0], [nirenjan@gmail.com])
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects])
|
||||
AC_PROG_CC
|
||||
|
|
|
@ -295,4 +295,18 @@ int libx52_set_blink(libx52_device *x52, uint8_t state);
|
|||
*/
|
||||
int libx52_update(libx52_device *x52);
|
||||
|
||||
/**
|
||||
* @brief Write a raw vendor control packet
|
||||
*
|
||||
* This can be used to debug issues seen on the hardware, however, it is not
|
||||
* recommended for use by end users, as it can potentially damage the hardware.
|
||||
*
|
||||
* @param[in] x52 Pointer to the device
|
||||
* @param[in] index wIndex in the USB packet
|
||||
* @param[in] value wValue in the USB packet
|
||||
*
|
||||
* @returns 0 on success, -errno on failure
|
||||
*/
|
||||
int libx52_vendor_command(libx52_device *x52, uint16_t index, uint16_t value);
|
||||
|
||||
#endif /* !defined LIBX52_H */
|
||||
|
|
|
@ -24,6 +24,7 @@ typedef enum {
|
|||
X52_CTL_CMD_SHIFT,
|
||||
X52_CTL_CMD_CLOCK,
|
||||
X52_CTL_CMD_OFFSET,
|
||||
X52_CTL_CMD_RAW,
|
||||
|
||||
X52_CTL_CMD_MAX
|
||||
} x52_ctl_command;
|
||||
|
@ -160,6 +161,7 @@ DEFINE_MAP(command) = {
|
|||
{ "shift", X52_CTL_CMD_SHIFT },
|
||||
{ "clock", X52_CTL_CMD_CLOCK },
|
||||
{ "offset", X52_CTL_CMD_OFFSET },
|
||||
{ "raw", X52_CTL_CMD_RAW },
|
||||
{ NULL, -1 }
|
||||
};
|
||||
|
||||
|
@ -231,6 +233,14 @@ static int update_offset(libx52_device *x52, void *args[])
|
|||
return rc;
|
||||
}
|
||||
|
||||
static int write_raw(libx52_device *x52, void *args[])
|
||||
{
|
||||
uint16_t wIndex = (uint16_t)strtoul(args[0], NULL, 0);
|
||||
uint16_t wValue = (uint16_t)strtoul(args[1], NULL, 0);
|
||||
|
||||
return libx52_vendor_command(x52, wIndex, wValue);
|
||||
}
|
||||
|
||||
const struct command_handler handlers[X52_CTL_CMD_MAX] = {
|
||||
[X52_CTL_CMD_LED_STATE] = {
|
||||
update_led,
|
||||
|
@ -291,6 +301,15 @@ const struct command_handler handlers[X52_CTL_CMD_MAX] = {
|
|||
},
|
||||
"offset {2 | 3} <offset from clock 1 in minutes> {12hr | 24hr}"
|
||||
},
|
||||
[X52_CTL_CMD_RAW] = {
|
||||
write_raw,
|
||||
2,
|
||||
{
|
||||
NULL,
|
||||
NULL,
|
||||
},
|
||||
"raw <wIndex> <wValue>"
|
||||
}
|
||||
};
|
||||
|
||||
static int do_help(const struct command_handler *cmd)
|
||||
|
@ -304,7 +323,7 @@ static int do_help(const struct command_handler *cmd)
|
|||
printf("\t%s\n", handlers[i].help);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
printf("\nWARNING: raw command may damage your device\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "x52_commands.h"
|
||||
#include "x52_common.h"
|
||||
|
||||
static int libx52_vendor_command(libx52_device *x52, uint16_t index, uint16_t value)
|
||||
int libx52_vendor_command(libx52_device *x52, uint16_t index, uint16_t value)
|
||||
{
|
||||
int j;
|
||||
int rc;
|
||||
|
|
Loading…
Reference in New Issue