pour ceux que cela intéresse.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' demo of the graphics library for the 4D-Systems PICASSO range of touch LCDs
' this has been tested on the 4.3 inch and 3.2 inch serial displays
' models: uLCD43(SGC) and uLCD-32PT(SGC)
'
' the demo displays the time and some other graphics (see the photo)
' buttons are not used but can easily be added
'
' Geoff Graham, March 2012
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' open the display
LCDOpen 2
''''''''''''''''''''''''''''''''''''''''''''''''''''
MainScreen:
LCDCLS ' clear the screen and any buttons
TCol = RGB(0,1,1) ' time display colour and position
TVPos = 0
WCol = RGB(0,.8,0) ' water display colour and position
WVpos = 120
BCol = RGB(1,0,0) ' battery display colour and position
BVpos = 156
ICol = RGB(0.9,0.9,0) ' inside temperatures display colour and position
IVpos = 198 : IHpos = 45
OCol = RGB(0.9,0.9,0) ' outside temperatures display colour and position
OVpos = 198 : OHpos = 196
' this demo does not have any butons but this is how you would set them up
'LCDBSetup 250, 50, "Msg1" ' button labeled Msg1
'LCDBSetup 250, 100, "Msg2" ' similar
'LCDBSetup 0, 0, "", 240, 100 ' button not labeled (area of the screen)
LCDPrint 0, WVpos+2, "Water", WCol, 13
LCDLine 96, WVpos, 319, WVpos+20, WCol, 1
LCDLine 100, WVpos + 4, 300, WVpos+16, WCol, 2
LCDPrint 0, BVpos+2, "Battery", BCol, 13
LCDLine 96, BVpos, 319, BVpos+20, BCol, 1
LCDLine 100, BVpos + 4, 150, BVpos+16, BCol, 2
LCDPrint IHPos, IVpos, "27", ICol, 33
LCDPrint IHPos-30, IVPos + 8, "I", ICol, 12
LCDPrint IHPos-30, IVPos + 24, "N", ICol, 12
LCDPrint IHPos+80, IVPos, "C", ICol, 13
LCDPrint OHPos, OVpos, "32", OCol, 33
LCDPrint OHPos+110, OVPos + 2, "O", OCol, 12
LCDPrint OHPos+110, OVPos + 16, "U", OCol, 12
LCDPrint OHPos+110, OVPos + 30, "T", OCol, 12
LCDPrint OHPos+80, OVPos, "C", OCol, 13
Do ' this loop never ends
If tlast$ <> Left$(Time$, 5) Then
tlast$ = Left$(Time$, 5)
hrs = Val(Left$(Time$, 2)) : min = Val(Mid$(Time$, 4, 2))
If hrs > 12 Then hrs = hrs - 12
If hrs >= 10 Then oset = 0 Else oset = 6 * 5
LCDPrint 10 + oset, TVPos, Format$(hrs, "%g" ) + ":" + Format$(min, "%02g" ), TCol, 53
LCDPrint 26, TVPos+80, "Saturday 5th April 2012", TCol, 13
' this demo does not have any butons but this is how you would detect a
' button press and run the appropiate subrouting to handle the press
'On LCDTouch() GoSub msg1, msg2, msg3
EndIf
Loop
' this demo does not have any butons but this is an example of how you would
' handle a button press. Note that these are the target of GOSUB's
'msg1: Print "MSG1 pressed"
' Pause 250
' Return
'
'msg2: Print "MSG2 pressed"
' Pause 250
' Return
'
'msg3: Print "Screen press"
' Pause 250
' Return
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' graphics library for the 4D-Systems PICASSO range of touch LCDs
' this has been tested on the 4.3 inch and 3.2 inch serial displays
' models: uLCD43(SGC) and uLCD-32PT(SGC)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' open the LCD display for access
' this resets the display and opens comms at 9600 baud
' com is the communication channel. ie, 3 for COM3:
' pin 17 is used to reset the display and should be connected to the RES
' pin on the LCD. This must be called once at the start of the program
Sub LCDOpen com
Dim LCDBut(10, 5) : Dim LCDBMsg$(10) ' these are used to record the buttons
Open "COM" + Chr$(com + 48) + ":9600" As #10
SetPin 17, 9
Pin(17) = 1
Pause 2000
Print #10, "U";
LCDGetAck
Print #10, "Y" Chr$(5) Chr$(0); ' enable the touchscreen
LCDGetAck
' the following is only needed if the display is in portrait mode
'Print #10, "Y" Chr$(4) Chr$(1); ' rotate a portrait screen to landscape
'LCDGetAck
End Sub
' clear the LCD screen and any buttons that have been setup on it
Sub LCDCLS
Local i
For i = 1 To 10
LCDBut(i, 0) = 0
Next i
Print #10, "E";
LCDGetAck
End Sub
' print a string on the LCD
' z and y are the coordinates, msg$ is the text
' c is the colour and f is the font (both are optional)
' f is two digits, the first is the scale and the second is the PICASO font
Sub LCDPrint x, y, msg$, c, f
Local scale, opaque
If f = 0 Then f = 13
scale = (f\10) Mod 10
opaque = ((f\100) = 0)
If scale = 0 Then scale = 1
f = f Mod 10
If c = -1 Or c = 0 Then c = RGB(1,1,1)
Print #10, "O" Chr$(opaque);
LCDGetAck
If f > 3 Then f = f - 3
Print #10, "S" LCDWords$(2, x, y);
Print #10, Chr$(f) LCDWords$(1, c);
Print #10, Chr$(scale) Chr$(scale) msg$ Chr$(0);
LCDGetAck
End Sub
' draw a line or a box
' x1, y1, x2, y2 are the start and end coordinates, c is the colour
' b = 0 will draw a line, b = 1 will draw a box and b = 2 a filled box
' c and b are optional and will default to a white line
Sub LCDLine x1, y1, x2, y2, c, b
Local cmd$, pen
If c = -1 Or (c = 0 And b = 0) Then c = RGB(1,1,1)
If b = 0 Then
cmd$ = "L"
Else
cmd$ = "r"
Print #10, "p" Chr$(b = 1);
LCDGetAck
EndIf
Print #10, cmd$ LCDWords$(5, x1, y1, x2, y2, c);
LCDGetAck
End Sub
' generate a colour index for the LCD
' r = red, g = green and b = blue
' the values can range from zero (full off) to 1 (fully on)
Function RGB(r, g, b)
RGB = Int(r * 31) * 2048 + Int(g * 63) * 32 + Int(b * 31)
End Function
' draw a button on the screen and initialise it
' x and y are the top left coordinates of the button
' msg$ is the caption for the button. This can be a zero length string
' (ie, "" ) and in that case the button is not drawn and x1 and y1 are
' used to define an area on the screen which, if touched will return a
' button press. A maximum of 10 buttons can be defined.
' x1 and y1 are optional
Sub LCDBSetup x, y, msg$, x1, y1
Local i
For i = 1 To 10
If(LCDBut(i, 0) = 0) Then Exit For
Next i
If i > 10 Then Error
LCDBut(i, 0) = 2: LCDBut(i, 1) = x: LCDBut(i, 2) = y
LCDBMsg$(i) = msg$
If msg$ <> "" Then
LCDBut(i, 3) = x + Len(msg$) * 24 + 12: LCDBut(i, 4) = y + 44
LCDButton 1, x, y, msg$
Else
LCDBut(i, 3) = x1 : LCDBut(i, 4) = y1
EndIf
End Sub
' returns the button number that has been pressed or zero if no buton pressed
' normally this is used like this: On LCDTouch() GoSub msg1, msg2, msg3
' the button number is the order in which they were set up
Function LCDTouch
Local i, j, k, x, y
Print #10, "o" Chr$(4);
For k = 1 To 8000
If Loc(10) = 4 Then
If Input$(4, #10) = Chr$(0)+Chr$(3)+Chr$(0)+Chr$(0) Then
Print #10, "o" Chr$(5);
For j = 1 To 8000
If Loc(10) = 4 Then
x = Asc(Input$(1, #10)) * 256 + Asc(Input$(1, #10))
y = Asc(Input$(1, #10)) * 256 + Asc(Input$(1, #10))
For i = 1 To 10
If x > LCDBut(i,1) And x < LCDBut(i,3) And y > LCDBut(i,2) And y < LCDBut(i,4) Then
If LCDBut(i, 0) = 2 Then
LCDBut(i, 0) = 1
If LCDBMsg$(i) <> "" Then LCDButton 0, LCDBut(i, 1), LCDBut(i, 2), LCDBMsg$(i)
LCDTouch = i
Exit Function
EndIf
EndIf
Next i
LCDTouch = 0
Exit Function
EndIf
Next j
Error
Else
For i = 1 To 10
If LCDBut(i, 0) = 1 Then
LCDBut(i, 0) = 2
If LCDBMsg$(i) <> "" Then LCDButton 1, LCDBut(i, 1), LCDBut(i, 2), LCDBMsg$(i)
EndIf
Next i
LCDTouch = 0
Exit Function
EndIf
EndIf
Next k
Error "LCD is not responding"
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' internal routines - user code should not call these routines
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' used internally to draw a button
' user code should not call this sub
Sub LCDButton state, x, y, msg$, f, ct, cb
Local scale
If f = 0 Then f = 23
scale = f\10
If scale = 0 Then scale = 1
f = f Mod 10
If ct = 0 Then ct = RGB(1,1,1)
If cb = 0 Then cb = RGB(0,0.5,0.5)
Print #10, "O" Chr$(0); : LCDGetAck
Print #10, "b" Chr$(state) LCDWords$(3, x, y, cb);
Print #10, Chr$(f) LCDWords$(1, ct) Chr$(scale) Chr$(scale);
Print #10, msg$ Chr$(0);
LCDGetAck
End Sub
' used to get an acknowledgement from the LCD
' user code should not call this sub
Sub LCDGetAck
Local i
For i = 1 To 8000
x$ = Input$(1, #10)
If x$ = Chr$(6) Then Exit Sub
If x$ = Chr$(15) Then Error "LCD reported an error"
Next i
Error "LCD is not responding"
End Sub
' send a series of bytes to the screen
' user code should not call this sub
Function LCDWords$(nbr, w1, w2, w3, w4, w5)
LCDWords$ = Chr$(w1\256) + Chr$(w1 And 255)
If nbr > 1 Then LCDWords$ = LCDWords$ + Chr$(w2\256) + Chr$(w2 And 255)
If nbr > 2 Then LCDWords$ = LCDWords$ + Chr$(w3\256) + Chr$(w3 And 255)
If nbr > 3 Then LCDWords$ = LCDWords$ + Chr$(w4\256) + Chr$(w4 And 255)
If nbr > 4 Then LCDWords$ = LCDWords$ + Chr$(w5\256) + Chr$(w5 And 255)
End Function