' MuntsOS Dedicated GPIO Server Toggle Test ' Copyright (C)2014-2016, 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. ' Lay out GUI GraphicsWindow.Width = 300 GraphicsWindow.Height = 130 GraphicsWindow.Title = "LED Control Program" GraphicsWindow.Show() GraphicsWindow.DrawText(40, 30, "Server:") ServerBox = Controls.AddTextBox(100, 28) ConnectButton = Controls.AddButton("Connect", 120, 80) ' Everything happens in the button handler subroutine Controls.ButtonClicked = ButtonHandler Sub ButtonHandler b = Controls.LastClickedButton c = Controls.GetButtonCaption(b) If c = "Connect" Then servername = Controls.GetTextBoxText(ServerBox) pin = 26 direction = 1 PutDDR() data = 0 PutGPIO() Controls.SetButtonCaption(b, " ON ") EndIf If c = " ON " Then data = 1 PutGPIO() Controls.SetButtonCaption(b, " OFF ") EndIf If c = " OFF " Then data = 0 PutGPIO() Controls.SetButtonCaption(b, " ON ") EndIf EndSub ' ******************* GPIO server subroutines follow ******************* ' Write GPIO data direction bit ' Parameter variables: ' servername -- IP address or host name ' pin -- GPIO pin number (2-26, as numbered by Linux) ' direction -- 0 for input, 1 for output Sub PutDDR webpage = Network.GetWebPageContents("http://" + servername + ":8083/GPIO/ddr/" + pin + "," + direction) If Text.StartsWith(webpage, "DDR" + pin + "=") Then Else GraphicsWindow.ShowMessage(webpage, "GPIO Server Error") EndIf EndSub ' Read GPIO data bit ' Parameter variables: ' servername -- IP address or host name ' pin -- GPIO pin number (2-26, as numbered by Linux) ' data -- Set to 0 or 1 Sub GetGPIO webpage = Network.GetWebPageContents("http://" + servername + ":8083/GPIO/get/" + pin) If Text.StartsWith(webpage, "GPIO" + pin + "=") Then data = Text.GetSubTextToEnd(webpage, Text.GetIndexOf(webpage, "=") + 1) Else GraphicsWindow.ShowMessage(webpage, "GPIO Server Error") EndIf EndSub ' Write GPIO data bit ' Parameter variables: ' servername -- IP address or host name ' pin -- GPIO pin number (2-26, as numbered by Linux) ' data -- 0=OFF (low), 1=ON (high) Sub PutGPIO webpage = Network.GetWebPageContents("http://" + servername + ":8083/GPIO/put/" + pin + "," + data) If Text.StartsWith(webpage, "GPIO" + pin + "=") Then Else GraphicsWindow.ShowMessage(webpage, "GPIO Server Error") EndIf EndSub