' Raspberry Pi LPC1114 I/O Processor Expansion Board SPI Agent Firmware ' ADC input 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 ADC Input 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, "Analog Input 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) LabelADC1 = Shapes.AddText("ADC1: 0.00V") LabelADC2 = Shapes.AddText("ADC2: 0.00V") LabelADC3 = Shapes.AddText("ADC3: 0.00V") LabelADC4 = Shapes.AddText("ADC4: 0.00V") LabelADC5 = Shapes.AddText("ADC5: 0.00V") Controls.Move(LabelADC1, W/2 - 100, 350) Controls.Move(LabelADC2, W/2 - 100, 400) Controls.Move(LabelADC3, W/2 - 100, 450) Controls.Move(LabelADC4, W/2 - 100, 500) Controls.Move(LabelADC5, W/2 - 100, 550) Controls.HideControl(LabelADC1) Controls.HideControl(LabelADC2) Controls.HideControl(LabelADC3) Controls.HideControl(LabelADC4) Controls.HideControl(LabelADC5) Else ' Layout the GUI for Windows Desktop GraphicsWindow.Width = 400 GraphicsWindow.Height = 240 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, "Analog Input Test") GraphicsWindow.FontSize = 14 GraphicsWindow.DrawText(30, 84, "Server name:") TextBoxServerName = Controls.AddTextBox(130, 80) ButtonConnect = Controls.AddButton("Connect", 300, 78) LabelADC1 = Shapes.AddText("ADC1: 0.00V") LabelADC2 = Shapes.AddText("ADC2: 0.00V") LabelADC3 = Shapes.AddText("ADC3: 0.00V") LabelADC4 = Shapes.AddText("ADC4: 0.00V") LabelADC5 = Shapes.AddText("ADC5: 0.00V") Controls.Move(LabelADC1, 150, 120) Controls.Move(LabelADC2, 150, 140) Controls.Move(LabelADC3, 150, 160) Controls.Move(LabelADC4, 150, 180) Controls.Move(LabelADC5, 150, 200) Controls.HideControl(LabelADC1) Controls.HideControl(LabelADC2) Controls.HideControl(LabelADC3) Controls.HideControl(LabelADC4) Controls.HideControl(LabelADC5) GraphicsWindow.Show() Endif ' Preload server name from command line argument If Program.ArgumentCount = 1 Then Controls.SetTextBoxText(TextBoxServerName, Program.GetArgument(1)) Endif ' Register the event handler subroutines Controls.ButtonClicked = ButtonHandler ' Sample analog inputs While "true" V1 = Math.Round(SPIAgent.AD1*100)/100 V2 = Math.Round(SPIAgent.AD2*100)/100 V3 = Math.Round(SPIAgent.AD3*100)/100 V4 = Math.Round(SPIAgent.AD4*100)/100 V5 = Math.Round(SPIAgent.AD5*100)/100 Shapes.SetText(LabelADC1, "ADC1: " + V1 + "V") Shapes.SetText(LabelADC2, "ADC2: " + V2 + "V") Shapes.SetText(LabelADC3, "ADC3: " + V3 + "V") Shapes.SetText(LabelADC4, "ADC4: " + V4 + "V") Shapes.SetText(LabelADC5, "ADC5: " + V5 + "V") Program.Delay(1000) EndWhile ' This subroutine handles button presses Sub ButtonHandler c = Controls.GetButtonCaption(Controls.LastClickedButton) 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 Shapes.SetText(LabelADC1, "ADC1:") Shapes.SetText(LabelADC2, "ADC2:") Shapes.SetText(LabelADC3, "ADC3:") Shapes.SetText(LabelADC4, "ADC4:") Shapes.SetText(LabelADC5, "ADC5:") Controls.ShowControl(LabelADC1) Controls.ShowControl(LabelADC2) Controls.ShowControl(LabelADC3) Controls.ShowControl(LabelADC4) Controls.ShowControl(LabelADC5) Controls.SetButtonCaption(ButtonConnect, "Disconnect") ElseIf c = "Disconnect" Then SPIAgent.Close() Shapes.SetText(LabelADC1, "ADC1:") Shapes.SetText(LabelADC2, "ADC2:") Shapes.SetText(LabelADC3, "ADC3:") Shapes.SetText(LabelADC4, "ADC4:") Shapes.SetText(LabelADC5, "ADC5:") Controls.HideControl(LabelADC1) Controls.HideControl(LabelADC2) Controls.HideControl(LabelADC3) Controls.HideControl(LabelADC4) Controls.HideControl(LabelADC5) Controls.SetButtonCaption(ButtonConnect, "Connect") EndIf ButtonHandlerDone: EndSub