Hi,

This patch add a new file to the DS2408 LCD_H/ directory: redefchar

It allows to redefine up to 8 chars corresponding to the ASCII codes 0 to 7. Once the chars are redefined, they can be displayed with screen* functions.

The format of the entry follows:
- each character definition is 17 bytes long (several characters can be defined at one time by concatenating their definition) - first char is the index of the redefined character: '0' -> '7' (human form) or '\0' -> '\10' (binary form) - 16 others define the 8 lines of each character, a pair of hexadecimal digit for each char between "00" and "1F" (or "1f", but see the note at the end). When a bit is set the corresponding pixel is on. For example:

18421 <- bits columns
..... => "00"
..#.. => "04"
.#.#. => "0A" (because 8 + 2)
#...# => "11"
#...# => "11"
.#.#. => "0A" (because 8 + 2)
..#.. => "04"
..... => "00"

So to define this character on ascii code '\1', we will use the string: "100040A11110A0400"

Other examples:
- an empty square on char '\6': "61F1111111111111F"
##### => "1F"
#...# => "11"
#...# => "11"
#...# => "11"
#...# => "11"
#...# => "11"
#...# => "11"
##### => "1F"

- a hourglass on char '\3' : "31F1F0E04040E1F1F"
##### => "1F"
##### => "1F"
.###. => "0E"
..#.. => "04"
..#.. => "04"
.###. => "0E"
##### => "1F"
##### => "1F"

- both in one write : "61F1111111111111F31F1F0E04040E1F1F"

Note that if redefined chars are already displayed on the LCD, redefining them again will change all of them on the display. This behavior is hard-coded in the LCD.

Note that one can redefine the character '\0' but it is not always easy to manipulate it and/or to display it due to libraries or interfaces constraints (like null terminated string handling)...

Lastly, this code use the function hex_digit() in ow_bae.c. This function does not work well for lower case hexadecimal digits, except if you apply the "ow_bae.c patch" I posted this morning.

Best regards,

Max.
--- owfs-2.8p14/module/owlib/src/c/ow_2408.c.orig       2012-01-09 
23:02:05.000000000 +0100
+++ owfs-2.8p14/module/owlib/src/c/ow_2408.c    2012-03-11 12:11:16.000000000 
+0100
@@ -86,6 +86,7 @@
 WRITE_FUNCTION(FS_Hscreenyx);
 WRITE_FUNCTION(FS_Hmessage);
 WRITE_FUNCTION(FS_Honoff);
+WRITE_FUNCTION(FS_Hredefchar);
 
 #define PROPERTY_LENGTH_LCD_MESSAGE   128
 
@@ -113,6 +114,7 @@
        {"LCD_H/screenyx", PROPERTY_LENGTH_LCD_MESSAGE, NON_AGGREGATE, 
ft_ascii, fc_stable, NO_READ_FUNCTION, FS_Hscreenyx, VISIBLE, 
NO_FILETYPE_DATA,},
        {"LCD_H/message", PROPERTY_LENGTH_LCD_MESSAGE, NON_AGGREGATE, ft_ascii, 
fc_stable, NO_READ_FUNCTION, FS_Hmessage, VISIBLE, NO_FILETYPE_DATA,},
        {"LCD_H/onoff", PROPERTY_LENGTH_UNSIGNED, NON_AGGREGATE, ft_unsigned, 
fc_stable, NO_READ_FUNCTION, FS_Honoff, VISIBLE, NO_FILETYPE_DATA,},
+       {"LCD_H/redefchar", PROPERTY_LENGTH_LCD_MESSAGE, NON_AGGREGATE, 
ft_ascii, fc_stable, NO_READ_FUNCTION, FS_Hredefchar, VISIBLE, 
NO_FILETYPE_DATA,},
 };
 
 DeviceEntryExtended(29, DS2408, DEV_alarm | DEV_resume | DEV_ovdr, 
NO_GENERIC_READ, NO_GENERIC_WRITE);
@@ -583,6 +585,63 @@
        return 0;
 }
 
+// (xL1..L8)+
+// x = character index from '0' to '7' OR from '\0' to '\10'
+// Ln = hexa double digit for each line from "00" to "1f"
+extern int hex_digit(BYTE c); // from ow_bae.c
+static ZERO_OR_ERROR FS_Hredefchar(struct one_wire_query *owq)
+{
+       struct parsedname *pn = PN(owq);
+       char *buf = OWQ_buffer(owq);
+       size_t size = OWQ_size(owq);
+       BYTE data[size * 2]; // worst case
+       size_t i, j, k;
+       int num;
+
+       RETURN_ERROR_IF_BAD( OW_Hinit(pn) ) ;
+
+       if (size < 17) {
+               return -EINVAL;
+       }
+
+       i = j = 0;
+       do {
+               if (*buf < '0' || *buf > '7') {
+                       if (*buf <= 7) {
+                               num = buf[i++]; // binary
+                       } else {
+                               LEVEL_DEBUG("Can only redefine chars from 0 to 
7");
+                               return -EINVAL ;
+                       }
+               } else {
+                       num = buf[i++] - '0';
+               }
+
+               num *= 8;
+               num += 0x40;
+
+               data[j++] = (num & 0xF0);
+               data[j++] = (num << 4) & 0xF0;
+
+               // The eigth definition lines (2 hex digits / line)
+               for (k = i + 16; i < k; i += 2) {
+                       num = hex_digit(buf[i]) * 16 + hex_digit(buf[i + 1]);
+                       if (num < 0 || num > 0x1f) {
+                               LEVEL_DEBUG("A redef char line must be a 
hexadecimal integer < 0x1f");
+                               return -EINVAL ;
+                       }
+
+                       data[j++] = (num & 0xF0) | 0x08;
+                       data[j++] = ((num << 4) & 0xF0) | 0x08;
+               }
+
+               size -= 17;
+       }
+       while (size >= 17);
+
+       return GB_to_Z_OR_E( OW_w_pios(data, j, pn) ) ;
+}
+
 /* Read 6 bytes --
    0x88 PIO logic State
    0x89 PIO output Latch state
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Owfs-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/owfs-developers

Reply via email to