*/
#define _GNU_SOURCE
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "font.c"
+#define array_size(x) (sizeof(x) / sizeof(x[0]))
+
typedef struct {
int x, y;
int code;
text_out16(fb, 10, 260, lid_closed ? 0x07e0 : 0x7bef, "LID");
}
-static void setkey(int code, int val)
+static void set_key(int code, int val)
{
key_item *key = NULL;
int i;
}
}
+/* sound test */
+#include <sys/soundcard.h>
+#include <pthread.h>
+
+static int snd_test_l, snd_test_r, snd_test_quit;
+static pthread_cond_t snd_cond = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t snd_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+static void *sound_thread(void *arg)
+{
+ int i, ret, randfd, dspfd;
+ int frag, bits, stereo, rate;
+ short buf[8*1024];//2*22050 / 10];
+
+ randfd = open("/dev/urandom", O_RDONLY);
+ if (randfd == -1) {
+ perror("open(\"/dev/urandom\")");
+ return NULL;
+ }
+
+ dspfd = open("/dev/dsp", O_WRONLY);
+ if (dspfd == -1) {
+ perror("open(\"/dev/dsp\")");
+ close(randfd);
+ return NULL;
+ }
+
+ frag = (2 << 16) | 13;
+ ret = ioctl(dspfd, SNDCTL_DSP_SETFRAGMENT, &frag);
+ if (ret < 0)
+ perror("SNDCTL_DSP_SETFRAGMENT");
+
+ stereo = 1; bits = 16; rate = 22050;
+ ret = ioctl(dspfd, SNDCTL_DSP_STEREO, &stereo);
+ if (ret == 0)
+ ret = ioctl(dspfd, SNDCTL_DSP_SETFMT, &bits);
+ if (ret == 0)
+ ret = ioctl(dspfd, SNDCTL_DSP_SPEED, &rate);
+ if (ret < 0)
+ perror("failed to set audio format");
+
+ while (1) {
+ pthread_mutex_lock(&snd_mutex);
+ if (!snd_test_l && !snd_test_r)
+ pthread_cond_wait(&snd_cond, &snd_mutex);
+ pthread_mutex_unlock(&snd_mutex);
+
+ if (snd_test_quit)
+ break;
+
+ ret = read(randfd, buf, sizeof(buf));
+ if (ret == -1) {
+ perror("urandom read");
+ break;
+ }
+
+ if (!snd_test_l)
+ for (i = 0; i < array_size(buf) / 2; i++)
+ buf[i * 2] = 0;
+ if (!snd_test_r)
+ for (i = 0; i < array_size(buf) / 2; i++)
+ buf[i * 2 + 1] = 0;
+
+ ret = write(dspfd, buf, sizeof(buf));
+ if (ret == -1) {
+ perror("dsp write");
+ break;
+ }
+ }
+
+ close(randfd);
+ close(dspfd);
+
+ return NULL;
+}
+
+static void sound_init(void)
+{
+ pthread_t tid;
+ int ret;
+
+ ret = pthread_create(&tid, NULL, sound_thread, NULL);
+ if (ret != 0) {
+ fprintf(stderr, "pthread_create sound_thread: %d\n", ret);
+ return;
+ }
+ pthread_detach(tid);
+}
+
+static void sound_do(int l, int r)
+{
+ pthread_mutex_lock(&snd_mutex);
+ snd_test_l = l;
+ snd_test_r = r;
+ if (l || r || snd_test_quit)
+ pthread_cond_signal(&snd_cond);
+ pthread_mutex_unlock(&snd_mutex);
+}
+
enum {
DEV_PWRBTN,
DEV_KEYPAD,
memset(screen, 0, 800*480*2);
+ sound_init();
+
for (id = 0; ; id++)
{
char fname[64];
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");
+#ifdef VALIDATION
+ text_out16_small(screen, 220, 3, 0x7bef, "press menu/pandora to shutdown, alt/start to exit");
+#else
text_out16_small(screen, 320, 3, 0x7bef, "Press L+R to exit");
+#endif
while (!pressed_l || !pressed_r)
{
case EV_SYN:
break;
case EV_KEY:
- setkey(ev[i].code, ev[i].value);
+ 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;
+ if (ev[i].code == KEY_MENU && !!ev[i].value) {
+ sync();
+ system("poweroff -f");
+ goto end;
+ }
+#endif
+ if (ev[i].code == KEY_LEFT)
+ sound_do(!!ev[i].value, snd_test_r);
+ if (ev[i].code == KEY_RIGHT)
+ sound_do(snd_test_l, !!ev[i].value);
break;
case EV_ABS:
which = (fd == ifd[DEV_LNUB]) ? 0 : 1;
}
}
+ snd_test_quit = 1;
+ sound_do(0, 0);
end:
if (ts != NULL)