#define array_size(x) (sizeof(x) / sizeof(x[0]))
+/* this sucks, but EvilDragon wants it */
+#ifdef VALIDATION
+#define NUB_RANGE_REQ (256-8*3)
+#else
+#define NUB_RANGE_REQ 256
+#endif
+
typedef struct {
int x, y;
int code;
#define KI_COUNT (sizeof(key_items) / sizeof(key_items[0]))
-static int ts_old_x = 0, ts_old_y = 0;
-static int lid_closed = 0;
+static int nub_range_hit, all_btns_tested, lid_tested, ts_tested;
+static int ts_old_x, ts_old_y;
+static int lid_closed;
static void draw_ts_cross(unsigned short *fb, unsigned short col, int x, int y)
{
if (x >= 0 && x < 800)
for (y1 = y - 5, i = 0; i < 11; i++, y1++)
if (y1 >= 0 && y1 < 480) fb[y1 * 800 + x] = col;
-
+
+ if (x != ts_old_x && y != ts_old_y)
+ ts_tested = 1;
+
ts_old_x = x;
ts_old_y = y;
}
static void redraw_nubs(unsigned short *fb, int x1, int y1, int x2, int y2)
{
- static int range_hit;
char buff[32];
- int y;
+ int fill = 0, y;
fb += 90*800;
+ if (nub_range_hit == 0xff && all_btns_tested && lid_tested && ts_tested)
+ fill = 3;
+
// clear areas
for (y = 0; y < 140; y++) {
- memset(fb + 800*y + 200, 0, (64+8)*2*2);
- memset(fb + 800*y + 450, 0, (64+8)*2*2);
+ memset(fb + 800*y + 200, fill, (64+8)*2*2);
+ memset(fb + 800*y + 450, fill, (64+8)*2*2);
}
text_out16(fb + 200, 32*2 + x1/8, 32*2 + y1/8, 0x001f, "@");
text_out16(fb + 450, 32*2 + x2/8, 32*2 + y2/8, 0x001f, "@");
- if (x1 == -256) range_hit |= 0x01;
- if (x1 == 256) range_hit |= 0x02;
- if (y1 == -256) range_hit |= 0x04;
- if (y1 == 256) range_hit |= 0x08;
- if (x2 == -256) range_hit |= 0x10;
- if (x2 == 256) range_hit |= 0x20;
- if (y2 == -256) range_hit |= 0x40;
- if (y2 == 256) range_hit |= 0x80;
+ if (x1 <= -NUB_RANGE_REQ) nub_range_hit |= 0x01;
+ if (x1 >= NUB_RANGE_REQ) nub_range_hit |= 0x02;
+ if (y1 <= -NUB_RANGE_REQ) nub_range_hit |= 0x04;
+ if (y1 >= NUB_RANGE_REQ) nub_range_hit |= 0x08;
+ if (x2 <= -NUB_RANGE_REQ) nub_range_hit |= 0x10;
+ if (x2 >= NUB_RANGE_REQ) nub_range_hit |= 0x20;
+ if (y2 <= -NUB_RANGE_REQ) nub_range_hit |= 0x40;
+ if (y2 >= NUB_RANGE_REQ) nub_range_hit |= 0x80;
snprintf(buff, sizeof(buff), "%3i", x1/8);
- text_out16_small(fb, 235, 130, (range_hit & 0x03) == 0x03 ? 0xce6f : 0x7bef, buff);
+ text_out16_small(fb, 235, 130, (nub_range_hit & 0x03) == 0x03 ? 0xce6f : 0x7bef, buff);
snprintf(buff, sizeof(buff), "%3i", y1/8);
- text_out16_small(fb, 270, 130, (range_hit & 0x0c) == 0x0c ? 0xce6f : 0x7bef, buff);
+ text_out16_small(fb, 270, 130, (nub_range_hit & 0x0c) == 0x0c ? 0xce6f : 0x7bef, buff);
snprintf(buff, sizeof(buff), "%3i", x2/8);
- text_out16_small(fb, 485, 130, (range_hit & 0x30) == 0x30 ? 0xce6f : 0x7bef, buff);
+ text_out16_small(fb, 485, 130, (nub_range_hit & 0x30) == 0x30 ? 0xce6f : 0x7bef, buff);
snprintf(buff, sizeof(buff), "%3i", y2/8);
- text_out16_small(fb, 520, 130, (range_hit & 0xc0) == 0xc0 ? 0xce6f : 0x7bef, buff);
+ text_out16_small(fb, 520, 130, (nub_range_hit & 0xc0) == 0xc0 ? 0xce6f : 0x7bef, buff);
}
static void redraw_keys_lid(unsigned short *fb)
key->name);
}
- text_out16(fb, 10, 260, lid_closed ? 0x07e0 : 0x7bef, "LID");
+ text_out16(fb, 10, 260, lid_closed ? 0x07e0 : (lid_tested ? 0xce6f : 0x7bef), "LID");
}
static void set_key(int code, int val)
key->tested |= !!val;
printf("%c %s\n", val ? '+' : '-', key->name);
}
+
+ if (all_btns_tested)
+ return;
+
+ for (i = 0; i < KI_COUNT; i++)
+ {
+ if (key_items[i].code == KEY_MENU)
+ continue;
+ if (key_items[i].code == KEY_KPPLUS || key_items[i].code == KEY_KPMINUS)
+ continue;
+ if (!key_items[i].tested)
+ break;
+ }
+
+ if (i == KI_COUNT)
+ all_btns_tested = 1;
}
/* sound test */
int nubx[2] = {0,0}, nuby[2] = {0,0};
int pressed_l = 0, pressed_r = 0;
struct tsdev *ts = NULL;
+ int retval = 0;
fbdev = open("/dev/fb0", O_RDWR);
if (fbdev == -1)
ioctl(fd, EVIOCGNAME(sizeof(name)), name);
- if (strcasestr(name, "power") != NULL)
+ if (strcasestr(name, "power") != NULL || strcasestr(name, "pwrbutton") != NULL)
{
ifd[DEV_PWRBTN] = fd;
}
if (ifd[DEV_PWRBTN] == -1) printf("Warning: couldn't find pwrbutton device\n");
if (ifd[DEV_KEYPAD] == -1) printf("Warning: couldn't find keypad device\n");
- if (ifd[DEV_BUTTONS] == -1) printf("Warning: couldn't find button device\n");
if (ifd[DEV_TS] == -1) printf("Warning: couldn't find touchscreen device\n");
if (ifd[DEV_LNUB] == -1) printf("Warning: couldn't find nub1 device\n");
if (ifd[DEV_RNUB] == -1) printf("Warning: couldn't find nub2 device\n");
+ if (ifd[DEV_BUTTONS] == -1) {
+ printf("Error: couldn't find button device\n");
+ /* buttons needed to exit this, so bail out */
+ retval = -1;
+ goto end;
+ }
#ifdef VALIDATION
- text_out16_small(screen, 220, 3, 0x7bef, "press menu/pandora to shutdown, alt/start to exit");
+ int early_leave_attempt = 0;
+ text_out16_small(screen, 220, 3, 0x7bef,
+ "press menu/pandora to exit");
#else
text_out16_small(screen, 320, 3, 0x7bef, "Press L+R to exit");
#endif
+#ifdef VALIDATION
+ while (1)
+#else
while (!pressed_l || !pressed_r)
+#endif
{
struct input_event ev[64];
int fd = -1, rd, which, ret;
fd_set fdset;
+#ifdef VALIDATION
+ if (early_leave_attempt > 1) {
+ char buff[128];
+ snprintf(buff, sizeof(buff), "not everything tested (%s%s%s%s), L+R to override",
+ nub_range_hit == 0xff ? "" : "nubs", all_btns_tested ? "" : " buttons",
+ lid_tested ? "" : " lid_switch", ts_tested ? "" : " touchscreen");
+ memset(screen, 0, 800*12*2);
+ if (nub_range_hit == 0xff && all_btns_tested && lid_tested && ts_tested)
+ text_out16_small(screen, 220, 3, 0x07c0,
+ "press menu/pandora to exit");
+ else
+ text_out16_small(screen, 4, 3, 0xf800, buff);
+ }
+#endif
draw_ts_cross(screen, 0x0000, ts_old_x, ts_old_y);
redraw_keys_lid(screen);
redraw_nubs(screen, nubx[0], nuby[0], nubx[1], nuby[1]);
break;
case EV_KEY:
set_key(ev[i].code, ev[i].value);
-#ifndef VALIDATION
+
if (ev[i].code == KEY_RIGHTSHIFT)
pressed_l = !!ev[i].value;
if (ev[i].code == KEY_RIGHTCTRL)
pressed_r = !!ev[i].value;
-#else
- if (ev[i].code == KEY_LEFTALT && !!ev[i].value)
- goto end;
+#ifdef VALIDATION
if (ev[i].code == KEY_MENU && !!ev[i].value) {
- sync();
- system("poweroff -f");
- goto end;
+ if (nub_range_hit == 0xff && all_btns_tested && lid_tested && ts_tested)
+ goto end;
+ if (pressed_l && pressed_r) {
+ retval = 1;
+ goto end;
+ }
+ early_leave_attempt++;
}
#endif
if (ev[i].code == KEY_LEFT)
printf("unexpected EV_ABS code: %i\n", ev[i].code);
break;
case EV_SW:
- if (ev[i].code == SW_LID)
+ if (ev[i].code == SW_LID) {
lid_closed = ev[i].value;
+ lid_tested |= ev[i].value;
+ }
else
printf("unexpected EV_SW code: %i\n", ev[i].code);
break;
close(ifd[i]);
munmap(screen, 800*480*2);
close(fbdev);
- return 0;
+ return retval;
}