chronometer

chronometer

Postby damianodec » Fri Nov 23, 2018 7:26 am

hi to all
I need a chronometer in a dialog.
two buttons, one start and one stop and a field with chornometer:

START HH:MM:SS STOP

any example?

thank you
FiveWin for xHarbour 17.09 - Sep. 2017 - Embarcadero C++ 7.00 for Win32
FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)
Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
User avatar
damianodec
 
Posts: 419
Joined: Wed Jun 06, 2007 2:58 pm
Location: Italia

Re: chronometer

Postby nageswaragunupudi » Fri Nov 23, 2018 8:59 am

Code: Select all  Expand view  RUN
#include "fivewin"

function Main()

   local oDlg, oSay, oTimer, oFont, oBold, nSecs

   DEFINE FONT oFont NAME "Segoe UI" SIZE 0,-16
   DEFINE FONT oBold NAME "Segoe UI" SIZE 0,-34

   DEFINE DIALOG oDlg SIZE 500,120 PIXEL TRUEPIXEL FONT oFont

   @ 40, 40 BTNBMP PROMPT "START" SIZE 100,40 PIXEL OF oDlg FLAT ACTION ( nSecs := SECONDS() )

   @ 40,170 SAY oSay PROMPT { || If( nSecs == nil, "00:00:00", SECTOTIME( SECONDS() - nSecs ) ) } ;
      SIZE 160,40 PIXEL OF oDlg FONT oBold CENTER VCENTER UPDATE ;
      COLOR CLR_YELLOW, CLR_CYAN

   @ 40,360 BTNBMP PROMPT "STOP"  SIZE 100,40 PIXEL OF oDlg FLAT ;
      ACTION ( nSecs := nil, oSay:Refresh() )

   oDlg:bInit := <||
      DEFINE TIMER oTimer OF oDlg INTERVAL 100 ACTION If( nSecs == nil,,oSay:Refresh() )
      ACTIVATE TIMER oTimer
      return nil
      >

   ACTIVATE DIALOG oDlg CENTERED ;
      VALID ( oTimer:End(), .t. )

   RELEASE FONT oFont, oBold

return nil
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10662
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: chronometer

Postby damianodec » Fri Nov 23, 2018 10:49 am

very good mr.Rao

thank you!
FiveWin for xHarbour 17.09 - Sep. 2017 - Embarcadero C++ 7.00 for Win32
FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)
Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
User avatar
damianodec
 
Posts: 419
Joined: Wed Jun 06, 2007 2:58 pm
Location: Italia

Re: chronometer

Postby Euclides » Fri Nov 23, 2018 3:54 pm

Anyway, thanks Mr. Rao!
I have a very complicated routine to do almost the same thing... (back from the Clipper code)
I changed a little bit the code with your permission (I hope) and works fine to me.
It shows the result time (in cents of seconds) and resets the value with the second "STOP"
It can be tested just hiting the Enter Key.
Code: Select all  Expand view  RUN

function Main()
local oDlg, oSay, oTimer, oFont, oBold, nSecs, cTimStop:="00:00:00::00", oBt1, oBt2

   DEFINE FONT oFont NAME "Segoe UI" SIZE 0,-16
   DEFINE FONT oBold NAME "Segoe UI" SIZE 0,-34

   DEFINE DIALOG oDlg SIZE 500,120 PIXEL TRUEPIXEL FONT oFont

   @ 40, 25 BTNBMP oBt1 PROMPT "START" SIZE 100,40 PIXEL OF oDlg FLAT ACTION ( nSecs := SECONDS(), oBt2:SetFocus() )

   @ 40,155 SAY oSay PROMPT { || If( nSecs == nil, cTimStop, SECTOTIME( SECONDS() - nSecs,.T. ) ) } ;
      SIZE 190,40 PIXEL OF oDlg FONT oBold CENTER VCENTER UPDATE ;
      COLOR CLR_YELLOW, CLR_CYAN

   @ 40,375 BTNBMP oBt2 PROMPT "STOP"  SIZE 100,40 PIXEL OF oDlg FLAT ;
      ACTION ( cTimStop := iif(nSecs = nil, ( oBt1:SetFocus(), "00:00:00::00"),  SECTOTIME( SECONDS() - nSecs,.T.)), nSecs := nil , oSay:Refresh() )

   oDlg:bInit := <||
      DEFINE TIMER oTimer OF oDlg INTERVAL 100 ACTION If( nSecs == nil,,oSay:Refresh() )
      ACTIVATE TIMER oTimer
      return nil
      >
   ACTIVATE DIALOG oDlg CENTERED VALID ( oTimer:End(), .t. )
   RELEASE FONT oFont, oBold
return nil
 

Always is nice to see (and learn) your solutions...
Regards, Euclides
User avatar
Euclides
 
Posts: 156
Joined: Wed Mar 28, 2007 1:19 pm

Re: chronometer

Postby Silvio.Falconi » Fri Nov 23, 2018 4:33 pm

Friends,
there is My Tled class it make also a chronometer
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7076
Joined: Thu Oct 18, 2012 7:17 pm

Re: chronometer

Postby nageswaragunupudi » Sat Nov 24, 2018 3:06 am

