Recent

Author Topic: Addition to IndustrialStuff Package  (Read 4673 times)

bobby100

  • Full Member
  • ***
  • Posts: 102
    • Malzilla
Addition to IndustrialStuff Package
« on: February 16, 2022, 11:26:06 pm »
I have added Flash function to the AdvLed.
Because at Lazarus CCR nobody cares to answer my question how to contribute the code, I'll just upload it here.

Flash function will flash the LED for the specified time (in milliseconds).
I use it to visualize the ongoing communication on the serial port. This way the user has some feedback if any communication is happening or not.
https://gitlab.com/bobby100 - my Lazarus components and units
https://sourceforge.net/u/boban_spasic/profile/ - my open source apps

https://malzilla.org/ - remainder at my previous life as a web security expert

Bart

  • Hero Member
  • *****
  • Posts: 4747
    • Bart en Mariska's Webstek
Re: Addition to IndustrialStuff Package
« Reply #1 on: February 16, 2022, 11:28:17 pm »
Maybe you can post this in the Lazarus-CCR bugtracker (see link on the panel on the left)?

Bart

bobby100

  • Full Member
  • ***
  • Posts: 102
    • Malzilla
Re: Addition to IndustrialStuff Package
« Reply #2 on: February 16, 2022, 11:31:18 pm »
Thanks Bart, I'll try as you suggested.
https://gitlab.com/bobby100 - my Lazarus components and units
https://sourceforge.net/u/boban_spasic/profile/ - my open source apps

https://malzilla.org/ - remainder at my previous life as a web security expert

wp

  • Hero Member
  • *****
  • Posts: 10045
Re: Addition to IndustrialStuff Package
« Reply #3 on: February 17, 2022, 12:32:42 am »
Don't post on the CCR sourceforge forum/tickets/feature requests etc - there is so little activity that I only rarely look if there is anything new.

Committed your patch with small modifications:

- added a Toggle() method which switches OFF to ON and ON to OFF (but only when LED is not disabled).
- added a "flash-from-ON-to-OFF" feature (you only provided "flash-from-OFF-to-ON")
- Flash() is ignored when LED.State is disabled.

I also added a demo project to show the features of the TAdvLED

bobby100

  • Full Member
  • ***
  • Posts: 102
    • Malzilla
Re: Addition to IndustrialStuff Package
« Reply #4 on: February 17, 2022, 12:43:35 am »
Thanks wp.
https://gitlab.com/bobby100 - my Lazarus components and units
https://sourceforge.net/u/boban_spasic/profile/ - my open source apps

https://malzilla.org/ - remainder at my previous life as a web security expert

bobby100

  • Full Member
  • ***
  • Posts: 102
    • Malzilla
Re: Addition to IndustrialStuff Package
« Reply #5 on: June 03, 2022, 09:46:25 am »
Would this be worth to be added to the IndustrialStuff package?
(screenshot in attachment)
https://gitlab.com/bobby100 - my Lazarus components and units
https://sourceforge.net/u/boban_spasic/profile/ - my open source apps

https://malzilla.org/ - remainder at my previous life as a web security expert

wp

  • Hero Member
  • *****
  • Posts: 10045
Re: Addition to IndustrialStuff Package
« Reply #6 on: June 03, 2022, 10:36:31 am »
Certainly. Upload the code so that I can have a look.
« Last Edit: June 03, 2022, 12:06:29 pm by wp »

bobby100

  • Full Member
  • ***
  • Posts: 102
    • Malzilla
Re: Addition to IndustrialStuff Package
« Reply #7 on: June 03, 2022, 01:01:00 pm »
I am not finished yet. There are graphic glitches.

The original code is LCDLine for Delphi, from Yuriy Tereshchenko, and it is an LCD screen with just one line of text (also scrollable).
This one is already ported to Lazarus (Avra ported the CodeTyphoon component).

I have added multi-line functionality, but it isn't ready yet.
Also, in original component is no license for the source code. Dunno how to publish a derived code.

