While you are free to make any modifications you want to your own private copy as the code is open source, I would discourage that as you will then likely not be able to use future updates of the library without having to make modifications to your code.
(For example, the code you posted in the zip image is already behind the latest hd44780 release)
It would be better to help me to get the library updated to work with that display since I want the library to work with type of display as well.
(Although I think the font issue might be an issue that I may not want to solve - see below)
I guess in my earlier posts I should have been clearer by saying that the code should work with that display.
I don't have one of those to test with, and you are seeing the results of what happens when I can't actually test it. Normally I never release alpha code for this very reason. I don't like to give out code that doesn't work.
In terms of complexity the library architecture is actually not THAT complicated.
It uses virtual functions for the i/o classes but that allows the underlying code to be broken out into small layers that are very specific.
I would like to fix the library code to work correctly with that display.
I will need to get one of those devices to test with before the code will become bullet proof.
One thing that I did notice is that the pcf2119x chip designers totally screwed up the way they implemented their Function Set command. Their SL and M bits are bits 1 and 2 and they should have been bits 2 and 3 so that they would be compatible with the hd44780 F & N function set bits which are bits 2 and 3 and offer the same functionality.
That is why you needed to send the 0x34 command. Because they screwed up their hd44780 function set command. They use bit 2 instead of bit 3 to indicate a 2 line display.
IMO, what they did was unnecessary and VERY VERY stupid - seems like a rooky mistake on their part.
This will mean that there will always have to be something special done on this type of display, either in the library or in user code since in this particular aspect it deviates from the hd44780 interface.
I'll look at everything in more detail but this kind of sucks and I may have to create a hd44780_pcf2119x i/o class just to work around this to allow users to get that "it just works" experience.
It could be done using the 3rd parameter in begin() but I really don't like handling it that way as then it requires modifying actual sketch code when displays change and a major goal of this library is that device specific parameters are all in the constructor and not handled in application/sketch code.
It could also be handled by leaving the display in 1x32 mode but then altering the row offsets used by setCursor()
This is interesting because it would then also allow the to line to wrap to the 2nd line but again if there isn't a separate i/o class, the application has to do special things for this display - which is something that I REALLY want to avoid.
In terms of the font issue, this seems like another area where they REALLY screwed up.
The module appears come with one of 6 different fonts. A, D, F, I, R, S
The problem is that for fonts F, R, and S, they don't map the ASCII code points to ASCII character glyphs instead they move the ASCII code points up high. This is a very dumb thing to do.
Fonts A and I are good for ASCII, and D is usable with no lower case
but Fonts F, R and S are a disaster.
This one is not really workable in a generic way as ASCII pretty much won out about 40 years ago so pretty much everything assumes ASCII encoding at least for the lower 0x80 code points.
Yes there is UTF encoding which is used to support larger and varied fonts but supporting it is complex and simply isn't done very often as it requires using other data types than an 8 bit char and the the Arduino Print class doesn't and probably won't ever support it.
And even UTF assumes ASCII for the lower 0x80 code points.
I did some kludges in my openGLCD library to minimally support UTF but in reality it is not all that useful as all it does is allow simple UTF encoding for code points 0-255 which doesn't cover many/most of the fonts.
In this case the issue is that the sketch is sending ASCII codes but the font on the display module is not an ASCII font.
My recommendation would be get another display with one of the fonts that works with ASCII code points - Font A, D, or I with A or I being preferable.
If you insist on using a LCD module with on of the 'broken' fonts (F, R or S), then about the only easy thing that you could do is put a hack into the code to flip the upper and lower halves of the code points to move the near ASCII code points to the lower have of the code points.
But even that won't fix everything as there are some characters missing like: [ \ ] ^ { | } ~
And then there is the issue of how to handle the code points 0x0-0x0f and 0x80 to 0x8f
If you do a simple flip then the custom character code points would now be 0x80 to 0x8f.
You could do a simple additional check and only flip code points 0x10 to 0x7f and 0x90 to 0xff
That would keep the custom characters down low and preserver the code points 0x80 to 0x8f
Custom characters is going to be an issue.The reason being is that when a custom character is defined, normal writes is used. So it becomes a real issue of knowing when to do the code point bit flipping.
i.e. you want it flipped for sending character data but you don't want to mess with the data value when creating a custom code point. The issue is that the both look exactly the same to the i/o class.
Yes the hd44780 code could be updated track the additional state information and pass it down to the i/o class so that the i/o class can then know whether to do the code point flipping or to put the added code into the i/o class to figure out if a custom font is being defined, but that is not something I'm interested in doing & supporting.
IMO this is a case of the combination of a sketch sending ASCII code points and a LCD that does not support ASCII code points in its font and the library shouldn't have to solve this issue.
If you are willing to give up custom characters the changes are pretty minimal.
I'd recommend doing it in hd44780_I2Clcd rather than in hd44780 so that it won't break all the other devices.
It is only a single of code to do it using an exclusive or with 0x80 to flip the code upper/lower code points..
if(type == hd44780::HD44780_IOdata)
{
ctlbyte = I2Clcd_RS; // control byte with RS and no continue
value ^= 0x80; // flip the upper/lower code points
}
else
{
ctlbyte = 0; // control byte with no RS and no continue
}
This will flip the two halves of the code points so 0x-0x7f are now 0x80-0xff and 0x80-0xff is now 0x00-0x7f which should place the ascii glyphs in the correct location.
If you do this kind of custom modifications to the library, I'd recommend using git & github so you can merge in future hd44780 library updates. i.e. fork the code into your own github repo, then locally clone it into your sketchbook area that way you can push/pull changes back and forth between your local development area and your github repo and you can merge in changes from hd44780 and even do pull requests back to hd44780 if you think the code changes you have made are generic enough for the library.
I'll think on this font issue some more, like maybe about having a way to properly handle flipping the upper and lower code points of a font while still allowing custom fonts to work. But so far this seems to be an issue for this one display and an issue that can't be fully resolved no matter what is done in the library.
--- bill