I still remember the beautiful screenshots posted by Mr. Silvio long time back. You can see if his solution meets your requirements.

Mr. Euclides,

Nice changes. Taking forward your changes I altered my program. Please check if this is ok with you.
Code: Select all  Expand view  RUN
#include "fivewin.ch"

function Main()

   local nSecsLapsed

   nSecsLapsed := ChronoMeter()

   ? nSecsLapsed, SECTOTIME( nSecsLapsed, .t. )

return nil

function ChronoMeter()

   local oDlg, oSay, oBtnStart, oBtnStop, oTimer, oFont, oBold
   local nStartSec, nSecsLapsed := 0

   DEFINE FONT oFont NAME "Segoe UI" SIZE 0,-16
   DEFINE FONT oBold NAME "Segoe UI" SIZE 0,-32

   DEFINE DIALOG oDlg SIZE 500,120 PIXEL TRUEPIXEL FONT oFont

   @ 40, 40 BTNBMP oBtnStart PROMPT "START" SIZE 100,40 PIXEL OF oDlg FLAT ;
      WHEN nStartSec == nil ;
      ACTION ( nStartSec := SECONDS(), oBtnStop:SetFocus() )

   @ 40,170 SAY oSay PROMPT { || SECTOTIME( nSecsLapsed, .t. ) } ;
      SIZE 160,40 PIXEL OF oDlg FONT oBold CENTER VCENTER UPDATE ;
      COLOR CLR_HGREEN, CLR_BLACK

   @ 40,360 BTNBMP oBtnStop PROMPT { || If( nStartSec == nil .and. nSecsLapsed > 0, "CLEAR", "STOP" ) } ;
      SIZE 100,40 PIXEL OF oDlg FLAT UPDATE ;
      WHEN nStartSec != nil .or. nSecsLapsed > 0 ACTION ( ;
      If( nStartSec == nil, ;
      If( nSecsLapsed > 0, nSecsLapsed := 0, nil ), ;
      ( nSecsLapsed := SECONDS() - nStartSec, nStartSec := nil ) ), ;
      oDlg:Update(), oBtnStart:SetFocus() )

   oDlg:bInit := <||
      DEFINE TIMER oTimer OF oDlg INTERVAL 100 ;
         ACTION If( nStartSec == nil,,( nSecsLapsed := SECONDS() - nStartSec,oSay:Refresh() ) )
      ACTIVATE TIMER oTimer
      return nil
      >

   ACTIVATE DIALOG oDlg CENTERED ;
      VALID ( oTimer:End(), .t. )

   RELEASE FONT oFont, oBold

return nSecsLapsed
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10662
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: chronometer

Postby Silvio.Falconi » Sat Nov 24, 2018 9:59 am

Mr. Rao
Can you set until ten stops ?

on my class I can make

Local cMessage:= "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
oLed2:= TLed():New(20, 10, oDlg,cMessage)

@ 19, 10 say "sample TLed with Chronometer" of oDlg size 100,10

oLed2:nLedLines := 0 // one linea
oLed2:lChronometer := .t.
oLed2:nLedHeight := 8
oLed2:nLedWidth := 6
oLed2:nLedSpace := 2

@ 20,10 Button "Stop" size 60,20 of oDlg ACTION (oLed2:StopChrono() )
@ 20,22 Button "Go" size 60,20 of oDlg ACTION oLed2:PlayChrono()
@ 20,34 Button "Reset" size 60,20 of oDlg ACTION oLed2:ResetChrono()
@ 20,50 Button "Save partials" size 60,20 of oDlg ACTION ( Aadd(aPartial,oLed2:cTxtLin1) )
@ 20,70 Button "Show Partials" size 60,20 of oDlg ACTION xbrowse(aPartial)


Image

download from https://github.com/silviofalconi/Tled
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7076
Joined: Thu Oct 18, 2012 7:17 pm

Re: chronometer

Postby nageswaragunupudi » Sat Nov 24, 2018 1:56 pm

Mr. Silvio

You already have it.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10662
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: chronometer

Postby Silvio.Falconi » Sat Nov 24, 2018 3:49 pm

:)
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7076
Joined: Thu Oct 18, 2012 7:17 pm

Re: chronometer

Postby Euclides » Sat Nov 24, 2018 6:50 pm

Silvio, did you try compile TLED with Harbour??
I strongly REFUSE to use xHarbour...
Euclides
User avatar
Euclides
 
Posts: 156
Joined: Wed Mar 28, 2007 1:19 pm

Re: chronometer

Postby Silvio.Falconi » Sun Nov 25, 2018 10:22 am

???
why ?
I compile with xharbour and harbour what's mean ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7076
Joined: Thu Oct 18, 2012 7:17 pm

Re: chronometer

Postby damianodec » Thu Nov 29, 2018 2:36 pm

hi mr Rao,
your function works good but what happened when I press started button at 11:59:40 pm ? reset Seconds?
Users have to use this chrono all days, 24/24 7/7, night and day and will be work always.
FiveWin for xHarbour 17.09 - Sep. 2017 - Embarcadero C++ 7.00 for Win32
FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)
Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
User avatar
damianodec
 
