' Raspberry Pi LPC1114 I/O Processor Expansion Board SPI Agent Firmware ' Version 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 Version 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, "Version Test") GraphicsWindow.FontSize = 32 GraphicsWindow.DrawText(W/2 - 300, 250, "Server name:") TextBoxServerName = Controls.AddTextBox(W/2 - 80, 245) Controls.SetSize(TextBoxServerName, 260, 50) ButtonQuery = Controls.AddButton("Query", W/2 + 190, 245) Results1 = Shapes.AddText("") Results2 = Shapes.AddText("") Controls.Move(Results1, W/2 - 350, 350) Controls.Move(Results2, W/2 - 350, 400) 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, "Version Test") GraphicsWindow.FontSize = 14 GraphicsWindow.DrawText(30, 84, "Server name:") TextBoxServerName = Controls.AddTextBox(130, 80) ButtonQuery = Controls.AddButton("Query", 300, 78) Results1 = Shapes.AddText("") Results2 = Shapes.AddText("") Controls.Move(Results1, 30, 120) Controls.Move(Results2, 30, 140) GraphicsWindow.Show() Endif ' 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 ' This subroutine handles button presses Sub ButtonHandler c = Controls.GetButtonCaption(Controls.LastClickedButton) ' Query button pressed If c = "Query" Then SPIAgent.Open(Controls.GetTextBoxText(TextBoxServerName)) If SPIAgent.error <> 0 Then GraphicsWindow.ShowMessage("SPIAgent.Open() returned error " + SPIAgent.error, "ERROR:") Goto ButtonHandlerDone Endif ' Query the firmware version SPIAgent.Command("nop", 0, 0) If SPIAgent.error <> 0 Then GraphicsWindow.ShowMessage("SPIAgent.Command() returned error " + SPIAgent.error, "ERROR:") Goto ButtonHandlerDone EndIf firmware_version = SPIAgent.data ' Query the LPC1114 device ID SPIAgent.Command("get_sfr", "device_id", 0) If SPIAgent.error <> 0 Then GraphicsWindow.ShowMessage("SPIAgent.Command() returned error " + SPIAgent.error, "ERROR:") Goto ButtonHandlerDone EndIf device_id = SPIAgent.datahex Shapes.SetText(Results1, "The SPI Agent Firmware version number is " + firmware_version) Shapes.SetText(Results2, "The LPC1114 device ID is " + device_id) SPIAgent.Close() EndIf ButtonHandlerDone: EndSub