There is another, better component - LCDScreen, but the CodeTyphoon's port from Delphi (and also Avra's port to Lazarus) are far from perfect. TBitmap.ScanLine is used, and this one renders the display in Lazarus port wrong.

Next step for me is to clean up the code (scrolling is not a thing for multi-line screen), and I'll upload the code after that.
https://gitlab.com/bobby100 - my Lazarus components and units
https://sourceforge.net/u/boban_spasic/profile/ - my open source apps

https://malzilla.org/ - remainder at my previous life as a web security expert

wp

  • Hero Member
  • *****
  • Posts: 10045
Re: Addition to IndustrialStuff Package
« Reply #8 on: June 03, 2022, 01:54:25 pm »
Thank you for working on these components. Just take your time and upload the code when you feel to be finished. Then I'll have a look and add it to CCR and, after a grace period for testing, to OPM.

As for the license, we should try to find the original units (CodeTyphon often drops the original authors) and check if there is some license information or a contact address (*). Maybe we should contact the original author and see if he accepts a license such as the LGPL with linking exception or similar (LGPL w/linking exception is my favourite because it is the same as used by the Lazarus LCL).

----
(*) There are an LCDInfo and an LCDScreen on torry (https://torry.net/quicksearchd.php?String=lcd&Title=Yes).

bobby100

  • Full Member
  • ***
  • Posts: 102
    • Malzilla
Re: Addition to IndustrialStuff Package
« Reply #9 on: June 04, 2022, 09:42:03 pm »
Torry's: LCDLine v1.00 by Uta Tera is the component I am porting/extending. In the source files is Yuriy Tereshtcheno mentioned as the author. The comments in the source code are written in Russian (no problem to read for me).

Torry's LCDScreen v3.00 by Jacques Voirin is the problematic one with TBitmap.ScanLine

I'll get back to this next week when I get back from vacation.
https://gitlab.com/bobby100 - my Lazarus components and units
https://sourceforge.net/u/boban_spasic/profile/ - my open source apps

https://malzilla.org/ - remainder at my previous life as a web security expert

bobby100

  • Full Member
  • ***
  • Posts: 102
    • Malzilla
Re: Addition to IndustrialStuff Package
« Reply #10 on: June 12, 2022, 11:20:28 pm »
Hi wp,

here is the current state of the code. I would say it is pretty much complete, but I have one problem...
If you compile the Test, you will see that the component frame isn't rendered like it should (it is black for most of the component variations on the form).
After minimizing the test app and maximizing it again - the rendering of the frame is OK.
Could you take a look?

EDIT: the problem exists on Windows 10, dunno about other OS-es and/or widgetsets
« Last Edit: June 12, 2022, 11:22:26 pm by bobby100 »
https://gitlab.com/bobby100 - my Lazarus components and units
https://sourceforge.net/u/boban_spasic/profile/ - my open source apps

https://malzilla.org/ - remainder at my previous life as a web security expert

wp

  • Hero Member
  • *****
  • Posts: 10045
Re: Addition to IndustrialStuff Package
« Reply #11 on: June 13, 2022, 12:26:01 am »
Nice. I'll adapt it to cooperate with LCL scaling and add it to the Industrial package.

The border is painted in black initially because you fell into the "famous 'with' trap": Your code in TLCDLines.DrawBorder is

Code: Pascal  [Select][+][-]
  1.  with BitMap.Canvas do
  2.  begin
  3.     ...
  4.     Rectangle(0, 0, Width, Height);      
  5.  

Because of the "with" the Width and Height refer to the same properties of the Canvas. But the Canvas does not yet have a handle at this moment, and thus Bitmap.Canvas.Width and Bitmap.Canvas.Height are returned as 0, and the rectangle is not painted at all.

Better to expand Width and Height to Bitmap.Width and Bitmap.Height:
Code: Pascal  [Select][+][-]
  1.  with BitMap.Canvas do
  2.  begin
  3.     ...
  4.     Rectangle(0, 0, Bitmap.Width, Bitmap.Height);      
  5.  

I'd remove the property "LinesCount" because it is already defined by the Lines.Count. Or is there a reason behind it which I do not understand?

bobby100

  • Full Member
  • ***
  • Posts: 102
    • Malzilla
Re: Addition to IndustrialStuff Package
« Reply #12 on: June 13, 2022, 06:23:05 am »
Thank you.

LinesCount is for adding empty lines if the LCD is defined bigger than the List.Count (e.g. you have LCD with two lines, but displaying just one line of text):
Code: Pascal  [Select][+][-]
  1. procedure TLCDLines.SetLines(const Value: TStringList);
  2. var
  3.   i: integer;
  4. begin
  5.   FLines.Clear;
  6.   for i := 0 to FLinesCount - 1 do
  7.   begin
  8.     if i < Value.Count then
  9.       FLines.Add(Value[i])
  10.     else
  11.       FLines.Add(' ');
  12.   end;
  13.   invalidate;
  14. end;

Important if you use AutoSize
« Last Edit: June 13, 2022, 06:34:27 am by bobby100 »
https://gitlab.com/bobby100 - my Lazarus components and units
https://sourceforge.net/u/boban_spasic/profile/ - my open source apps

https://malzilla.org/ - remainder at my previous life as a web security expert

bobby100

  • Full Member
  • ***
  • Posts: 102
    • Malzilla
Re: Addition to IndustrialStuff Package
« Reply #13 on: June 13, 2022, 06:29:20 am »
I also have problems with AutoSize overriding, that's why I've use LocalAutoSize.

btw. I still don't have an idea what should we do with the source code license
https://gitlab.com/bobby100 - my Lazarus components and units
https://sourceforge.net/u/boban_spasic/profile/ - my open source apps

https://malzilla.org/ - remainder at my previous life as a web security expert

wp

  • Hero Member
  • *****
  • Posts: 10045
Re: Addition to IndustrialStuff Package
« Reply #14 on: June 13, 2022, 11:21:31 am »
I also have problems with AutoSize overriding, that's why I've use LocalAutoSize.
You are changing the contol's Width and Height in the Paint method - this looks very risky to me because changing the size normally triggers another paint cycle. Better to do it the Lazarus way: Remove the FAutoSize and the redeclaration of Autosize, just leave "property AutoSize;". Then override the method "CalculatePreferredSize(var PreferredWidth, PreferredHeight: Integer; WithThemeSpace: Boolean)". Here you return in PreferredWidth and PreferredHeight the size that the auto-size control should have. The rest should work automatically.

There is one problem which I noticed looking at the code more carefully: unit LCDLines_char defines the pixel matrix for each character, but does this only for 255 characters. This means: the control is not ready for UTF-8, the Lazarus standard. And in fact scrolling down a bit, I see that the characters #192..#255 are russian cyrillic. I think this is a severe limitation.

To avoid this I had the idea to use the pixel matrix of a rendered font instead of a self-made table, and wrote the attached feasibility project: The text is drawn on a 1-bit bitmap. Then I read the pixels of the bitmap. Each black pixel is drawn as a bright square (or circle) on the destination canvas, each white pixel is the background and is rendered as a dark square. In this demo, reading the bitmap pixels is done by using the Bitmap.Canvas.Pixels[x,y] property which is normally avoided because it's slow, but since the bitmap should not be too small this will not be an issue (it can be optimized, though). Using a ready-made font for rendering the LCD display makes all characters of the font available for the component.

Merging this idea into your component and using some more Lazarus-specific code (AutoSize mentioned above, LCLScaling) makes it sufficiently different from the original so that we can use our own license for it. (As mentioned earlier, I prefer the LGPL with linking exception of the Lazarus-LCL).
« Last Edit: June 13, 2022, 11:25:21 am by wp »

 

TinyPortal © 2005-2018