mirror of https://github.com/nirenjan/libx52.git
Make x52test more verbose
parent
9dcc3507ed
commit
21f5440349
|
@ -7,10 +7,9 @@ libx52_la_SOURCES = src/x52_common.h src/x52_commands.h src/libx52.h \
|
|||
libx52_la_LDFLAGS = -version-info 1:0:0 -lusb-1.0
|
||||
pkginclude_HEADERS = src/libx52.h
|
||||
|
||||
noinst_PROGRAMS = x52_test
|
||||
x52_test_SOURCES = src/x52_test.c
|
||||
x52_test_LDADD = libx52.la
|
||||
|
||||
bin_PROGRAMS = x52cli
|
||||
bin_PROGRAMS = x52cli x52test
|
||||
x52cli_SOURCES = src/x52_cli.c
|
||||
x52cli_LDADD = libx52.la
|
||||
|
||||
x52test_SOURCES = src/x52_test.c src/x52_test_mfd.c src/x52_test_led.c
|
||||
x52test_LDADD = libx52.la
|
||||
|
|
|
@ -1,19 +1,33 @@
|
|||
/*
|
||||
* Saitek X52 Pro MFD & LED driver
|
||||
*
|
||||
* Copyright (C) 2012-2015 Nirenjan Krishnan (nirenjan@nirenjan.org)
|
||||
*
|
||||
* 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, version 2.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "libx52.h"
|
||||
#include "x52_test_common.h"
|
||||
|
||||
typedef void (*test_func)(libx52_device *dev, int step);
|
||||
libx52_device *dev;
|
||||
int test_exit;
|
||||
|
||||
/* Run test initializations */
|
||||
static void test_cleanup(libx52_device *dev)
|
||||
void test_cleanup(void)
|
||||
{
|
||||
/* Set the default LED states */
|
||||
libx52_set_text(dev, 0, " Saitek X52 Pro ", 16);
|
||||
libx52_set_text(dev, 1, " Flight ", 16);
|
||||
libx52_set_text(dev, 2, " Control System ", 16);
|
||||
|
||||
libx52_set_led_state(dev, LIBX52_LED_FIRE, LIBX52_LED_STATE_ON);
|
||||
libx52_set_led_state(dev, LIBX52_LED_THROTTLE, LIBX52_LED_STATE_ON);
|
||||
libx52_set_led_state(dev, LIBX52_LED_A, LIBX52_LED_STATE_GREEN);
|
||||
libx52_set_led_state(dev, LIBX52_LED_B, LIBX52_LED_STATE_GREEN);
|
||||
libx52_set_led_state(dev, LIBX52_LED_D, LIBX52_LED_STATE_GREEN);
|
||||
|
@ -23,211 +37,92 @@ static void test_cleanup(libx52_device *dev)
|
|||
libx52_set_led_state(dev, LIBX52_LED_T3, LIBX52_LED_STATE_GREEN);
|
||||
libx52_set_led_state(dev, LIBX52_LED_POV, LIBX52_LED_STATE_GREEN);
|
||||
libx52_set_led_state(dev, LIBX52_LED_CLUTCH, LIBX52_LED_STATE_GREEN);
|
||||
libx52_set_led_state(dev, LIBX52_LED_THROTTLE, LIBX52_LED_STATE_ON);
|
||||
|
||||
/* Shift/Blink Off */
|
||||
libx52_set_shift(dev, 0);
|
||||
libx52_set_blink(dev, 0);
|
||||
libx52_set_shift(dev, 0);
|
||||
|
||||
/* Default Text */
|
||||
libx52_set_text(dev, 0, " Saitek X52 Pro", 15);
|
||||
libx52_set_text(dev, 1, " Flight ", 15);
|
||||
libx52_set_text(dev, 2, " Control System", 15);
|
||||
libx52_set_clock(dev, time(NULL), 1); // Display local time
|
||||
libx52_set_clock_timezone(dev, LIBX52_CLOCK_2, 0); // GMT
|
||||
libx52_set_clock_timezone(dev, LIBX52_CLOCK_3, 330); // IST
|
||||
|
||||
/* Maximum brightness */
|
||||
libx52_set_brightness(dev, 1, 127);
|
||||
libx52_set_brightness(dev, 0, 127);
|
||||
libx52_set_clock_format(dev, LIBX52_CLOCK_1, LIBX52_CLOCK_FORMAT_24HR);
|
||||
libx52_set_clock_format(dev, LIBX52_CLOCK_2, LIBX52_CLOCK_FORMAT_24HR);
|
||||
libx52_set_clock_format(dev, LIBX52_CLOCK_3, LIBX52_CLOCK_FORMAT_24HR);
|
||||
|
||||
libx52_set_date_format(dev, LIBX52_DATE_FORMAT_MMDDYY);
|
||||
|
||||
libx52_set_brightness(dev, 1, 128);
|
||||
libx52_set_brightness(dev, 0, 128);
|
||||
|
||||
libx52_update(dev);
|
||||
}
|
||||
|
||||
static void test_mfd_display(libx52_device *dev, int step)
|
||||
void print_banner(const char *message)
|
||||
{
|
||||
uint32_t j;
|
||||
char str[16];
|
||||
char c;
|
||||
size_t len = strlen(message);
|
||||
int i;
|
||||
|
||||
libx52_set_text(dev, 1, "0123456789ABCDEF", 16);
|
||||
|
||||
/* Print line 0 - the hex of the step number */
|
||||
c = step;
|
||||
c += (c < 10) ? 0x30 : 0x37;
|
||||
for (j = 0; j < 16; j++) {
|
||||
str[j] = c;
|
||||
putchar('\n');
|
||||
putchar('\t');
|
||||
for (i = 0; i < len + 2; i++) {
|
||||
putchar('=');
|
||||
}
|
||||
libx52_set_text(dev, 0, str, 16);
|
||||
putchar('\n');
|
||||
|
||||
putchar('\t');
|
||||
putchar(' ');
|
||||
puts(message);
|
||||
|
||||
for (j = 0; j < 16; j++) {
|
||||
str[j] = (step << 4) + j;
|
||||
putchar('\t');
|
||||
for (i = 0; i < len + 2; i++) {
|
||||
putchar('=');
|
||||
}
|
||||
libx52_set_text(dev, 2, str, 16);
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
/* Test the LEDs on the panel */
|
||||
static void test_leds(libx52_device *dev, int step)
|
||||
static void signal_handler(int sig)
|
||||
{
|
||||
int led;
|
||||
const char *state_map[] = {
|
||||
NULL,
|
||||
"A",
|
||||
"B",
|
||||
"D",
|
||||
"E",
|
||||
"T1",
|
||||
"T2",
|
||||
"T3",
|
||||
"POV",
|
||||
"I"
|
||||
};
|
||||
|
||||
switch (step) {
|
||||
case 0:
|
||||
/* Turn off Fire LED */
|
||||
libx52_set_text(dev, 0, "LED Test", 8);
|
||||
libx52_set_text(dev, 1, "Fire", 4);
|
||||
libx52_set_text(dev, 2, "OFF", 3);
|
||||
libx52_set_led_state(dev, LIBX52_LED_FIRE, LIBX52_LED_STATE_OFF);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
/* Turn on Fire LED */
|
||||
libx52_set_text(dev, 1, "Fire", 4);
|
||||
libx52_set_text(dev, 2, "ON", 2);
|
||||
libx52_set_led_state(dev, LIBX52_LED_FIRE, LIBX52_LED_STATE_ON);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
/* Turn off Throttle LED */
|
||||
libx52_set_text(dev, 1, "Throttle", 8);
|
||||
libx52_set_text(dev, 2, "OFF", 3);
|
||||
libx52_set_led_state(dev, LIBX52_LED_THROTTLE, LIBX52_LED_STATE_OFF);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
/* Turn on Throttle LED */
|
||||
libx52_set_text(dev, 1, "Throttle", 8);
|
||||
libx52_set_text(dev, 2, "ON", 2);
|
||||
libx52_set_led_state(dev, LIBX52_LED_THROTTLE, LIBX52_LED_STATE_ON);
|
||||
break;
|
||||
|
||||
default: {
|
||||
led = step / 4;
|
||||
libx52_set_text(dev, 1, state_map[led], strlen(state_map[led]));
|
||||
|
||||
led = led * 2;
|
||||
switch (step % 4) {
|
||||
case 0:
|
||||
libx52_set_text(dev, 2, "OFF", 3);
|
||||
libx52_set_led_state(dev, led, LIBX52_LED_STATE_OFF);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
libx52_set_text(dev, 2, "RED", 3);
|
||||
libx52_set_led_state(dev, led, LIBX52_LED_STATE_RED);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
libx52_set_text(dev, 2, "AMBER", 5);
|
||||
libx52_set_led_state(dev, led, LIBX52_LED_STATE_AMBER);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
libx52_set_text(dev, 2, "GREEN", 5);
|
||||
libx52_set_led_state(dev, led, LIBX52_LED_STATE_GREEN);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
test_exit = sig;
|
||||
}
|
||||
|
||||
static void test_blinkenlichts(libx52_device *dev, int step)
|
||||
{
|
||||
switch (step) {
|
||||
case 0:
|
||||
libx52_set_text(dev, 0, "Blinkenlichts", 13);
|
||||
libx52_set_text(dev, 1, "Shift Indicator", 15);
|
||||
libx52_set_text(dev, 2, "ON", 2);
|
||||
libx52_set_shift(dev, 1);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
libx52_set_text(dev, 2, "OFF", 3);
|
||||
libx52_set_shift(dev, 0);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
libx52_set_text(dev, 1, "Blink Indicator", 15);
|
||||
libx52_set_text(dev, 2, "ON", 2);
|
||||
libx52_set_blink(dev, 1);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
libx52_set_text(dev, 2, "OFF", 3);
|
||||
libx52_set_blink(dev, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void test_brightness(libx52_device *dev, int step)
|
||||
{
|
||||
char line1[16];
|
||||
char line2[16];
|
||||
int len1;
|
||||
int len2;
|
||||
|
||||
if (step == 0) {
|
||||
libx52_set_text(dev, 0, "Brightness", 10);
|
||||
}
|
||||
|
||||
len1 = snprintf(line1, sizeof(line1), "MFD: %d", step);
|
||||
len2 = snprintf(line2, sizeof(line2), "LED: %d", step);
|
||||
|
||||
libx52_set_text(dev, 1, line1, len1);
|
||||
libx52_set_text(dev, 2, line2, len2);
|
||||
libx52_set_brightness(dev, 0, step);
|
||||
libx52_set_brightness(dev, 1, step);
|
||||
}
|
||||
|
||||
struct test_case {
|
||||
test_func test;
|
||||
int test_steps;
|
||||
};
|
||||
|
||||
static struct test_case cases[] = {
|
||||
{ test_brightness, 129 },
|
||||
{ test_mfd_display, 16 },
|
||||
{ test_leds, 40 },
|
||||
{ test_blinkenlichts, 4 },
|
||||
{ NULL, 0 } /* Must be the last entry */
|
||||
};
|
||||
#define RUN_TEST(tst) rc = test_ ## tst (); if (rc) break;
|
||||
|
||||
int main()
|
||||
{
|
||||
uint32_t i;
|
||||
uint32_t j;
|
||||
char str[16];
|
||||
char c;
|
||||
struct test_case *tc;
|
||||
int rc = 0;
|
||||
|
||||
libx52_device *dev;
|
||||
printf("x52test is a suite of tests to write to the X52 Pro device\n");
|
||||
printf("and test the extra functionality available in the LEDs and MFD\n");
|
||||
printf("\nThese tests take quite some time, press Enter to begin the test");
|
||||
|
||||
getc(stdin);
|
||||
|
||||
dev = libx52_init();
|
||||
if (dev == NULL) {
|
||||
fprintf(stderr, "Unable to connect to X52 Pro Joystick!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
signal(SIGTERM, signal_handler);
|
||||
signal(SIGINT, signal_handler);
|
||||
test_exit = 0;
|
||||
|
||||
tc = &cases[0];
|
||||
do {
|
||||
for (i = 0; i < tc->test_steps; i++) {
|
||||
if (tc->test) {
|
||||
(*tc->test)(dev, i);
|
||||
}
|
||||
libx52_update(dev);
|
||||
usleep(500000);
|
||||
}
|
||||
RUN_TEST(brightness)
|
||||
RUN_TEST(leds)
|
||||
RUN_TEST(mfd_text)
|
||||
RUN_TEST(mfd_display)
|
||||
} while (0);
|
||||
|
||||
tc++;
|
||||
|
||||
/* Reset the X52 */
|
||||
test_cleanup(dev);
|
||||
libx52_update(dev);
|
||||
} while (tc->test);
|
||||
if (rc > 0) {
|
||||
fprintf(stderr, "Received %s signal, quitting...\n", strsignal(rc));
|
||||
} else if (rc < 0) {
|
||||
fprintf(stderr, "Got error %s\n", strerror(-rc));
|
||||
} else {
|
||||
puts("All tests completed successfully");
|
||||
}
|
||||
|
||||
if (rc >= 0) test_cleanup();
|
||||
libx52_exit(dev);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Saitek X52 Pro MFD & LED driver
|
||||
*
|
||||
* Copyright (C) 2012-2015 Nirenjan Krishnan (nirenjan@nirenjan.org)
|
||||
*
|
||||
* 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, version 2.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef X52_TEST_COMMON_H
|
||||
#define X52_TEST_COMMON_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include "libx52.h"
|
||||
|
||||
extern libx52_device *dev;
|
||||
extern int test_exit;
|
||||
|
||||
#define TEST(tst, ...) do { \
|
||||
int rc; \
|
||||
rc = ( libx52_set_ ## tst (dev, __VA_ARGS__) ); \
|
||||
if (rc) { \
|
||||
fprintf(stderr, "\n%s(%s) failed with %d\n", #tst, #__VA_ARGS__, rc); \
|
||||
return rc; \
|
||||
} \
|
||||
if (test_exit) return test_exit; \
|
||||
rc = libx52_update(dev); \
|
||||
if (rc) { \
|
||||
fprintf(stderr, "\nupdate failed with %d\n", rc); \
|
||||
return rc; \
|
||||
} \
|
||||
if (test_exit) return test_exit; \
|
||||
} while (0)
|
||||
|
||||
void test_cleanup(void);
|
||||
|
||||
void print_banner(const char *message);
|
||||
|
||||
int test_brightness(void);
|
||||
int test_mfd_display(void);
|
||||
int test_leds(void);
|
||||
|
||||
|
||||
#endif /* X52_TEST_COMMON_H */
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Saitek X52 Pro MFD & LED driver
|
||||
*
|
||||
* Copyright (C) 2012-2015 Nirenjan Krishnan (nirenjan@nirenjan.org)
|
||||
*
|
||||
* 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, version 2.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "libx52.h"
|
||||
#include "x52_test_common.h"
|
||||
|
||||
#define TEST_LED(name, state) do { \
|
||||
puts("LED " #name " - " #state); \
|
||||
TEST(led_state, LIBX52_LED_ ## name, LIBX52_LED_STATE_ ## state); \
|
||||
usleep(500000); \
|
||||
} while(0)
|
||||
|
||||
#define TEST_LED_MONO(name) do { \
|
||||
puts("\nTesting LED " #name); \
|
||||
sleep(2); \
|
||||
TEST_LED(name, OFF); \
|
||||
TEST_LED(name, ON); \
|
||||
} while(0)
|
||||
|
||||
#define TEST_LED_COLOR(name) do {\
|
||||
puts("\nTesting LED " #name); \
|
||||
sleep(2); \
|
||||
TEST_LED(name, OFF); \
|
||||
TEST_LED(name, RED); \
|
||||
TEST_LED(name, AMBER); \
|
||||
TEST_LED(name, GREEN); \
|
||||
} while(0)
|
||||
|
||||
int test_leds(void)
|
||||
{
|
||||
print_banner("LEDs");
|
||||
puts("This cycles the LEDs through all possible states");
|
||||
|
||||
TEST_LED_MONO(FIRE);
|
||||
TEST_LED_COLOR(A);
|
||||
TEST_LED_COLOR(B);
|
||||
TEST_LED_COLOR(D);
|
||||
TEST_LED_COLOR(E);
|
||||
TEST_LED_COLOR(T1);
|
||||
TEST_LED_COLOR(T2);
|
||||
TEST_LED_COLOR(T3);
|
||||
TEST_LED_COLOR(POV);
|
||||
TEST_LED_COLOR(CLUTCH);
|
||||
TEST_LED_MONO(THROTTLE);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
* Saitek X52 Pro MFD & LED driver
|
||||
*
|
||||
* Copyright (C) 2012-2015 Nirenjan Krishnan (nirenjan@nirenjan.org)
|
||||
*
|
||||
* 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, version 2.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "libx52.h"
|
||||
#include "x52_test_common.h"
|
||||
|
||||
#define TEST_BRIGHTNESS(mfd, value) TEST(brightness, mfd, value)
|
||||
|
||||
int test_brightness(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
print_banner("Brightness");
|
||||
|
||||
puts("This test cycles through the MFD and LED brightness scales");
|
||||
|
||||
fputs("\n |+---+---+---+---+---+---+---+---+|", stdout);
|
||||
fputs("\nMFD: ", stdout);
|
||||
for (i = 0; i < 129; i++) {
|
||||
if (!(i & 3)) fputs("#", stdout);
|
||||
fflush(stdout);
|
||||
TEST_BRIGHTNESS(1, i);
|
||||
usleep(250000);
|
||||
}
|
||||
fputs("\nLED: ", stdout);
|
||||
for (i = 0; i < 129; i++) {
|
||||
if (!(i & 3)) fputs("#", stdout);
|
||||
fflush(stdout);
|
||||
TEST_BRIGHTNESS(0, i);
|
||||
usleep(250000);
|
||||
}
|
||||
|
||||
fputs("\n\n", stdout);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_mfd_text(void)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
char str[32];
|
||||
|
||||
print_banner("MFD text");
|
||||
puts("This test tests the character displays of the MFD\n");
|
||||
|
||||
for (i = 0; i < 256; i += 16) {
|
||||
j = snprintf(str, 16, "0x%02x - 0x%02x", i, i + 0xf);
|
||||
printf("Writing characters %s\n", str);
|
||||
TEST(text, 0, str, j);
|
||||
|
||||
memset(str, ' ', 32);
|
||||
for (j = 0; j < 16; j++) {
|
||||
str[j << 1] = i + j;
|
||||
}
|
||||
|
||||
TEST(text, 1, str, 16);
|
||||
TEST(text, 2, str + 16, 16);
|
||||
|
||||
sleep(2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_mfd_display(void)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int rc;
|
||||
char str[16];
|
||||
|
||||
print_banner("MFD display");
|
||||
puts("This test checks if the display elements can display all characters");
|
||||
puts("You should see the display cycling through each character, with every");
|
||||
puts("cell displaying the same character\n");
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
printf("Testing character 0x%02x...", i);
|
||||
|
||||
memset(str, i, 16);
|
||||
|
||||
libx52_set_text(dev, 0, str, 16);
|
||||
libx52_set_text(dev, 1, str, 16);
|
||||
libx52_set_text(dev, 2, str, 16);
|
||||
|
||||
/* Try upto 3 times - if it fails, dump an error */
|
||||
for (j = 0; j < 3; j++) {
|
||||
rc = libx52_update(dev);
|
||||
if (rc) {
|
||||
fprintf(stderr, "\tError %d during update\n", rc);
|
||||
sleep(1);
|
||||
} else {
|
||||
puts("OK");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (rc) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (test_exit) {
|
||||
return test_exit;
|
||||
}
|
||||
|
||||
/* usleep(1500000); */
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue