' Raspberry Pi LPC1114 I/O Processor Expansion Board SPI Agent Firmware ' LED test program ' Copyright (C)2015-2018, Philip Munts, President, Munts AM Corp. ' ' Redistribution and use in source and binary forms, with or without ' modification, are permitted provided that the following conditions are met: ' ' * Redistributions of source code must retain the above copyright notice, ' this list of conditions and the following disclaimer. ' ' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ' IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ' ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE ' LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR ' CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF ' SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ' INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN ' CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ' ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ' POSSIBILITY OF SUCH DAMAGE. ' Layout the GUI IsTablet = LDFile.Exists("C:\ProgramData\MuntsTechnologies\tablet.txt") GraphicsWindow.Title = "Raspberry Pi LPC1114 LED Test" GraphicsWindow.BrushColor = "black" If IsTablet Then ' Layout the GUI for Windows tablet LDUtilities.GWState = 2 W = GraphicsWindow.Width H = GraphicsWindow.Height GraphicsWindow.FontSize = 32 GraphicsWindow.DrawText(W/2 - 300, 50, "Raspberry Pi LPC1114 I/O Processor") GraphicsWindow.DrawText(W/2 - 300, 100, "Expansion Board SPI Agent Firmware") GraphicsWindow.DrawText(W/2 - 300, 150, "LED Test") GraphicsWindow.FontSize = 30 GraphicsWindow.DrawText(W/2 - 270, 250, "Server name:") TextBoxServerName = Controls.AddTextBox(W/2 - 60, 250) ButtonConnect = Controls.AddButton("Connect", W/2 + 120, 250) ButtonLED = Controls.AddButton("Waiting", W/2 - 120, 350) Else ' Layout the GUI for Windows Desktop GraphicsWindow.Width = 400 GraphicsWindow.Height = 180 GraphicsWindow.FontSize = 18 GraphicsWindow.DrawText(30, 10, "Raspberry Pi LPC1114 I/O Processor") GraphicsWindow.DrawText(30, 30, "Expansion Board SPI Agent Firmware") GraphicsWindow.DrawText(30, 50, "LED Test") GraphicsWindow.FontSize = 14 GraphicsWindow.DrawText(30, 84, "Server name:") TextBoxServerName = Controls.AddTextBox(130, 80) ButtonConnect = Controls.AddButton("Connect", 300, 78) ButtonLED = Controls.AddButton("Waiting", 140, 120) GraphicsWindow.Show() Endif Controls.HideControl(ButtonLED) ' Preload server name from command line argument If Program.ArgumentCount = 1 Then Controls.SetTextBoxText(TextBoxServerName, Program.GetArgument(1)) Endif ' Register the button click event handler Controls.ButtonClicked = ButtonHandler ' Monitor the LPC1114 LED for changes from another program While "true" Program.Delay(500) If Controls.GetButtonCaption(ButtonConnect) = "Disconnect" Then If SPIAgent.LED = 1 Then Controls.SetButtonCaption(ButtonLED, "Turn LED OFF") Else Controls.SetButtonCaption(ButtonLED, "Turn LED ON") EndIF EndIf EndWhile ' This subroutine handles button presses Sub ButtonHandler c = Controls.GetButtonCaption(Controls.LastClickedButton) ' Connect button pressed If c = "Connect" Then SPIAgent.Open(Controls.GetTextBoxText(TextBoxServerName)) If SPIAgent.error <> 0 Then GraphicsWindow.ShowMessage("SPIAgent.Open() returned error " + SPIAgent.error, "ERROR:") Goto ButtonHandlerDone Endif If SPIAgent.LED = 1 Then Controls.SetButtonCaption(ButtonLED, "Turn LED OFF") Else Controls.SetButtonCaption(ButtonLED, "Turn LED ON") EndIF Controls.SetButtonCaption(ButtonConnect, "Disconnect") Controls.ShowControl(ButtonLED) ' Disconnect button pressed ElseIf c = "Disconnect" Then SPIAgent.Close() Controls.SetButtonCaption(ButtonConnect, "Connect") Controls.HideControl(ButtonLED) ' Turn LED ON button pressed ElseIf c = "Turn LED ON" Then SPIAgent.LED = "ON" If SPIAgent.error <> 0 Then GraphicsWindow.ShowMessage("SPIAgent.Command() returned error " + SPIAgent.error, "ERROR:") SPIAgent.Close() Controls.SetButtonCaption(ButtonConnect, "Connect") Controls.HideControl(ButtonLED) Goto ButtonHandlerDone Endif Controls.SetButtonCaption(ButtonLED, "Turn LED OFF") ' Turn LED OFF button pressed ElseIf c = "Turn LED OFF" Then SPIAgent.LED = "OFF" If SPIAgent.error <> 0 Then GraphicsWindow.ShowMessage("SPIAgent.Command() returned error " + SPIAgent.error, "ERROR:") SPIAgent.Close() Controls.SetButtonCaption(ButtonConnect, "Connect") Controls.HideControl(ButtonLED) Goto ButtonHandlerDone Endif Controls.SetButtonCaption(ButtonLED, "Turn LED ON") EndIf ButtonHandlerDone: EndSub