Posts: 419
Joined: Wed Jun 06, 2007 2:58 pm
Location: Italia

Re: chronometer

Postby nageswaragunupudi » Thu Nov 29, 2018 3:52 pm

damianodec wrote:hi mr Rao,
your function works good but what happened when I press started button at 11:59:40 pm ? reset Seconds?
Users have to use this chrono all days, 24/24 7/7, night and day and will be work always.


Please try:
Code: Select all  Expand view  RUN
#include "fivewin.ch"

function Main()

   local nSecsLapsed

   nSecsLapsed := ChronoMeter()

   ? nSecsLapsed, SECTOTIME( nSecsLapsed, .t. )

return nil

function ChronoMeter()

   local oDlg, oSay, oBtnStart, oBtnStop, oTimer, oFont, oBold
   local nStartSec, nSecsLapsed := 0

   DEFINE FONT oFont NAME "Segoe UI" SIZE 0,-16
   DEFINE FONT oBold NAME "Segoe UI" SIZE 0,-32

   DEFINE DIALOG oDlg SIZE 500,120 PIXEL TRUEPIXEL FONT oFont

   @ 40, 40 BTNBMP oBtnStart PROMPT "START" SIZE 100,40 PIXEL OF oDlg FLAT ;
      WHEN nStartSec == nil ;
      ACTION ( nStartSec := SECONDS(), oBtnStop:SetFocus() )

   @ 40,170 SAY oSay PROMPT { || SECTOTIME( nSecsLapsed, .t. ) } ;
      SIZE 160,40 PIXEL OF oDlg FONT oBold CENTER VCENTER UPDATE ;
      COLOR CLR_HGREEN, CLR_BLACK

   @ 40,360 BTNBMP oBtnStop PROMPT { || If( nStartSec == nil .and. nSecsLapsed > 0, "CLEAR", "STOP" ) } ;
      SIZE 100,40 PIXEL OF oDlg FLAT UPDATE ;
      WHEN nStartSec != nil .or. nSecsLapsed > 0 ACTION ( ;
      If( nStartSec == nil, ;
      If( nSecsLapsed > 0, nSecsLapsed := 0, nil ), ;
      ( nSecsLapsed := SecsLapsed( nStartSec ), nStartSec := nil ) ), ;
      oDlg:Update(), oBtnStart:SetFocus() )

   oDlg:bInit := <||
      DEFINE TIMER oTimer OF oDlg INTERVAL 100 ;
         ACTION If( nStartSec == nil,,( nSecsLapsed := SecsLapsed( nStartSec ),oSay:Refresh() ) )
      ACTIVATE TIMER oTimer
      return nil
      >

   ACTIVATE DIALOG oDlg CENTERED ;
      VALID ( oTimer:End(), .t. )

   RELEASE FONT oFont, oBold

return nSecsLapsed

static function SecsLapsed( nStart )

   local nLapsed := 0

   if nStart != nil
      nLapsed  := SECONDS() - nStart
      if nLapsed < 0
         nLapsed   += 86400.0
      endif
   endif

return nLapsed
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10662
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: chronometer

Postby Silvio.Falconi » Fri Nov 30, 2018 12:10 pm

Sorry,
I saw there is a oldest release on github and now there is the right release of Tled 1.00 run also on Harbour

Image

Code: Select all  Expand view  RUN

CLASS TLed FROM TControl

       CLASSDATA lRegistered AS LOGICAL

   DATA  lBorder         AS LOGICAL INIT .T.
   DATA  nBorderLine     AS NUMERIC INIT 3

   DATA  nColorBorder    AS NUMERIC INIT  nRGB(   3,  56, 147 )
   DATA  nColorBack      AS NUMERIC INIT  nRGB(  89, 135, 214 )
   DATA  nColorLedOFF    AS NUMERIC INIT  nRGB( 125, 165, 224 )
   DATA  nColorLedON     AS NUMERIC INIT  nRGB( 247, 192, 91 )

   DATA  nLedWidth       AS NUMERIC INIT 3
   DATA  nLedHeight      AS NUMERIC INIT 5
   DATA  nLedSpace       AS NUMERIC INIT 1

   DATA cTxtLin1         INIT "Linea 1"
   DATA cTxtLin2         INIT "Linea 2"

   DATA cMessage         INIT ""

   DATA aLinea1         AS ARRAY   INIT {}
   DATA aLinea2         AS ARRAY   INIT {}


   DATA lBlink          AS LOGICAL INIT .F.
   DATA lStatus         AS LOGICAL INIT .F. //internal
   DATA lTimeDate       AS LOGICAL INIT .F.
   DATA lStatusTime     AS LOGICAL INIT .F.  //internal
   DATA lBeep           AS LOGICAL INIT .F.

   DATA  oTimer          READONLY   //internal
   DATA  oOut            READONLY    //internal
   DATA  nInterval       AS NUMERIC INIT  700

   DATA  nLedLines       AS NUMERIC INIT  2
   DATA  nLedCharacters  AS NUMERIC INIT 20

   DATA   lChronometer   AS LOGICAL INIT .F.
   DATA   oTimerKrono    READONLY
   DATA   n_secs       //FOR CHRONPMETER



     METHOD New( nTop, nLeft, oWnd, cMessage, nBorderLine, lPixel, lBorder , nColorBack ) CONSTRUCTOR
     METHOD ReDefine( nId, oWnd ) CONSTRUCTOR
     METHOD Display() INLINE ::BeginPaint(), ::Paint(), ::EndPaint(), 0
     METHOD Paint()
     METHOD _FillRect( nTop, nLeft, nBottom, nRight, nColor )
     METHOD Initiate( hDlg ) INLINE ::Super:Initiate( hDlg ), ::Default()
     METHOD Default()
     METHOD CheckLines()
     METHOD GetCode( cChar )
     METHOD Resize()
     METHOD AdjustText()
     METHOD TimeDate()
     METHOD Blink()
     METHOD StopTime()
     METHOD StopBlink()  INLINE ::oOut:deactivate()
     METHOD Chronometer()
     METHOD StopChrono()   INLINE ::oTimerKrono:deactivate()
     METHOD ResetChrono()  INLINE ( ::StopChrono(), ::cTxtLin1:=space(3)+"00:00:00:000", ::refresh(.t.) )
     METHOD PlayChrono()   INLINE ( if(::lChronometer, ::StopChrono(),), ::cTxtLin1:=space(3)+"00:00:00:000", ::n_secs:=seconds(),::oTimerKrono:activate())


  ENDCLASS




METHOD New( nTop, nLeft, oWnd, cMessage, nBorderLine, lPixel, lBorder , nColorBack) CLASS TLed

DEFAULT  nTop     := 0, nLeft := 0           ,;
         oWnd := GetWndDefault()             ,;
         nBorderLine := 3                    ,;
         lPixel   := .f.                     ,;
         lBorder  := .t.                     ,;
         nColorBack := nRGB(  89, 135, 214 ) ,;
         cMessage   := "Fivewin TLed        (*) For Harbour (*)"



       ::nStyle    = nOR( WS_CHILD, WS_VISIBLE, WS_TABSTOP )
       ::nId       = ::GetNewId()
       ::oWnd      = oWnd

       ::nTop      = If( lPixel, nTop, nTop * SAY_CHARPIX_H )
       ::nLeft     = If( lPixel, nLeft, nLeft * SAY_CHARPIX_W )

       ::cMessage  = cMessage
       ::nLedLines = 2






       ::AdjustText()

     *  ::Register()
       ::Register( nOR( CS_VREDRAW, CS_HREDRAW ) )
        ::n_secs:=seconds()

       if ! Empty( oWnd:hWnd )
          ::Create()
          ::Default()
          oWnd:AddControl( Self )
       else
          oWnd:DefControl( Self )
       endif


   if ::lDrag
      ::CheckDots()
   endif


    return Self


//----------------------------------------------------------------------------------------//
METHOD ReDefine( nId, oWnd )  CLASS TLed


   return Self


METHOD StopTime() CLASS TLed
    IF  ::oTimer != NIL
       ::oTimer:deactivate()
    ELSE
       ::Default()
      endif
  return nil












