[Libphidget-cvs-commits] CVS: libphidget/src/libphidget phidget.c,1.21,1.22 phidget.h,1.13,1.14
Status: Alpha
Brought to you by:
jstrohm
|
From: Jack S. <js...@us...> - 2002-12-14 18:23:09
|
Update of /cvsroot/libphidget/libphidget/src/libphidget
In directory sc8-pr-cvs1:/tmp/cvs-serv576/libphidget
Modified Files:
phidget.c phidget.h
Log Message:
Fully implemented writing strings to the Text LCD and added more commands, clear, on, and off. Example uses all of these
Index: phidget.c
===================================================================
RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** phidget.c 14 Dec 2002 06:49:43 -0000 1.21
--- phidget.c 14 Dec 2002 18:23:06 -0000 1.22
***************
*** 1455,1574 ****
/**
! * Helper function to send data to a Text LCD
*/
! #include <stdio.h>
! enum ELPError phidgetTextLCDWrite(struct phidget *phidgetDevice, int row, int col, const char *str)
{
! {
! int t,i,j, len, buf_ptr;
! unsigned char form_buffer[30];
! unsigned char buffer[10];//={0,0,0,0,0,0,0,0,0,0};
!
! /* 0000 - 0
! * 0001 - 1
! * 0010 - 2
! * 0011 - 3
! * 0100 - 4
! * 0101 - 5
! * 0110 - 6
! * 0111 - 7
! * 1000 - 8
! * 1001 - 9
! * 1010 - A
! * 1011 - B
! * 1100 - C
! * 1101 - D
! * 1110 - E
! * 1111 - F
! */
!
! {
! // Initialize command mode
! buffer[0] = 0x69; // 0: 0 1 1 0 1 0 0 1 <- System Set, 4 lines, Use CGRAM
! buffer[1] = 0x31; // 0: 0 0 1 1 0 0 0 1 <- Display ON/OFF, Display ON
! buffer[2] = 0x42;//66; // 0: 0 1 0 0 0 0 1 0 <- Power Save, Oscillator Circuit ON
! buffer[3] = 0x57;//87; // 0: 0 1 0 1 0 1 1 1 <- RAM Address set to 010111 (23)
! buffer[4] = 0xB0; // Set the address pointer
! buffer[5] = 0x30 + (row - 1) * 0x10 + 0x80+col;
! buffer[7] = 6; // testing - this makes it work, not sure why
! phidgetWrite(phidgetDevice,buffer,8);
!
! // Seems to be needed to flush data
! buffer[0]=0x02;
! buffer[1]=str[0];
! buffer[2]=str[1];
! buffer[3]=str[2];
! buffer[4]=str[3];
! buffer[5]=str[4];
! buffer[6]=1; // go back into command mode
! buffer[7]=7;
! phidgetWrite(phidgetDevice,buffer,8);
!
! }
! /*
! {
! // Initialize command mode
! buffer[0] = 0; // buffer[0] is a windows thing
! buffer[1] = 0x69; // 0: 0 1 1 0 1 0 0 1 <- System Set, 4 lines, Use CGRAM
! buffer[2] = 0x31; // 0: 0 0 1 1 0 0 0 1 <- Display ON/OFF, Display ON
! buffer[3] = 0x42;//66; // 0: 0 1 0 0 0 0 1 0 <- Power Save, Oscillator Circuit ON
! buffer[4] = 0x57;//87; // 0: 0 1 0 1 0 1 1 1 <- RAM Address set to 010111 (23)
! buffer[5] = 0xB0; // Set the address pointer
! buffer[8] = 0x05;
! phidgetWrite(phidgetDevice,buffer,9);
! //buffer[0]=0x02;
! //buffer[8]=1;
! //phidgetWrite(phidgetDevice,buffer,9);
! }
! */
! /*
! printf("1\n");fflush(stdout);
! len=strlen(str)/2;
! // Always
! buffer[0] = 0;
! // Set the address 0 0 1 1 0 0 0 0
! form_buffer[0] = 0x30 + (row - 1) * 0x10 + 0x80;
! // Switch to data mode
! form_buffer[1] = 0x02;
! buf_ptr = 2;
! for (i = 0; i<len; i++)
! {
! form_buffer[buf_ptr++] = (unsigned char)str[i];
! }
! for (i = 0; i < (12 - len); i++)
! {
! form_buffer[buf_ptr++] = 0x20;
! }
! // Back into command mode
! form_buffer[buf_ptr++] = 0x01;
! printf("2\n");fflush(stdout);
! for (i = 0; i<buf_ptr; i+=7)
{
! printf(">> %d of %d\n",i,buf_ptr);
! if ((buf_ptr - i) > 7)
! len = 7;
! else
! len = (buf_ptr - i);
!
! for (j = 0; j < len; j++)
! buffer[j + 1] = form_buffer[i + j];
!
! buffer[8] = len;
!
! phidgetWrite(phidgetDevice, buffer, 9);
!
}
!
! printf("3\n");fflush(stdout);
! */
}
--- 1455,1538 ----
/**
! * Helper function to clear the Text LCD
*/
! enum ELPError phidgetTextLCDClear(struct phidget *phidgetDevice)
{
! phidgetTextLCDWrite(phidgetDevice,0,0," ");
! phidgetTextLCDWrite(phidgetDevice,1,0," ");
! phidgetTextLCDWrite(phidgetDevice,2,0," ");
! phidgetTextLCDWrite(phidgetDevice,3,0," ");
! }
! /**
! * Helper function to turn the Text LCD on and configure it
! */
! enum ELPError phidgetTextLCDOn(struct phidget *phidgetDevice)
! {
! char buffer[8];
! buffer[0] = 0x69; // 0: 0 1 1 0 1 0 0 1 <- System Set, 4 lines, Use CGRAM
! buffer[1] = 0x31; // 0: 0 0 1 1 0 0 0 1 <- Display ON/OFF, Display ON
! buffer[2] = 0x42; // 0: 0 1 0 0 0 0 1 0 <- Power Save, Oscillator Circuit ON
! buffer[7] = 3;
! phidgetWrite(phidgetDevice,buffer,8);
! }
! /**
! * Helper function to turn the Text LCD off
! */
! enum ELPError phidgetTextLCDOff(struct phidget *phidgetDevice)
! {
! char buffer[8];
! buffer[0] = 0x30; // 0: 0 0 1 1 0 0 0 0 <- Display ON/OFF, Display ON
! buffer[1] = 0x40; // 0: 0 1 0 0 0 0 0 0 <- Power Save, Oscillator Circuit ON
! buffer[7] = 2;
! phidgetWrite(phidgetDevice,buffer,8);
! }
! /**
! * Helper function to send data to a Text LCD
! * 0 >= row < 4
! * 0 >= col < 12
! *
! * str can't be longer than 12 bytes, and no bounds checking.
! */
! enum ELPError phidgetTextLCDWrite(struct phidget *phidgetDevice, int row, int col, const char *str)
! {
! int pos=0,t,len,tc;
! unsigned char temp[256],buffer[10];
! //temp[pos++] = 0x69; // 0: 0 1 1 0 1 0 0 1 <- System Set, 4 lines, Use CGRAM
! //temp[pos++] = 0x31; // 0: 0 0 1 1 0 0 0 1 <- Display ON/OFF, Display ON
! //temp[pos++] = 0x42; // 0: 0 1 0 0 0 0 1 0 <- Power Save, Oscillator Circuit ON
! temp[pos++] = 0x57; // 0: 0 1 0 1 0 1 1 1 <- RAM Address set to 010111 (23)
! temp[pos++] = 0xB0; // Set the address pointer
! temp[pos++] = 0x30 + row * 0x10 + 0x80+col; // set position we write to
! temp[pos++] = 0x02; // Data mode
! // Write the string
! len=strlen(str);
! if (len>12) len=12;
! for (t=0;t<len;t++)
! temp[pos++]=str[t];
! temp[pos++] = 0x01; // back to command mode
! tc=0;
! for (t=0;t<pos;t++)
! {
! buffer[tc++]=temp[t];
! if (tc==7)
{
! buffer[7]=7;
! phidgetWrite(phidgetDevice,buffer,8);
! tc=0;
}
! }
! if (tc!=0)
! {
! buffer[7]=tc;
! phidgetWrite(phidgetDevice,buffer,8);
}
Index: phidget.h
===================================================================
RCS file: /cvsroot/libphidget/libphidget/src/libphidget/phidget.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** phidget.h 14 Dec 2002 04:34:36 -0000 1.13
--- phidget.h 14 Dec 2002 18:23:06 -0000 1.14
***************
*** 212,218 ****
--- 212,221 ----
enum ELPError phidget8Servo(struct phidget *phidgetDevice, int id, float percent1, float maxvelocity, float acceleration);
+ enum ELPError phidgetTextLCDOn(struct phidget *phidgetDevice);
+ enum ELPError phidgetTextLCDOff(struct phidget *phidgetDevice);
enum ELPError phidgetInterfaceKit488(struct phidget *phidgetDevice, float analog[4], int digital[8]);
enum ELPError phidgetInterfaceKit880(struct phidget *phidgetDevice, float analog[8], int digital[8]);
enum ELPError phidgetTextLCDWrite(struct phidget *phidgetDevice, int row, int col, const char *str);
+ enum ELPError phidgetTextLCDClear(struct phidget *phidgetDevice);
/**
|