/* glcd_primitives.c based on Debian Slug C program to draw primitive structures on a graphic display controlled by a PIC i2c slave headers modified for Sweex ------------------------------------------------------------ usage :- type the following arguments after the program name eg for a rectangle - glcd_primitives 81 2 100 30 110 40 1 1 arguments - argv[1] = PIC address (0xA0 on PIC is 80 on Linux master, 0xA2 is 81) - then send these bytes to the PIC - argv[2] values 1 line(x1 y1 x2 y2 color(0/1)) 2 rect(x1 y1 x2 y2 fill(0/1) color(0/1) 3 bar(x1 y1 x2 y2 width color(0/1) - - - fails, why? 4 circle(x1 y1 x2 y2 color(0/1)) 5 text(x, y, textptr, size, color(0/1)) - later 6 pixel (x y color(0/1)) 7 wipe all screen (color(0/1)) */ #include #include #include #include #include int i2c; unsigned char tx_buf[8]; /* bytes to send */ int address; /* i2c bus address */ int rc; int main(int argc, char** argv) { if (argc != 9) /* report error if we are not getting just 8 inputs after the program name */ { printf("Error. usage: %s i2c_chip_address command arg3 arg4 arg5 arg6 arg7 arg8\n", argv[0]); } address = atoi(argv[1]); // i2c decimal address // the write command sends the contents of txbuf[] tx_buf[0] = atoi(argv[2]); // command tx_buf[1] = atoi(argv[3]); tx_buf[2] = atoi(argv[4]); tx_buf[3] = atoi(argv[5]); tx_buf[4] = atoi(argv[6]); tx_buf[5] = atoi(argv[7]); tx_buf[6] = atoi(argv[8]); printf("address=%u\ncommand=%u arg3=%u arg4=%u arg5=%u arg6=%u arg7=%u arg8=%u\n\n", address, tx_buf[0], tx_buf[1], tx_buf[2], tx_buf[3], tx_buf[4], tx_buf[5], tx_buf[6]); //-----------------------------------------------------------send the bytes i2c = open("/dev/i2c/0",O_RDWR); /* open the device dev/i2c/0 */ rc=ioctl(i2c,I2C_SLAVE,address); /* set the i2c chip address */ write(i2c,tx_buf,7); /* we send the first 7 bytes from tx_buf[]*/ usleep(10); i2c = close(i2c); }