//----------------------------------------------------------------------------------------//
/*
 METHOD Paint()      CLASS TLed
    Local aRect       := GetClientRect( ::hWnd )
    Local nMidLine,hPen,hOldPen
    Local k,w
    Local nLinea,nCar,aChar,cFila
    Local nLineax:= 0
    Local nLineay:= 0
    Local nColorPixel
    Local hDC         := ::hDC
    Local aInfo       := ::DispBegin()

     //background
   ::_FillRect( aRect[1], aRect[2], aRect[3],aRect[4], ::nColorBack )



     //control and create aLinea
   ::CheckLines()



 For nHeight := 0 to ::nLedLines  // 2 lines
         aLinea := IIF( nHeight == 0, ::aLinea1, ::aLinea2 )
         For nWidth := 0 to (::nLedCharacters-1)     // 20 characters
            aChar := aLinea[nWidth + 1]
            For k := 0 to 7    // 8 pixel
               nLineax := ( nHeight * ( ( ::nLedHeight * 9 ) + ( ::nLedSpace * 8 ) ) ) + ( k * ( ::nLedHeight +  ::nLedSpace ) ) + ( ::nLedHeight + 3 )
               cFila := aChar[k+1]
               For w := 0 to 4
                  nLineay := ( nWidth * ( ( ::nLedWidth * 7 ) + ( ::nLedSpace * 4 ) ) ) + ( w * ( ::nLedWidth + ::nLedSpace ) ) + ( ::nLedHeight + 3 )
                  nColorPixel := IIF( cFila[w+1] == SYMBOL_LED, ::nColorLedON, ::nColorLedOFF)
                 FillSolidRect(::hDC, { nLineax, nLineay, nLineax + ::nLedWidth, nLineay + ::nLedHeight} , nColorPixel)
              Next

            Next
         Next
      Next




   //Border

  If ::lBorder
      hPen := CreatePen( 0, ::nBorderLine, ::nColorBorder )
      hOldPen := SelectObject( ::hDc, hPen )
      nMidLine := ::nBorderLine / 2
      MoveTo( ::hDC, nMidLine, nMidLine )
      LineTo(::hDC, nMidLine, ::nHeight - nMidLine , hPen )
      LineTo(::hDC, ::nWidth - nMidLine, ::nHeight - nMidLine , hPen )
      LineTo(::hDC, ::nWidth - nMidLine , nMidLine, hPen )
      LineTo(::hDC, nMidLine, nMidLine, 0, hPen )
    ENDIF




   ::DispEnd( aInfo )
   return 0
   */


    METHOD Paint()      CLASS TLed
    Local aRect       := GetClientRect( ::hWnd )
    Local nMidLine,hPen,hOldPen
    Local k,w
    Local aChar,cFila
    Local nLineax:= 0
    Local nLineay:= 0
    Local nColorPixel
    Local hDC         := ::hDC
    Local nHeight,nWidth
    Local aLinea
    Local aInfo       := ::DispBegin()


     //background
   ::_FillRect( aRect[1], aRect[2], aRect[3],aRect[4], ::nColorBack )

   /*
    If ::lBorder
      hPen := CreatePen( 0, ::nBorderLine, ::nColorBorder )
      hOldPen := SelectObject( ::hDc, hPen )
      nMidLine := ::nBorderLine / 2
      MoveTo( ::hDC, nMidLine, nMidLine )
      LineTo(::hDC, nMidLine, ::nHeight - nMidLine , hPen )
      LineTo(::hDC, ::nWidth - nMidLine, ::nHeight - nMidLine , hPen )
      LineTo(::hDC, ::nWidth - nMidLine , nMidLine, hPen )
      LineTo(::hDC, nMidLine, nMidLine, 0, hPen )
   ENDIF
     */


   if ::lBorder
     BoxEx( ::hDC, GetClientRect( ::hWnd ), ::nColorBorder )
   endif







   //control and create aLinea
   ::CheckLines()


       For nHeight := 0 to (::nLedLines-1)  // 2 lines
         aLinea := IIF( nHeight == 0, ::aLinea1, ::aLinea2 )
         For nWidth := 0 to (::nLedCharacters-1)     // 20 characters
            aChar := aLinea[nWidth + 1]
            For k := 0 to 7    // 8 pixel
               nLineax := ( nHeight * ( ( ::nLedHeight * 9 ) + ( ::nLedSpace * 8 ) ) ) + ( k * ( ::nLedHeight +  ::nLedSpace ) ) + ( ::nLedHeight + 3 )
               cFila := aChar[k+1]
              For w := 0 to 4
                  nLineay := ( nWidth * ( ( ::nLedWidth * 7 ) + ( ::nLedSpace * 4 ) ) ) + ( w * ( ::nLedWidth + ::nLedSpace ) ) + ( ::nLedHeight + 3 )
                  //XHARBOUR
                  *  nColorPixel := IIF( cFila[w+1] == SYMBOL_LED, ::nClrLedON, ::nClrLedOFF)   //xharbour

                //HARBOUR
                nColorPixel :=  IIF( SubStr(cFila, w+1, 1)  == SYMBOL_LED, ::nColorLedON, ::nColorLedOFF)
                FillSolidRect(::hDC, { nLineax, nLineay, nLineax + ::nLedWidth, nLineay + ::nLedHeight} , nColorPixel)
              Next

            Next
         Next
      Next
   ::DispEnd( aInfo )
   return 0

//----------------------------------------------------------------------------------------//

  METHOD Default()  CLASS TLed

     ::Resize()


     IF ::lTimeDate
      DEFINE TIMER ::oTimer INTERVAL 500 OF ::oWnd ACTION ::TimeDate()
      ACTIVATE TIMER ::oTimer
     ENDIF


   IF ::lBlink
      DEFINE TIMER ::oOut INTERVAL ::nInterval OF ::oWnd ACTION ::Blink ()
      ACTIVATE TIMER ::oOut
   ENDIF



     IF ::lChronometer
      DEFINE TIMER ::oTimerKrono INTERVAL 500 OF ::oWnd ACTION ::Chronometer()
      ACTIVATE TIMER ::oTimerKrono
     ENDIF


   RETURN NIL


//----------------------------------------------------------------------------------------//

 METHOD Blink()  CLASS TLed
    STATIC nSaveON, nSaveOFF
    DEFAULT nSaveON :=  ::nColorLedON
    DEFAULT nSaveOFF := ::nColorLedOFF

      if ::lStatus
         ::nColorLedON := nSaveON
       else
         ::nColorLedON := nSaveOFF
      endif

      IIF( ! Empty( ::hWnd ), ::Refresh(.f.), )

      ::lStatus := ! ::lStatus

      return  NIL

//----------------------------------------------------------------------------------------//

METHOD TimeDate(lBeep,nLang)  CLASS TLed

    Local cDate:=  DtoS( Date() )
    Local aItalian:=  {"Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio","Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"}
    Local aSpanish := {"Enero", "Febrero", "Marzo", "Abril", "Mayo", "Abril","Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"}
    Local aEnglish  := {"January", "Febrary", "March", "April", "May", "June", "July", "August","September", "October", "November", "December" }
    Local cMessage


    default nlang := 1


       DO CASE
        CASE nLang = 1
               aMesi  :=  aItalian
        CASE nLang = 2
               aMesi  :=  aEnglish
        CASE nLang = 3
               aMesi  :=  aSpanish
       ENDCASE




    cMessage := Right( cDate, 2 ) + " | " +;
                 aMesi[ Val( SubStr( cDate, 5, 2 ) ) ] + " | " +;
                 Left(cDate, 4 )



     if ::lStatusTime
        ::cTxtLin1 := Space(6) + Time()
        ::cTxtLin2 := Space( ( 20 - Len( cMessage) ) /2 ) + cMessage

         IF ::lBeep
          Msgbeep()
         Endif
     endif

        * ::resize()

       IIF( ! Empty( ::hWnd ), ::Refresh(.f.), )


       ::lStatusTime := ! ::lStatusTime

       return  NIL

//----------------------------------------------------------------------------------------//
   METHOD Chronometer(cMessage)  CLASS TLed
        default cMessage := "Chronometer Led "

     if ::lStatusTime
        ::cTxtLin1 := Space(3) + CalTime(::n_Secs)
        ::cTxtLin2 := Space( ( 20 - Len( cMessage) ) /2 ) + cMessage

     endif
          ::nLedLines = 1
        * ::resize()

       IIF( ! Empty( ::hWnd ), ::Refresh(.f.), )


       ::lStatusTime := ! ::lStatusTime

       return  NIL

//----------------------------------------------------------------------------------------//
static Function CalTime(n_Secs)
Local _nTotSecs:=SECONDS()-n_Secs
Return Right(SecsToTime(_nTotSecs),16)



static function SecsToTime( nTimeInSecs )

   local nHours := Int( nTimeInSecs / 3600 )
   local nMins  := Int( nTimeInSecs % 3600 / 60 )
   local nSecs  := Int( nTimeInSecs - ( nHours * 3600 ) - ( nMins * 60 ) )

   local nMillisec := Int(GETTICKCOUNT())


return StrZero( nHours, 2 ) + ":" + StrZero( nMins, 2 ) + ":" + ;
       StrZero( nSecs, 2 )  + ":" + Right(str(nMillisec),3)

//----------------------------------------------------------------------------------------//

 METHOD _FillRect( nTop, nLeft, nBottom, nRight, nColor ) CLASS TLed

   LOCAL oBrush, hBru, hOld, nMid

   hBru := CreateSolidBrush( nColor )
   hOld := SelectObject( ::hDC, hBru )

      FillRect( ::hDC, { nTop, nLeft, nBottom, nRight }, hBru )

   SelectObject( ::hDC, hOld )
   DeleteObject( hBru )

   RETURN (Nil)

//----------------------------------------------------------------------------------------//
/*
 METHOD Resize()  CLASS TLed

    Local y, x
    Local nLedValLines
    Local nWidthChars:= (::nLedCharacters*6.87)+0.5  //138   // 20 cr
    Local nHeightsymbol := 7
    Local nLines:= 2
    Local nSpaces:= (::nLedCharacters*2)*2

    if ::nLedlines  == 0
       nLedValLines :=  7
    else
       nLedValLines := 18 //19
    endif


  y := ( ::nLedHeight * nLedValLines) + ( ::nLedSpace * (nHeightsymbol*nLines) ) + 8
  x := ( ::nLedWidth * nWidthChars ) + ( ::nLedHeight * 2 ) + ( ::nLedSpace * nSpaces ) + 8


   ::nWidth := x
   ::nHeight := y

   IIF( ! Empty( ::hWnd ), ::Refresh(.f.), )

RETURN Nil

*/


 METHOD Resize()  CLASS TLed

 Local y, x
 Local nLedValLines
 Local nWidthChars:= (::nLedCharacters*6.87)+0.5  //138   // 20 cr
 Local nHeightsymbol := 7
 Local nLines:= 2
 Local nSpaces:= (::nLedCharacters*2)*2

    if ::nLedlines  == 1
       nLedValLines :=  7
    else
       nLedValLines := 18 //19
    endif

   y := ( ::nLedHeight * nLedValLines ) + ( ::nLedSpace * 14 ) + 8
   x := ( ::nLedWidth * nWidthChars ) + ( ::nLedHeight * 2 ) + ( ::nLedSpace * 80 ) + 8

   ::nWidth := x
   ::nHeight := y

   IIF( ! Empty(  ::hWnd  ), ::Refresh(.f.), )

   RETURN Nil



















//----------------------------------------------------------------------------------------//

METHOD AdjustText()  CLASS TLed
   Local cLin1, cLin2
   Local cTmp := ::cMessage

   IIF( Len( cTmp ) >= 41, cTmp := Left( cTmp, 40 ), )

   IF Len( cTmp ) == 40
      ::cTxtLin1 := Left( cTmp, ::nLedCharacters )
      ::cTxtLin2 := Right( cTmp, ::nLedCharacters )
   ELSE
      ::cTxtLin1 := Left( cTmp, ::nLedCharacters )
      ::cTxtLin1 := ::cTxtLin1 + Space( ::nLedCharacters - Len( ::cTxtLin1 ) )
      ::cTxtLin2 := Right( cTmp, Len( cTmp ) - ::nLedCharacters )
      ::cTxtLin2 := ::cTxtLin2 + Space( ::nLedCharacters - Len( ::cTxtLin2 ) )
   END

   IIF( ! Empty( ::hWnd ), ::Refresh(.f.), )

RETURN Nil



//----------------------------------------------------------------------------------------//
/*
METHOD CheckLines()   CLASS TLed

  Local nI
   ::aLinea1 := {}
   ::aLinea2 := {}


   For nI := 1 to ::nLedCharacters
      IF ni <= LEN( ::cTxtLin1 )
         AAdd( ::aLinea1, ::GetCode( alltrim( ::cTxtLin1[nI] ) ) )
      ELSE
         AAdd( ::aLinea1, ::GetCode( " " ) )
      END
      IF ni <= LEN( ::cTxtLin2 )
         AAdd( ::aLinea2, ::GetCode( alltrim( ::cTxtLin2[nI] ) ) )
      ELSE
         AAdd( ::aLinea2, ::GetCode( " " ) )
      END
   Next


   RETURN Nil */



METHOD CheckLines()   CLASS TLed

  Local nI
   ::aLinea1 := {}
   ::aLinea2 := {}

   For nI := 1 to ::nLedCharacters
      IF ni <= LEN( ::cTxtLin1 )
          AAdd( ::aLinea1, ::GetCode( SubStr(::cTxtLin1, ni, 1) ) )
      ELSE
         AAdd( ::aLinea1, ::GetCode( " " ) )
      END
      IF ni <= LEN( ::cTxtLin2 )
         AAdd( ::aLinea2, ::GetCode( SubStr(::cTxtLin2, ni, 1) ) )
      ELSE
         AAdd( ::aLinea2, ::GetCode( " " ) )
      END
   Next


RETURN Nil

//----------------------------------------------------------------------------------------//



METHOD GetCode( cChar ) CLASS TLed
   Local aChar, nChar
        nChar := ASC( cChar )
     DO CASE
        CASE nChar=32  //space
           aChar := CodeAScii32()
        CASE nChar=33
           aChar := CodeAScii33()
        CASE nChar=34
           aChar := CodeAScii34()
        CASE nChar=35
           aChar := CodeAScii35()
        CASE nChar=36
           aChar := CodeAScii36()
        CASE nChar=37
           aChar := CodeAScii37()
        CASE nChar=38
           aChar := CodeAScii38()
        CASE nChar=39
           aChar := CodeAScii39()
        CASE nChar=40
           aChar := CodeAScii40()
        CASE nChar=41
           aChar := CodeAScii41()
        CASE nChar=42
           aChar := CodeAScii42()
        CASE nChar=43
           aChar := CodeAScii43()
        CASE nChar=44
           aChar := CodeAScii44()
        CASE nChar=45
           aChar := CodeAScii45()
        CASE nChar=46
           aChar := CodeAScii46()
        CASE nChar=47
           aChar := CodeAScii47()
        CASE nChar=48
           aChar := CodeAScii48()
        CASE nChar=49
           aChar := CodeAScii49()
        CASE nChar=50
           aChar := CodeAScii50()
        CASE nChar=51
           aChar := CodeAScii51()
        CASE nChar=52
           aChar := CodeAScii52()
        CASE nChar=53
           aChar := CodeAScii53()
        CASE nChar=54
           aChar := CodeAScii54()
        CASE nChar=55
           aChar := CodeAScii55()
        CASE nChar=56
           aChar := CodeAScii56()
        CASE nChar=57
           aChar := CodeAScii57()
        CASE nChar=58
           aChar := CodeAScii58()
        CASE nChar=51
           aChar := CodeAScii51()
        CASE nChar=53
           aChar := CodeAScii53()
        CASE nChar=54
           aChar := CodeAScii54()
        CASE nChar=55
           aChar := CodeAScii55()
        CASE nChar=56
           aChar := CodeAScii56()
        CASE nChar=57
           aChar := CodeAScii57()
        CASE nChar=58
           aChar := CodeAScii58()
        CASE nChar=59
           aChar := CodeAScii59()
        CASE nChar=60
           aChar := CodeAScii60()
        CASE nChar=61
           aChar := CodeAScii61()
        CASE nChar=62
           aChar := CodeAScii62()
        CASE nChar=63
           aChar := CodeAScii63()
        CASE nChar=64
           aChar := CodeAScii64()
        CASE nChar=65
           aChar := CodeAScii65()
        CASE nChar=66
           aChar := CodeAScii66()
        CASE nChar=67
           aChar := CodeAScii67()
        CASE nChar=68
           aChar := CodeAScii68()
        CASE nChar=69
           aChar := CodeAScii69()
        CASE nChar=70
           aChar := CodeAScii70()
        CASE nChar=71
           aChar := CodeAScii71()
        CASE nChar=72
           aChar := CodeAScii72()
        CASE nChar=73
           aChar := CodeAScii73()
        CASE nChar=74
           aChar := CodeAScii74()
        CASE nChar=75
           aChar := CodeAScii75()
        CASE nChar=76
           aChar := CodeAScii76()
        CASE nChar=77
           aChar := CodeAScii77()
       CASE nChar=78
           aChar := CodeAScii78()
       CASE nChar=79
           aChar := CodeAScii79()
       CASE nChar=80
           aChar := CodeAScii80()
       CASE nChar=81
           aChar := CodeAScii81()
        CASE nChar=82
           aChar := CodeAScii82()
        CASE nChar=83
           aChar := CodeAScii83()
       CASE nChar=84
           aChar := CodeAScii84()
        CASE nChar=85
           aChar := CodeAScii85()
        CASE nChar=86
           aChar := CodeAScii86()
        CASE nChar=87
           aChar := CodeAScii87()
        CASE nChar=88
           aChar := CodeAScii88()
        CASE nChar=89
           aChar := CodeAScii89()
        CASE nChar=90
           aChar := CodeAScii90()
        CASE nChar=91
           aChar := CodeAScii91()
        CASE nChar=92
           aChar := CodeAScii92()
        CASE nChar=93
           aChar := CodeAScii93()
        CASE nChar=94
           aChar := CodeAScii94()
        CASE nChar=95
           aChar := CodeAScii95()
        CASE nChar=96
           aChar := CodeAScii96()
        CASE nChar=97
           aChar := CodeAScii97()
        CASE nChar=98
           aChar := CodeAScii98()
        CASE nChar=99
           aChar := CodeAScii99()
        CASE nChar=100
           aChar := CodeAScii100()
        CASE nChar=101
           aChar := CodeAScii101()
        CASE nChar=102
           aChar := CodeAScii102()
        CASE nChar=103
           aChar := CodeAScii103()
        CASE nChar=104
           aChar := CodeAScii104()
        CASE nChar=105
           aChar := CodeAScii105()
        CASE nChar=106
           aChar := CodeAScii106()
        CASE nChar=106
           aChar := CodeAScii106()
        CASE nChar=107
           aChar := CodeAScii107()
        CASE nChar=108
           aChar := CodeAScii108()
        CASE nChar=109
           aChar := CodeAScii109()
        CASE nChar=110
           aChar := CodeAScii110()
        CASE nChar=111
           aChar := CodeAScii111()
        CASE nChar=112
           aChar := CodeAScii112()
        CASE nChar=113
           aChar := CodeAScii113()
        CASE nChar=114
           aChar := CodeAScii114()
        CASE nChar=115
           aChar := CodeAScii115()
        CASE nChar=116
           aChar := CodeAScii116()
        CASE nChar=117
           aChar := CodeAScii117()
        CASE nChar=118
           aChar := CodeAScii118()
        CASE nChar=119
           aChar := CodeAScii119()
        CASE nChar=120
           aChar := CodeAScii120()
        CASE nChar=121
           aChar := CodeAScii121()
        CASE nChar=122
           aChar := CodeAScii122()
        CASE nChar=123
           aChar := CodeAScii123()
        CASE nChar=124
           aChar := CodeAScii124()
        CASE nChar=125
           aChar := CodeAScii125()
        CASE nChar=126
           aChar := CodeAScii126()
        CASE nChar=128
           aChar := CodeAScii128()
        CASE nChar=161
           aChar := CodeAScii161()
        CASE nChar=170
           aChar := CodeAScii170()
        CASE nChar=186
           aChar := CodeAScii186()
        CASE nChar=224
           aChar := CodeAScii224()
        CASE nChar=225
           aChar := CodeAScii225()
        CASE nChar=232
           aChar := CodeAScii232()
        CASE nChar=233
           aChar := CodeAScii233()
        CASE nChar=236
           aChar := CodeAScii236()
        CASE nChar=237
           aChar := CodeAScii237()
        CASE nChar=242
           aChar := CodeAScii242()
        CASE nChar=243
           aChar := CodeAScii243()
        CASE nChar=247
           aChar := CodeAScii247()
        CASE nChar=249
           aChar := CodeAScii249()
        CASE nChar=250
           aChar := CodeAScii250()
        OTHERWISE
          aChar :=  CodeAScii32()
       ENDCASE
RETURN aChar


 


do not forget to add the Code Ascii Table function
Last edited by Silvio.Falconi on Sun Dec 02, 2018 8:38 pm, edited 1 time in total.
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7076
Joined: Thu Oct 18, 2012 7:17 pm

Re: chronometer

Postby Silvio.Falconi » Sun Dec 02, 2018 7:54 pm

With this class is simply...

Image

I did this when I had to simulate a panel of the old LCD in an office where there is always the queue of people and each has its number as in supermarkets or at the post office "Now we serve the number ....", I really like using it when I make invoices to see the total on the video with the turret display


sample for a date display with Beep with 2 lines

Code: Select all  Expand view  RUN

Function test()
   Local oDlg,oDisplay
   Define Dialog oDlg size 550,200

   oDisplay:=TLed():New(1,1,oDlg)
           oDisplay:lTimeDate :=.t.
           oDisplay:lBeep:=.t.
   Activate Dialog oDlg
   return nil
 


Image
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7076
Joined: Thu Oct 18, 2012 7:17 pm

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 68 guests