Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Unified Diff: test/test-pad.c

Issue 6475005: Revert "Import files from .tar.gz that are missing from upstream git repo." (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/xf86-input-synaptics.git@master
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/Makefile.in ('k') | test/testprotocol.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/test-pad.c
diff --git a/test/test-pad.c b/test/test-pad.c
new file mode 100644
index 0000000000000000000000000000000000000000..f4c27e9322231236c5ae92d745cd3aeb333509ca
--- /dev/null
+++ b/test/test-pad.c
@@ -0,0 +1,121 @@
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+int
+getbyte(int fd, unsigned char *b)
+{
+ return(read(fd, b, 1) == 1);
+}
+
+int
+putbyte(int fd, unsigned char b)
+{
+ unsigned char ack;
+
+ printf("write %02X\n", b);
+ if (write(fd, &b, 1) != 1) {
+ fprintf(stderr, "error write: %s\n", strerror(errno));
+ return 0;
+ }
+
+ if (!getbyte(fd, &ack)) {
+ fprintf(stderr, "error read: %s\n", strerror(errno));
+ return 0;
+ }
+ printf("read %02X\n", ack);
+
+ if (ack != 0xFA) {
+ fprintf(stderr, "error ack\n");
+ return 0;
+ }
+
+ return 1;
+}
+
+int
+special_cmd(int fd, unsigned char cmd)
+{
+ int i;
+
+ if (putbyte(fd, 0xE6))
+ for (i = 0; i < 4; i++) {
+ printf("special_cmd %i\n", i);
+ if ((!putbyte(fd, 0xE8)) || (!putbyte(fd, (cmd>>6)&0x3)))
+ return 0;
+ cmd<<=2;
+ }
+ else
+ return 0;
+ return 1;
+}
+
+int
+send_cmd(int fd, unsigned char cmd)
+{
+ return (special_cmd(fd, cmd) &&
+ putbyte(fd, 0xE9));
+}
+
+int
+identify(int fd, unsigned long int *ident)
+{
+ unsigned char id[3];
+
+ if (send_cmd(fd, 0x00) &&
+ getbyte(fd, &id[0]) &&
+ getbyte(fd, &id[1]) &&
+ getbyte(fd, &id[2])) {
+ *ident = (id[0]<<16)|(id[1]<<8)|id[2];
+ printf("ident %06X\n", *ident);
+ return 1;
+ } else {
+ fprintf(stderr, "error identify\n");
+ return 0;
+ }
+}
+
+int
+reset(int fd)
+{
+ unsigned char r[2];
+
+ if (!putbyte(fd, 0xFF)) {
+ fprintf(stderr, "error reset\n");
+ return 0;
+ }
+
+ sleep(5);
+
+ if (getbyte(fd, &r[0]) && getbyte(fd, &r[1]))
+ if (r[0] == 0xAA && r[1] == 0x00) {
+ fprintf(stderr, "reset done\n");
+ return 1;
+ }
+ fprintf(stderr, "error reset ack\n");
+ return 0;
+}
+
+int
+main(int argc, char* argv[])
+{
+ int fd;
+ unsigned long int ident;
+
+ fd = open("/dev/psaux", O_RDWR);
+ if (fd == -1) {
+ fprintf(stderr, "error open: %s\n", strerror(errno));
+ exit(0);
+ }
+
+ reset(fd);
+ identify(fd, &ident);
+
+ close(fd);
+
+ exit(0);
+}
« no previous file with comments | « src/Makefile.in ('k') | test/testprotocol.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698