Logitech DiNovo Media LCD
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 9 lines · On Mon, 08 Jan 2007 23:10:38 +0100 "Glen Rolle" <[email protected]> wrote:
Hello!
First of all I want to thank you for your efforts developping the LCD communication stuff. I have been working on this since several weeks to no avail and it seems that my driver programming knowledge was not good enough.
I was working with your patch for several days now and have some comments and suggestions.
The thanks, as well as the comments are much appreciated. :)
Quoted 5 lines
- When patching I had a problem with the makefile generated automatically. The DBUS tags you added in the patch were integrated as empty strings into the makefile. I had to place the correct contents manually. Don't know why this happened. (I use debian testing with bluez-utils 3.7)
You need to rebuild the Makefile.in from Makefile.am by running automake in the bluez-utils directory after patching, before you run configure. You might want to retry it with a fresh copy.
Quoted 6 lines
- I have extended the interface for the lcd and added following functions. I wanted to have more atomic control over the LCD.
-- WriteLine (
line_number,scroll_mode, string)
--- Write only a single line, so that you can set content and scroll mode separately for each line.
IMO, it's easier to have the driver auto-determine the scroll mode. This saves the programmer from having to deal with splitting up the text.
Quoted 4 lines
-- SetScreenMode (mode)
--- An easy way to switch between the 3-line display (0) and the clock display (1).
You can switch back to the clock display by pressing "Clear Screen", and to the "3-line" mode by writing text. (This is so that alerts persist until the user presses "Clear Screen.")
Quoted 6 lines
-- SendRawData (
array_of_integers)
--- Mainly for testing and debugging purpose, so that you can send commands to the LCD without having to recompile fakehid all the time. The raw data starts with0x10and0x11resp. The0xA2will be send automaticallay.
This could be useful under certain circumstances, however, there's really no need at this point to send raw data to the mediapad, because the functionality is quite complete (With the exception of the Nav indicator and the Calculator -> Clipboard, of course (I know how it works sending the data back (I've got code in place in the driver), but I can't seem to isolate the init packet.))
Quoted 3 lines
It might be useful to split some of your funtions e. g. the WriteText into a "initScreen" part and the text display. (This would remove the flashing display when sending new text with WriteText.)
If you look at the code that writes the text out to the display, it handles the scrolling of the display automatically (for simplicity.)
I do concur that a WriteLine() function would be helpful, so I've added the following (based on your suggestions):
WriteLine(lineno, text)
WriteLineBin(lineno, chars)
WriteTextBin(lineno, chars)
Quoted 10 lines
- hidd is not always initialized correctly. You can connect the MediaPad on two different ways. First is to run hidd --search and press the connect button on the MediaPad. This is a bit ugly compared to the second method but correctly initializes your DBus-interface (and does not show the NAV-led) The second method is to just press a key on the MediaPad. It will connect and will be visible to hidd, but the connection method in hidd is not run and therefore the DBUS-interface is not available. (But the NAV-led works) I think this is not a problem with the work you done, but maybe it helps us to improve the usage of the MediaPad.
The "second method" is because hidd passes the connection into the kernel's bluetooth HID driver (which should really be in userspace, IMHO) - and thus is "never heard from again."
Quoted 5 lines
As a conclusion I would like to suggest that we have one or two more reviews on the code and then resend it to the bluez-devel list and confirm that it is working. Then we could share some better code and the confirmation seems to be neccessary to make the maintainer include a patch. (Some kind of approval by other users?)
Attached is an patch against my previous version, for both the python script, and the driver. I've CC'd this to the list. FYI, I'll be updating the patch on my website here shortly.
Pardon my nit-picking, however, I did notice a couple bugs in the patch you attached:
Quoted 7 lines
+ +struct mpcmd {
(quoted diff) +5
-0+ char command[22]; + uint8_t len; +}; + +/*
Review
Quoted 10 lines
(quoted diff) +10
-0+ * Send raw data to the MediaPad + * The data does not require the 0xa2 at the beginning + */ +static void send_raw_data(int sock, char *data, int length) { + struct mpcmd lcdwi; + if (!data || sock < 4) return; + memcpy(&lcdwi,write_raw,sizeof(struct mpcmd)); + int i; + for (i = 0; i < length; i++) { + lcdwi.command[i + 1] = data[i];
This will cause a segfault by writing past the end of lcdwi.command if (i+1) > 22, or by reading beyond the end of data if i is beyond the end of data.
Review
Quoted 3 lines
(quoted diff) +3
-0+ } + + write(sock,lcdwi.command,length+1);
Again, another potential segfault (if length + 1 > 22)
Quoted 1 line
+}
Regards,
Tim
hidd/fakehid.c +131 -11
@@ -522,20 +522,25 @@ }/************************ Logitech Mediapad Driver ******************************** -* (C) 2006 Tim Hentenaar <[email protected]> * +* (C) 2006-2007 Tim Hentenaar <[email protected]> * * Licensed under the GNU General Public License. * * The latest version of this work is available at http://hentenaar.com * * * +* Updates: * +* Thanks to Glen Rolle for suggesting the single-line write * +* mode, and for showing me a better method for writing chars * +* >= 0x80 from python. +* * * Notes: * -* 1) The i18n for the device isn't currently supported. * -* The way that the i18n works, is that when the device * -* connects, the Winblows app retrieves the respective * -* strings from the device and verifies/updates them. * +* 1) The i18n for the device isn't currently supported. * +* The way that the i18n works, is that when the device * +* connects, the Winblows app retrieves the respective * +* strings from the device and verifies/updates them. * * * -* Simple enough to do, but I'll worry about it later. * -* 2) The '000' key actually sends 3 0's and is not a special key. * -* 3) The "Copy calulator result to clipboard" requires an * -* activation packet that I haven't isolated to date. * +* Simple enough to do, but I'll worry about it later. * +* 2) The '000' key actually sends 3 0's and is not a special key. * +* 3) The "Copy calulator result to clipboard" requires an * +* activation packet that I haven't isolated to date. * * 4) Git-R-Done! * **********************************************************************************/
@@ -586,7 +591,21 @@ {{ 0xA2, 0x10, 0x00, 0x83, 0x11, 0x00, 0x00, 0x00 }, 8}, {{ 0 }, 0} }; + +struct mpcmd write_lcd_single[] = { /* Write a single line of text to the LCD */ + {{ 0xA2, 0x10, 0x00, 0x81, 0x10, 0x00, 0x00, 0x00 }, 8}, + {{ 0xA2, 0x10, 0x00, 0x80, 0x12, 0x10, 0x10, 0x10 }, 8}, + {{ 0xA2, 0x10, 0x00, 0x81, 0x10, 0x00, 0x00, 0x00 }, 8}, + {{ 0xA2, 0x11, 0x00, 0x82, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }, 21}, + {{ 0xA2, 0x11, 0x00, 0x82, 0x21, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }, 21}, + {{ 0xA2, 0x11, 0x00, 0x82, 0x22, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }, 21}, + {{ 0xA2, 0x10, 0x00, 0x80, 0x12, 0x10, 0x10, 0x10 }, 8}, + {{ 0xA2, 0x10, 0x00, 0x83, 0x11, 0x00, 0x00, 0x00 }, 8}, + {{ 0 }, 0} +}; + #define N_LCDW_CMDS 14 +#define N_LCDS_CMDS 8 /* LCD Line Flags */ #define LCD_LINE_DISPLAY 0x10
@@ -646,6 +665,20 @@" <!-- Max Length: 144 -->\n" " <arg name=\"text\" type=\"s\" direction=\"in\"/>\n" " </method>\n" +" <method name=\"WriteLine\">\n" +" <!-- Max Length: 48 -->\n" +" <arg name=\"lineno\" type=\"u\" direction=\"in\"/>\n" +" <arg name=\"text\" type=\"s\" direction=\"in\"/>\n" +" </method>\n" +" <method name=\"WriteTextBin\">\n" +" <!-- Max Length: 144 -->\n" +" <arg name=\"text\" type=\"ai\" direction=\"in\"/>\n" +" </method>\n" +" <method name=\"WriteLineBin\">\n" +" <!-- Max Length: 48 -->\n" +" <arg name=\"lineno\" type=\"u\" direction=\"in\"/>\n" +" <arg name=\"text\" type=\"ai\" direction=\"in\"/>\n" +" </method>\n" " </interface>\n" " </node>\n" ;
@@ -713,7 +746,6 @@while (setclk[i].len !=0 ) {write (sock,setclk[i].command,setclk[i].len); i++; } } -static void write_lcd_text (int sock,char *text) {char lines[16 *9 ];struct mpcmd *lcdw =NULL ;uint32_t i =0 ,z =0 ,line =0 ;uint8_t f1 =LCD_LINE_DISPLAY , f2 =LCD_LINE_DISPLAY , f3 =LCD_LINE_DISPLAY ;
@@ -748,10 +780,44 @@ lcdw[12 ].command[6 ] = f2; lcdw[12 ].command[7 ] = f3; i =0 ;while (lcdw[i].len !=0 ) {write (sock,lcdw[i].command,lcdw[i].len); i++; }free (lcdw); +} + +static void write_lcd_line (int sock,char *text,int lineno) { +char lines[16 *3 ];struct mpcmd *lcdw =NULL ;uint32_t i =0 ,z =0 ,line =0 ;uint8_t f =LCD_LINE_DISPLAY ; + +if (!text || sock <4 )return ; lineno = (lineno >3 ) ?3 : (lineno <=0 ) ?1 : lineno; +memset (lines,0x20 ,16 *3 ); z = (strlen (text) >16 *3 ) ?16 *3 :strlen (text); +for (i=0 ;i<z;i+=16 ) { + line = i /16 ; +memcpy (lines+(16 *line),text+i,((z-i) <16 ) ? (z-i) :16 ); + } + + lcdw =malloc (sizeof (struct mpcmd )*N_LCDS_CMDS ); +memcpy (lcdw,write_lcd_single,sizeof (struct mpcmd )*N_LCDS_CMDS ); + +/* Copy the line text */ +memcpy (lcdw[3 ].command+5 ,lines,16 ); +memcpy (lcdw[4 ].command+5 ,lines+16 ,16 ); +memcpy (lcdw[5 ].command+5 ,lines+(16 *2 ),16 ); + +/* Adjust the buffer numbers */ + *(lcdw[3 ].command+4 ) =0x20 +3 *(lineno-1 ); + *(lcdw[4 ].command+4 ) =0x21 +3 *(lineno-1 ); + *(lcdw[5 ].command+4 ) =0x22 +3 *(lineno-1 ); + +/* Adjust flags */ +if (z >16 ) { + f |=LCD_LINE_SCROLL |LCD_2_BUFFERS ; +if (z >16 *2 ) { f &=0xF0 ; f |=LCD_3_BUFFERS ; } + } + +/* Write the text */ + lcdw[1 ].command[4 + lineno] =LCD_LINE_INIT ; + i =0 ;while (lcdw[i].len !=0 ) {write (sock,lcdw[i].command,lcdw[i].len); i++; }free (lcdw); }int logitech_mediapad (int sock) { -DBusMessage *db_msg, *db_msg_reply;DBusConnection *db_conn =NULL ;DBusError db_err;DBusMessageIter db_args;dbus_uint32_t db_u1, db_u2; +DBusMessage *db_msg, *db_msg_reply;DBusConnection *db_conn =NULL ;DBusError db_err;DBusMessageIter db_args,db_sub;dbus_uint32_t db_u1, db_u2, db_u3;char buf[25 ], *cwtmp;struct pollfd p;int fd =0 , mode =0 , discard_keyup =0 , prev_key =0 , icons =0 , on_dbus =0 , last_dbus_poll =0 , ln =0 ;memset (&p,0 ,sizeof (struct pollfd )); p.fd = sock; p.events =POLLIN |POLLHUP |POLLERR ;
@@ -827,6 +893,60 @@ } }dinovo_dbus_do_reply (db_msg); + }else if (dbus_message_is_method_call (db_msg,"com.hentenaar.Dinovo.MediaPad" ,"WriteLine" )) { +/* WriteLine(lineno, text) Max Length: 48 */ +if (dbus_message_iter_init (db_msg,&db_args)) { +if (dbus_message_iter_get_arg_type (&db_args) ==DBUS_TYPE_UINT32 )dbus_message_iter_get_basic (&db_args,&db_u1); +if (dbus_message_iter_has_next (&db_args)) { +dbus_message_iter_next (&db_args); +if (dbus_message_iter_get_arg_type (&db_args) ==DBUS_TYPE_STRING ) { +dbus_message_iter_get_basic (&db_args,&cwtmp); +if (cwtmp &&strlen (cwtmp) >0 )write_lcd_line (sock,cwtmp,db_u1); + } + } + } +dinovo_dbus_do_reply (db_msg); + }else if (dbus_message_is_method_call (db_msg,"com.hentenaar.Dinovo.MediaPad" ,"WriteTextBin" )) { +/* WriteTextBin(chars) Max Length: 144 */ +if (dbus_message_iter_init (db_msg,&db_args)) { +if (dbus_message_iter_get_arg_type (&db_args) ==DBUS_TYPE_ARRAY ) { +dbus_message_iter_recurse (&db_args,&db_sub); +if ((cwtmp =malloc (1 +(16 *9 )))) { +memset (cwtmp,0 ,1 +(16 *9 )); +for (db_u1=0 ;db_u1<=16 *9 ;db_u1++) { +dbus_message_iter_get_basic (&db_sub,&db_u2); + cwtmp[db_u1] = (char )db_u2; +if (dbus_message_iter_has_next (&db_sub))dbus_message_iter_next (&db_sub); +else break ; + } +if (db_u1 >0 )write_lcd_text (sock,cwtmp); +free (cwtmp); + } + } + } +dinovo_dbus_do_reply (db_msg); + }else if (dbus_message_is_method_call (db_msg,"com.hentenaar.Dinovo.MediaPad" ,"WriteLineBin" )) { +/* WriteLineBin(lineno, chars) Max Length: 48 */ +if (dbus_message_iter_init (db_msg,&db_args)) { +if (dbus_message_iter_get_arg_type (&db_args) ==DBUS_TYPE_UINT32 )dbus_message_iter_get_basic (&db_args,&db_u1); +if (dbus_message_iter_has_next (&db_args)) { +dbus_message_iter_next (&db_args); +if (dbus_message_iter_get_arg_type (&db_args) ==DBUS_TYPE_ARRAY ) { +dbus_message_iter_recurse (&db_args,&db_sub); +if ((cwtmp =malloc (1 +(16 *3 )))) { +memset (cwtmp,0 ,1 +(16 *3 )); +for (db_u3=0 ;db_u3<=16 *3 ;db_u3++) { +dbus_message_iter_get_basic (&db_sub,&db_u2); + cwtmp[db_u3] = (char )db_u2; +if (dbus_message_iter_has_next (&db_sub))dbus_message_iter_next (&db_sub); +else break ; + } +if (db_u3 >0 )write_lcd_line (sock,cwtmp,db_u1);free (cwtmp); + } + } + } + } +dinovo_dbus_do_reply (db_msg); }else if (dbus_message_is_method_call (db_msg,"com.hentenaar.Dinovo.MediaPad" ,"SetIndicator" )) {/* SetIndicator(indicator, blink) * [ indicator := see LCD_ICON_* above ]
dinovo-dbus-test.py +45 -6
71 lines not on this page · raw message
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
Quoted 7 lines
Quoted 7 lines
- I have extended the interface for the lcd and added following functions. I wanted to have more atomic control over the LCD. =
-- WriteLine (
line_number,scroll_mode, string)
--- Write only a single line, so that you can set content and scroll mode separately for each line.
Quoted 7 lines
=
IMO, it's easier to have the driver auto-determine the scroll mode. =
This saves the programmer from having to deal with splitting up the text.
=
Yes, but then we are missing the scroll mode 0x20 which scrolls one line ch= aracter per character (like the html marque).
Maybe we should include a function like WriteScrollingLine, that sets this = scrolling mode. The autodetection scrolls only buffer-wise.
Quoted 11 lines
Quoted 5 lines
=
-- SetScreenMode (mode)
--- An easy way to switch between the 3-line display (0) and the clock display (1).=
You can switch back to the clock display by pressing "Clear Screen", and to the "3-line" mode by writing text. (This is so that alerts persist until the user presses "Clear Screen.")
=
This function is to allow a programme a more "atomic" control over the disp= lay.
Quoted 9 lines
Quoted 7 lines
=
-- SendRawData (
array_of_integers)
--- Mainly for testing and debugging purpose, so that you can send commands to the LCD without having to recompile fakehid all the time. The raw data starts with0x10and0x11resp. The0xA2will be send automaticallay.=
Quoted 8 lines
This could be useful under certain circumstances, however, there's really no need at this point to send raw data to the mediapad, because the functionality is quite complete (With the exception of the Nav indicator and the Calculator -> Clipboard, of course (I know how it works sending the data back (I've got code in place in the driver), but I can't seem to isolate the init packet.)) =
=
I use this function for testing purpose e. g. to evaluate what effect the c= ommand 0x83 0x00 0x00 0x00 has. (I still don't know ...). We can offer such=
a function for advanced users, though it is not essential.
Quoted 8 lines
Quoted 3 lines
It might be useful to split some of your funtions e. g. the WriteText into a "initScreen" part and the text display. (This would remove the flashing display when sending new text with WriteText.)
=
If you look at the code that writes the text out to the display, it handles the scrolling of the display automatically (for simplicity.) =
What I noticed between two sequential calls to WriteText was a short flasin= g on the display. The cause is the command 0x12 0x01 0x01 0x01 which hides = all three lines. We could avoid this flashing by separating the screen init= ializing and the actual text writing e. g.:
InitScreen:
0x80 0x00 0x00 0x00
0x12 0x01 0x01 0x01
0x81 0x00 0x00 0x00
WriteTextOnly:
0x20 ...
0x21 ...
...
0x28 ...
0x12 display modes
Quoted 1 line
I do concur that a
WriteLine()function would be helpful, so I've added t=
he following (based on your suggestions):
Quoted 7 lines
=
WriteLine(lineno, text)=
WriteLineBin(lineno, chars)
WriteTextBin(lineno, chars)
I had a look at the patch and think we should do some minor changes:
+ {{ 0xA2, 0x10, 0x00, 0x81, 0x10, 0x00, 0x00, 0x00 }, 8}, ## Should be 0x=
80 instead of 0x81
+ {{ 0xA2, 0x10, 0x00, 0x80, 0x12, 0x10, 0x10, 0x10 }, 8}, ## This would c=
hange the scroll mode on all three lines. Using 0x00 instead of 0x10 does n= ot change the display mode of the othr lines.
+ {{ 0xA2, 0x10, 0x00, 0x81, 0x10, 0x00, 0x00, 0x00 }, 8},
+ {{ 0xA2, 0x11, 0x00, 0x82, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20=
, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }, 21},
+ {{ 0xA2, 0x11, 0x00, 0x82, 0x21, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20=
, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }, 21},
+ {{ 0xA2, 0x11, 0x00, 0x82, 0x22, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20=
, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }, 21},
+ {{ 0xA2, 0x10, 0x00, 0x80, 0x12, 0x10, 0x10, 0x10 }, 8}, ## same as abov=
e.
+ {{ 0xA2, 0x10, 0x00, 0x83, 0x11, 0x00, 0x00, 0x00 }, 8}, ## Is this line=
really required? What does it do?
=
Quoted 10 lines
Quoted 10 lines
- hidd is not always initialized correctly. You can connect the MediaPad on two different ways. First is to run hidd --search and press the connect button on the MediaPad. This is a bit ugly compared to the second method but correctly initializes your DBus-interface (and does not show the NAV-led) The second method is to just press a key on the MediaPad. It will connect and will be visible to hidd, but the connection method in hidd is not run and therefore the DBUS-interface is not available. (But the NAV-led works) I think this is not a problem with the work you done, but maybe it helps us to improve the usage of the MediaPad.
Quoted 6 lines
=
The "second method" is because hidd passes the connection into the kernel's bluetooth HID driver (which should really be in userspace, IMHO) - and thus is "never heard from again."
That's bad. Any chance that we can change this behaviour? I would be much m= ore user-friendly not to have to call hidd manually. Marcel?
=
Quoted 2 lines
Pardon my nit-picking, however, I did notice a couple bugs in the patch you attached: =
That's why I did not send it to the list directly. :-)
Kind regards,
Glen.
-- =
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! =
Ideal f=FCr Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=3DDE=
VDEV
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel