Looking for GLCD Menu sample code
Moderators: David Barker, Jerry Messina
Looking for GLCD Menu sample code
I'm new to programming and am looking for samples of GLCD menus. Any help would be greatly appreciated.
Re: Looking for GLCD Menu sample code
You've already given a look here?
http://www.sfcompiler.co.uk/wiki/pmwiki ... MenuModule
http://www.sfcompiler.co.uk/wiki/pmwiki ... MenuModule
Re: Looking for GLCD Menu sample code
Thanks, However I'm looking for some sample used on a GLCD, not a 4 line LCD.
Re: Looking for GLCD Menu sample code
I'm not looking for someones complete project. Just an example of how to configure up up, down, select buttons and navigate through a few screens.
Re: Looking for GLCD Menu sample code
Ok, I've got this touchscreen driven menu system. Because it was done in a hurry the main logic and menu system are somewhat intertwined. I've got to rush off today, but here's the bulk of it It's not complete. I had to knock out some propriety bits so it won't compile or anything, but it should give you something to pick through for some ideas. Like I say, its somewhat nasty from many years ago. Someone else could probably create a more modular system from it.
Regards,
Rangerbob
Regards,
Rangerbob
Code: Select all
// import modules...
Include "system.bas"
Include "utils.bas"
Include "Project.bas"
include "adc.bas"
Include "glcd.bas"
Include "arial12.bas"
Include "graphics.bas"
Include "convert.bas"
Include "Touchscreen.bas"
Include "ImagesDX.bas"
Include "StringsDX.bas"
// Button Constants
Const Pressed = true
Const NotPressed = false
Const Basic = true
Const Detailed = false
Const Hidden = true
Const Visible = false
Const OK = 11
Const Cancel = 7
Const OKOnly = 1
Const None = 0
Const sChanIcon = 1
Const sPwrIcon = 2
Const sSetIcon = 3
Const sSrtIcon = 4
'Const sEngFlag = 5
'Const sFrFlag = 6
'Const sEsFlag = 7
Const sBright = 8
Const SmButton = 0
Const LgButton = 1
Const WnButton = 2
Const KbButton = 3
Const Kb2Button = 4
Const Kb3Button = 5
Const kbOK = 30
Const Space = 29
Const Del = 28
// Language Constants
Const English = 0
Const French = 1
Const Spanish = 2
Const PowerAdjust = 0
Const BrightAdjust = 1
Const pPort = %01000000
// Pin Constants
Const MaxPinTime = 60 'Maximum wait time between PIN timeouts (word sized)
Const PunishFactor = 2 'Incorrect PIN Punishment factor
Const
PinArraySize = 12,
PinArray(PinArraySize) As Byte = ("1","2","3","0","4","5","6","C","7","8","9","O"),
KbArraySize = 31,
KbArray(KbArraySize) As Byte = ("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","-","*","D"," ","O")
// Keyboard Buttons Positions
Const KbX(KbArraySize) As Word = (2,47,92,137,182,227,272,2,47,92,137,182,227,272,2,47,92,137,182,227,272,2,47,92,137,182,227,272,2,92,227)
Const KbY(KbArraySize) As Byte = (70,70,70,70,70,70,70,104,104,104,104,104,104,104,138,138,138,138,138,138,138,172,172,172,172,172,172,172,206,206,206)
Const NumX(PinArraySize) As Byte = (2,82,162,242,2,82,162,242,2,82,162,242)
Const NumY(PinArraySize) As Byte = (63,63,63,63,123,123,123,123,183,183,183,183)
// Main Buttons Positions
Const MainArraySize = 4
Const MainX(MainArraySize) As Byte = (4,4,189,4)
Const MainY(MainArraySize) As Byte = (35,101,164,164)
// Line positions
Const DisplayLine(5) As Byte = (53,71,89,107,125)
Dim X_Pos As Word
Dim Y_Pos As Word
Dim PenDown As Boolean
Dim ButtonCount As Byte
// Menu Variables
Dim MenuString(4) As String(13) //check if big enough!!!!
Dim ButtonSize(4) As Byte
Dim IconSelect(4) As Byte
{
********************************************************************************
* Name : SetFont *
* Purpose : Draws Black Title Bar *
********************************************************************************
}
Sub SetFontStyle(pStyle As Byte)
Brush.Style = bsSolid
Select pStyle
Case fsNormal
PEN.Color = 1
Brush.Color = 0
Case fsInvert
Brush.Color = 1
PEN.Color = 0
End Select
End Sub
{
********************************************************************************
* Name : LoadTouchscreenCal *
* Purpose : Loads the Touchscreen ADC Calibration Values *
********************************************************************************
}
Sub LoadTouchScreenCal()
Dim temp As Word
EE.Read(4, temp)
TouchScreen.Calibration.X_Min_TL = temp
EE.Read(6, temp)
TouchScreen.Calibration.X_Max_TL = temp
EE.Read(8, temp)
TouchScreen.Calibration.Y_Min_TL = temp
EE.Read(10, temp)
TouchScreen.Calibration.Y_Max_TL = temp
EE.Read(12, temp)
TouchScreen.Calibration.X_Min_BR = temp
EE.Read(14, temp)
TouchScreen.Calibration.X_Max_BR = temp
EE.Read(16, temp)
TouchScreen.Calibration.Y_Min_BR = temp
EE.Read(18, temp)
TouchScreen.Calibration.Y_Max_BR = temp
End Sub
{
********************************************************************************
* Name : SplashScreen *
* Purpose : displays Splash Screen, returns selection *
********************************************************************************
}
Sub SplashScreen()
ClearScreen
Brush.Style = bsClear 'Quickest brushstyle
TextAlign = taCenter
PEN.Color = 1
' SetImage(32,22,smlogoc) 'Draw Logo
SetImage(60,120,Title)
WriteStr(159,180,S_Continue)
#if Frequencies = European
WriteAt(200,225,"v ", Project.VersionStr, " EU")
#endif
#if Frequencies = US
WriteAt(200,225,"v ", Project.VersionStr, " US")
#endif
#if Frequencies = Both
WriteAt(200,225,"v ", Project.VersionStr)
#endif
End Sub
{
********************************************************************************
* Name : DrawTitle *
* Purpose : Draws Black Title Bar *
********************************************************************************
}
Sub DrawTitle(pPrompt1 As String)
SetFontStyle(fsInvert)
'Black title for better attention
Fill(0,0,320,17)
WriteAt(1,1,pPrompt1) 'Write Prompts
SetFontStyle(fsNormal)
End Sub
{
********************************************************************************
* Name : GetButton *
* Purpose : *
********************************************************************************
}
Function GetButton(MaxButton As Byte, ButtonType As Byte) As Word
Dim ButtonX As Word
Dim ButtonY As Word
Dim BoundsX As Word
Dim BoundsY As Word
Dim count As Word
Dim PenDown As Boolean
Select ButtonType
Case LgButton
boundsX = 122
boundsY = 50
Case KbButton
boundsX = 41
boundsY = 30
Else //Small Button and Warning button
BoundsX = 70
BoundsY = 50
End Select
count = 0
result = Maxbutton
Repeat
Repeat
Inc(count)
DelayMS(10)
'Timer.Stop
PenDown = TouchScreen.PenIsDown
'Timer.Start
Until PenDown Or Count = 100
If PenDown Then
DelayMS(50) // Wait to debounce
'Timer.Stop
TouchScreen.GetPenPosition(X_Pos, Y_Pos)
'Timer.Start
For result = 0 To MaxButton
Select ButtonType
Case SmButton
ButtonX = NumX(result)
ButtonY = NumY(result)
Case LgButton
ButtonX = MainX(result)
ButtonY = MainY(result)
Case KbButton
Select result
Case Del Or kbOK
BoundsX = 85
Case Space
BoundsX = 130
End Select
ButtonX = KbX(result)
ButtonY = KbY(result)
Case WnButton
ButtonX = 122
ButtonY = 160
End Select
If IsInRectangle (X_Pos, Y_Pos, (ButtonX + 6), (ButtonY + 6), (ButtonX + BoundsX), (ButtonY + BoundsY)) Then
Break
EndIf
Next
EndIf
Until result <= MaxButton
End Function
{
********************************************************************************
* Name : NumberButton *
* Purpose : Draws Number Pad Button *
********************************************************************************
}
Sub DrawButton(ButtonX As Word, ButtonY As Byte, ButtonType As Byte, ButPressed As Boolean)
Dim MaxX As Word
Dim MaxY As Byte
Select ButtonType
Case SmButton
MaxX = 76
MaxY = 56
Case LgButton
MaxX = 128
MaxY = 56
Case KbButton
MaxX = 45
MaxY = 34
Case Kb2Button
MaxX = 90
MaxY = 34
Case Kb3Button
MaxX = 135
MaxY = 34
End Select
//Delete Existing Button
Brush.Color = 0
Fill (ButtonX, ButtonY, (ButtonX + (MaxX - 1)), (ButtonY + (MaxY - 1)))
Brush.Color = 1
If ButPressed = True Then
//Draw Corners
SetImage ( ButtonX, ButtonY, TopLeftPressed)
SetImage ( (ButtonX + (MaxX - 7)), (ButtonY + 0), TopRightPressed)
SetImage ( (ButtonX + (MaxX - 7)), (ButtonY + (MaxY - 7)), BottomRightPressed)
SetImage ( (ButtonX + 0), (ButtonY + (MaxY - 7)), BottomLeftPressed)
//Draw Outline
Fill ( (ButtonX + 7), ButtonY, (ButtonX + (MaxX - 8)), (ButtonY + 5))
Fill ( ButtonX, (ButtonY + 7), (ButtonX + 5), (ButtonY + (MaxY - 8)))
Line ( (ButtonX + 7), (ButtonY + (MaxY - 6)), (ButtonX + (MaxX - 8)), (ButtonY + (MaxY - 6)))
Line ( (ButtonX + 7), (ButtonY + (MaxY - 1)), (ButtonX + (MaxX - 8)), (ButtonY + (MaxY - 1)))
Line ( (ButtonX + (MaxX - 6)), (ButtonY + 7), (ButtonX + (MaxX - 6)), (ButtonY + (MaxY - 8)))
Line ( (ButtonX + (MaxX - 1)), (ButtonY + 7), (ButtonX + (MaxX - 1)), (ButtonY + (MaxY - 8)))
Else
//Draw Corners
SetImage (ButtonX, ButtonY, TopLeftUnpressed)
SetImage ((ButtonX + (MaxX - 7)), (ButtonY + 0), TopRightUnpressed)
SetImage ((ButtonX + (MaxX - 7)), (ButtonY + (MaxY - 7)), BottomRightUnpressed)
SetImage ((ButtonX + 0), (ButtonY + (MaxY - 7)), BottomLeftUnpressed)
//Draw Outline
Fill ( (ButtonX + 7), (ButtonY + (MaxY - 6)), (ButtonX + (MaxX - 8)), (ButtonY + (MaxY - 1)))
Fill ( (ButtonX + (MaxX - 6)), (ButtonY + 7), (ButtonX + (MaxX - 1)), (ButtonY + (MaxY - 8)))
Line ( (ButtonX + 7), ButtonY, (ButtonX + (MaxX - 8)), ButtonY)
Line ( (ButtonX + 7), (ButtonY + 5), (ButtonX + (MaxX - 8)), (ButtonY + 5))
Line ( ButtonX, (ButtonY + 7), ButtonX, (ButtonY + (MaxY - 8)))
Line ( (ButtonX + 5), (ButtonY + 7), (ButtonX + 5), (ButtonY + (MaxY - 8)))
EndIf
End Sub
{
********************************************************************************
* Name : DrawArrayButton *
* Purpose : Draws Number Pad Buttons *
********************************************************************************
}
Sub DrawArrayButton(ButtonNumber As Byte, ButPressed As Boolean, ButType As Byte)
Dim ButtonX As Word
Dim ButtonY As Byte
Brush.Style = bsClear
PEN.Color = 1
// Get Location
Select ButType
Case SmButton
// Get Location
ButtonX = NumX(ButtonNumber)
ButtonY = NumY(ButtonNumber)
// Draw Button
DrawButton(ButtonX, ButtonY, SmButton, ButPressed)
// Put on Label
If ButtonNumber = OK Then 'OK Button
WriteAt((ButtonX + 10),(ButtonY + 15),"OK")
Else
WriteAt((ButtonX + 10),(ButtonY + 15),PinArray(ButtonNumber))
EndIf
Case KbButton
// Get Location
ButtonX = KbX(ButtonNumber)
ButtonY = KbY(ButtonNumber)
// Put on Label
Select ButtonNumber
Case kbOK
DrawButton(ButtonX,ButtonY, Kb2Button, butpressed)
WriteAt((ButtonX + 10),(ButtonY + 10),"OK")
Case Space
DrawButton(ButtonX,ButtonY, Kb3Button, butpressed)
WriteAt((ButtonX + 15),(ButtonY + 10)," ")
Case Del
DrawButton(ButtonX,ButtonY, Kb2Button, butpressed)
WriteAt((ButtonX + 10),(ButtonY + 10),"del")
Else
DrawButton(ButtonX, ButtonY, KbButton, ButPressed)
WriteAt((ButtonX + 15),(ButtonY + 10),KbArray(ButtonNumber))
End Select
End Select
End Sub
{
********************************************************************************
* Name : DrawAnyButton *
* Purpose : Draws Any Button at given coordinates *
********************************************************************************
}
Sub DrawAnyButton(ButtonX As Byte, ButtonY As Byte, pLabel As String, ButPressed As Boolean, pStyle As Byte, pIcon As Byte)
Brush.Style = bsClear
PEN.Color = 1
TextAlign = taCenter
If pStyle = SmButton Then 'Small Number Buttons
DrawButton(ButtonX, ButtonY, SmButton, ButPressed)
WriteStr((ButtonX + 38),(ButtonY + 15),pLabel)
Else
DrawButton(ButtonX, ButtonY, LgButton, ButPressed)
If pIcon = 0 Then
WriteStr((ButtonX + 64),(ButtonY + 20),pLabel)
Else
WriteStr((ButtonX + 75),(ButtonY + 20),pLabel)
EndIf
EndIf
Select pIcon
Case sChanIcon
SetImage ((ButtonX + 9), (ButtonY + 12), ChanIcon)
Case sPwrIcon
SetImage ((ButtonX + 9), (ButtonY + 12), PwrIcon)
Case sSetIcon
SetImage ((ButtonX + 9), (ButtonY + 12), SetIcon)
Case sSrtIcon
SetImage ((ButtonX + 9), (ButtonY + 12), SrtIcon)
' Case sEngFlag
' SetImage ((ButtonX + 7), (ButtonY + 19), EnglishFlag)
' Case sFrFlag
' SetImage ((ButtonX + 7), (ButtonY + 19), FrenchFlag)
' Case sEsFlag
' SetImage ((ButtonX + 7), (ButtonY + 19), SpanishFlag)
Case sBright
SetImage ((ButtonX + 9), (ButtonY + 12), BrightIcon)
End Select
End Sub
{
********************************************************************************
* Name : NumberEntry *
* Purpose : Allows User to enter numerical data, returns word sized entry *
********************************************************************************
}
Function NumberEntry(pHidden As Boolean, pPrompt1 As String, pPrompt2 As String, MaxDigits As Byte) As Word
Dim Count As Byte
Dim Button As Byte
Dim Calc As Word
Dim Temp As Word
Dim KeyDec As Byte
Dim KeyPos As Byte
Dim Entered(6) As Byte
Repeat
ClearScreen
For button = 0 To 11 'Draw Inital Button Array
DrawArrayButton(button,NotPressed,SmButton)
Next
DrawTitle(pPrompt1)
WriteAt(0,25,pPrompt2)
count = 0
KeyPos = 160
Repeat
Repeat
button = GetButton(12, SmButton)
Until Button < 12
DrawArrayButton(button,Pressed,SmButton) 'Indicate pressed button
KeyDec = PinArray(Button) 'Get Char for button
If Button = OK Or Button = Cancel Then
Break
Else
If count < maxdigits Then
If pHidden = true Then 'If PIN screen, Hide the Digits
WriteAt(KeyPos,25,"*")
Else
WriteAt(KeyPos,25,keydec)
EndIf
KeyDec = KeyDec - $30 'Convert selected Numerical Key to Decimal
Entered(count) = KeyDec
KeyPos = KeyPos + 20
Inc(count)
EndIf
EndIf
DelayMS(100)
Repeat 'While button held down wait
Until Not TouchScreen.PenIsDown
DrawArrayButton(button,NotPressed,SmButton) 'Indicate unpressed button
Until Button = OK 'Reset Screen if button = cancel
Until Button = OK
// Produce final Number for Result
Calc = 1
Result = 0
If count > 0 Then
Repeat
KeyDec = Entered(Count -1)
Temp = Keydec * Calc
Result = Result + temp
Calc = Calc * 10
Dec(Count)
Until count = 0
Else
result = $FFFF
EndIf
End Function
{
********************************************************************************
* Name : NumberEntry *
* Purpose : Allows User to enter Alphabetical data, returns string *
********************************************************************************
}
Function KeyPadEntry(pPrompt1 As String, MaxDigits As Byte) As String
Dim Button As Byte
Dim letterstr As String
Dim letterpos As Byte
// Account for Null character of string
MaxDigits = Maxdigits - 1
Repeat
ClearScreen
letterpos = 0
// Draw Button array
For button = 0 To 30
DrawArrayButton(button,NotPressed,KbButton)
Next
DrawTitle(pPrompt1)
SetFontStyle(fsNormal)
Repeat
Repeat
button = GetButton(31, KbButton)
Until Button < 31
DrawArrayButton(button,Pressed,KbButton) 'Indicate pressed button
Select button
Case kbOK
Case Del
// Stop Deleting if all gone
If letterpos > 0 Then
Dec(letterpos)
EndIf
Brush.Color = 0
Fill(10,25,200,50)
Else
// Limit Number of Characters
If letterpos < MaxDigits Then
letterstr(letterpos) = KbArray(button)
Inc(letterpos)
If letterpos > 250 Then
Letterpos = Maxdigits
EndIf
EndIf
EndSelect
letterstr(letterpos) = null
WriteAt(10,25,letterstr)
DelayMS(100)
Repeat 'While button held down wait
Until Not TouchScreen.PenIsDown
DrawArrayButton(button,NotPressed,KbButton) 'Indicate unpressed button
Until Button = kbOK
Until Button = kbOK 'Reset Screen if button = cancel
result = letterstr
End Function
{
********************************************************************************
* Name : DrawMessageBox *
* Purpose : Draws a message box over existing content *
********************************************************************************
}
Sub DrawMessageBox(pPrompt1 As String, pPrompt2 As String, MessType As Byte)
SetFontStyle(fsNormal)
Fill(60,60,260,180)
Rectangle(60,60,260,180)
SetFontStyle(fsInvert)
Fill(60,60,260,77)
WriteAt(61,61,pPrompt1) 'Write Prompts
SetFontStyle(fsNormal)
// WriteAt(160,90,pPrompt2)
WriteAt(65,90,pPrompt2)
Select MessType
Case OKOnly
DrawAnyButton(122,120,"OK",NotPressed,SmButton,None)
// wait for input
Repeat
Until TouchScreen.PenIsDown
DrawAnyButton(122,120,"OK",Pressed,SmButton,None)
DelayMS(100)
Repeat
Until Not TouchScreen.PenIsDown
End Select
End Sub
{
********************************************************************************
* Name : DrawMenuScreen *
* Purpose : Draws buttons and handles menu *
********************************************************************************
}
Function DrawMenuScreen(maxbutton As Byte) As Byte
Dim n As Byte
Dim button As Byte
// Stop Timer Interrupt
'Timer.Stop
// Draw Initial Buttons
For n = 0 To (maxbutton - 1)
DrawAnyButton(MainX(n),MainY(n),MenuString(n),NotPressed,ButtonSize(n),IconSelect(n))
Next
// Restart Timer Interrupt
'Timer.Start
// Wait for input
Repeat
BatteryUpdate(Detailed) 'Keep Battery info updated
button = GetButton(maxbutton, LgButton)
Until Button < maxbutton
// Stop Timer Interrupt
'Timer.Stop
//Draw Pressed Button
DrawAnyButton(MainX(button),MainY(button),MenuString(button),Pressed,ButtonSize(button),IconSelect(button))
// Start Timer Interrupt
'Timer.Start
DelayMS(100)
Repeat
Until Not TouchScreen.PenIsDown
result = button
End Function
{
********************************************************************************
* Name : Startup *
* Purpose : *
********************************************************************************
}
Sub StartUp()
Dim Pin As Word
Dim Returned As Word
Dim PinDelay As Byte 'Delay between incorrect PINs
Dim Timer As Word
Dim n As Byte
Dim Seed As LongWord
EE.Read(EEPin, Pin)
EE.Read(EEPinDelay, PinDelay)
Repeat
If Pindelay > 1 Then
DrawMessageBox(S_Error,S_IncorrectPIN,OKOnly)
Brush.Style = bsSolid
Brush.Color = 0
For Timer = PinDelay To 0 Step -1
WriteAt(65,90,S_Retry, DecToStr(Timer),S_Seconds)
DelayMS (1000)
Next
EndIf
SplashScreen() 'Display Startscreen
SetFontStyle(fsNormal)
n = 0
Repeat
If n = 250 Then
BatteryUpdate(Basic)
n = 0
EndIf
DelayMS(10)
Inc(n)
Until TouchScreen.PenIsDown
// Seed Random number generator
TouchScreen.GetPenPosition(X_Pos, Y_Pos)
Seed = X_Pos * Y_Pos
InitializeRand(Seed)
'Call PIN entry screen
Returned = NumberEntry(Hidden,S_LogOn,S_EnterPIN,4)
Select Returned
// Correct PIN Entered
Case Pin
If Pindelay > 1 Then
EE.Write(EEPinDelay, 1) 'Reset PinDelay to shortest
EndIf
// Debug Code for setting VTCXO
'Case 1583
Else
If Pindelay < MaxPinTime Then
Pindelay = Pindelay * PunishFactor
EE.Write(EEPinDelay, PinDelay) 'Keep adding punish factor
EndIf
End Select
Until returned = Pin
End Sub
{
********************************************************************************
* Name : SetPin *
* Purpose : Sets PIN number *
********************************************************************************
}
Sub SetPin()
Dim returned As Word
Dim Pin As Word
EE.Read(EEPin, Pin)
Returned = NumberEntry(Visible,S_EnterCurrentPIN," ",4)
If returned = Pin Then
Returned = NumberEntry(Visible,S_EnterNewPIN," ",4)
DrawMessageBox(S_Warning,S_PINSet,OKOnly)
EE.Write(EEPin, returned)
Else
DrawMessageBox(S_Error,S_IncorrectPIN,OKOnly)
EndIf
End Sub
{
********************************************************************************
* Name : PowerScreen *
* Purpose : Adjust Transmit Power & Screen Brightness *
********************************************************************************
}
Sub PowerScreen(Mode As Byte)
Dim button As Byte
Dim temp As Byte
Dim tempstr As String
Dim tempicon As Byte
ClearScreen
Select Mode
Case PowerAdjust
//Draw Titles
tempstr = S_Transmit + " " + S_Power
// Button 0 Settings
MenuString(0) = S_Increase
ButtonSize(0) = LgButton
IconSelect(0) = None
// Button 1 Settings
MenuString(1) = S_Decrease
ButtonSize(1) = LgButton
IconSelect(1) = None
// Button 2 Settings
MenuString(2) = S_OK
ButtonSize(2) = LgButton
IconSelect(2) = None
// Button 3 Settings
MenuString(3) = ""
ButtonSize(3) = LgButton
IconSelect(3) = None
tempicon = sSrtIcon
temp = Power
Case BrightAdjust
//Draw Titles
tempstr = S_Brightness
// Button 0 Settings
MenuString(0) = S_Increase
ButtonSize(0) = LgButton
IconSelect(0) = None
// Button 1 Settings
MenuString(1) = S_Decrease
ButtonSize(1) = LgButton
IconSelect(1) = None
// Button 2 Settings
MenuString(2) = S_OK
ButtonSize(2) = LgButton
IconSelect(2) = None
// Button 3 Settings
MenuString(3) = ""
ButtonSize(3) = LgButton
IconSelect(3) = None
tempicon = sBright
temp = Brightness
End Select
DrawTitle(tempstr)
Repeat
Rectangle(0,32,319,159)
DrawPowerMeter(160, 75, 1, tempicon, temp)
button = DrawMenuScreen(3)
Select button
Case 0
If temp < 5 Then
Inc(temp)
EndIf
Case 1
If temp > 1 Then
Dec(temp)
EndIf
End Select
Select Mode
Case PowerAdjust
Power = temp
SendPower(Power)
EE.Write(EEPower,Power)
Case BrightAdjust
Brightness = temp
PWM.SetDuty1Percent(Brightness * 20)
EE.Write(EEBrightness,Brightness)
End Select
Until button = 2 'OK Button Pressed
End Sub
{
********************************************************************************
* Name : SettingsScreen *
* Purpose : Adjust options *
********************************************************************************
}
Sub SettingsScreen()
Dim button As Byte
Dim tempstr As String
Repeat
ClearScreen
DrawTitle(S_Settings) 'Draw Title
// Button 0 Settings
MenuString(0) = S_Brightness
ButtonSize(0) = LgButton
IconSelect(0) = sBright
// Button 1 Settings
MenuString(1) = S_EditPin
ButtonSize(1) = LgButton
IconSelect(1) = None
// Button 2 Settings
MenuString(2) = S_OK
ButtonSize(2) = LgButton
IconSelect(2) = None
// Button 3 Settings
MenuString(3) = ""
ButtonSize(3) = None
IconSelect(3) = None
Rectangle(136,32,319,159)
SetFontStyle(fsNormal)
//Display Battery Details
WriteAt(150,40,S_BatteryStatus)
WriteAt(150,65,S_Power)
tempstr = DecToStr(GetRemainPC) + " %"
WriteAt(200,80,tempstr)
tempstr = DecToStr(GetBattCurrent) + " mAH"
WriteAt(200,95,tempstr)
If ExtPower = 1 Then
WriteAt(150,125,S_DisCharging)
Else
WriteAt(150,125,S_Charging)
EndIf
button = DrawMenuScreen(3)
Select button
Case 0
PowerScreen(BrightAdjust)
Case 1
SetPin()
Case 2 // OK button doesnt seem to register correctly
Break
End Select
Until button = 2 'OK Button Pressed
End Sub
{
********************************************************************************
* Name : MainScreen *
* Purpose : Displays the Root selection screen *
********************************************************************************
}
Function MainScreen(Transmitting As Boolean) As Byte
Dim button As Byte
Dim CurrentChannel As Word
// Stop Timer Interrupt
'Timer.Stop
ClearScreen
DrawTitle(S_MainScreen) 'Draw Title
// Button 0 Settings
MenuString(0) = S_Channel
ButtonSize(0) = LgButton
IconSelect(0) = sChanIcon
// Button 1 Settings
MenuString(1) = S_Power
ButtonSize(1) = LgButton
IconSelect(1) = sPwrIcon
// Button 2 Settings
If Transmitting = False Then
MenuString(2) = S_Start
Else
MenuString(2) = S_Stop
EndIf
ButtonSize(2) = LgButton
IconSelect(2) = sSrtIcon
// Button 3 Settings
MenuString(3) = S_Settings
ButtonSize(3) = LgButton
IconSelect(3) = sSetIcon
SetFontStyle(fsNormal)
Rectangle(0,32,319,93)
Rectangle(0,98,319,159)
If Transmitting = False Then
WriteAt(189,224,S_TXIdle)
Else
WriteAt(189,224,S_Transmitting)
EndIf
TextAlign = taCenter
EE.Read(EEChannel, CurrentChannel)
WriteStr(220,55,DecToStr(CurrentChannel))
TextAlign = taLeft
Brush.Color = 1
DrawPowerMeter(190,113, 0, sSrtIcon, Power)
button = DrawMenuScreen(4)
result = button
End Function
{
********************************************************************************
* Name : Calibrate (PRIVATE) *
* Purpose : *
********************************************************************************
}
Sub Calibrate()
Dim XMIN_TL, XMAX_TL, YMIN_TL, YMAX_TL, XMIN_BR, XMAX_BR, YMIN_BR, YMAX_BR As Word
ClearScreen
TextAlign = taCenter
SetFontStyle(fsNormal)
' GLCD.Rectangle(0, 0, 319, 239)
GLCD.Line(0, 0, 20, 0)
GLCD.Line(0, 0, 0, 20)
GLCD.Line(0, 0, 40, 40)
GLCD.WriteStr(159, 110, S_CalibrateTL)
Repeat
Until TouchScreen.PenIsDown
DelayMS(30)
TouchScreen.GetXY(XMIN_TL, XMAX_BR, YMIN_TL, YMAX_BR)
Repeat
Until Not TouchScreen.PenIsDown
ClearScreen
GLCD.Line(319, 239, 299, 239)
GLCD.Line(319, 239, 319, 219)
GLCD.Line(319, 239, 279, 199)
GLCD.WriteStr(159, 110, S_CalibrateBR)
Repeat
Until TouchScreen.PenIsDown
DelayMS(30)
TouchScreen.GetXY(XMAX_TL, XMIN_BR, YMAX_TL, YMIN_BR)
Repeat
Until Not TouchScreen.PenIsDown
EE.Write(4, XMIN_TL)
EE.Write(6, XMAX_TL)
EE.Write(8, YMIN_TL)
EE.Write(10, YMAX_TL)
EE.Write(12, XMIN_BR)
EE.Write(14, XMAX_BR)
EE.Write(16, YMIN_BR)
EE.Write(18, YMAX_BR)
End Sub
{
********************************************************************************
* Name : Initalize *
* Purpose : Initalizes Hardware *
********************************************************************************
}
Sub Initalize()
Dim n As Byte
SetAllDigital()
SetFont(ArialBold12)
// Set Touchscreen Backlight
EE.Read(EEBrightness, Brightness)
PWM.SetFreq(5000) ' Todo, adjustable
PWM.SetDuty1Percent(Brightness * 20)
PWM.Start1
DelayMS(100)
//Startup Touchscreen
InitializeADC()
PenDown = False
// Load Touchscreen data
LoadTouchScreenCal
n = 0
// Option to reset Touchscreen calibration
Repeat
DelayMS(100)
Inc(n)
Until Switch = 0 Or n = 100 ' 100 = 10 second hold
// Run calibration & reload settings
If n = 100 Then
Calibrate()
LoadTouchScreenCal()
EndIf
// Start Timers
SetupTimers()
ClearScreen
End Sub
{
********************************************************************************
* Name : Main *
* Purpose : Main Program Loop *
********************************************************************************
}
Sub Main()
Dim selected As Byte
// Start Main Program
StartUp()
// Setup the Random Number Pool
InitializePool()
While 1 = 1
Selected = MainScreen(TXStat)
Select Selected
Case 0
If TXStat = False Then
ChannelScreen()
EndIf
Case 1
PowerScreen(PowerAdjust)
Case 2
TXStat = StartStop(TXStat)
Case 3
SettingsScreen()
End Select
Wend
End Sub
Main
Re: Looking for GLCD Menu sample code
Thanks for the code. However I'm still looking for an example of how to scroll and select menu items in a non touch screen GLCD scenario.