Here are my static ports.
static OutputPort led13 = new OutputPort(Pins.GPIO_PIN_D13, false); static OutputPort led12 = new OutputPort(Pins.GPIO_PIN_D12, false); static InputPort in0 = new InputPort(Pins.GPIO_PIN_D0, false, Port.ResistorMode.Disabled); static InputPort in1 = new InputPort(Pins.GPIO_PIN_D1, false, Port.ResistorMode.Disabled);
Here is a rough copy of the ProcessRequest function that I have been working on.
private static string ProcessRequest(string receivedStr) { //-- Parse the first line of the request: "GET /led/1 HTTP/1.1\r" -- string firstLine = receivedStr.Substring(0, receivedStr.IndexOf('\n')); string sReturn = "Command executed at " + DateTime.Now.ToString(); string[] words = firstLine.Split(' '); string[] parts = words[1].Split('/'); string cmd = parts.Length > 1 ? parts[1] : ""; string param1 = parts.Length > 2 ? parts[2] : ""; string param2 = parts.Length > 3 ? parts[3] : ""; object selport; //-- Add more commands and param handling here -- switch (cmd) { case "led13": selport = (OutputPort) led13; case "led12": selport = (OutputPort)led12; case "in0": selport = (InputPort) in0; case "in1": selport = (InputPort)in1; default: sReturn = "Unknown Command at " + DateTime.Now.ToString(); break; } if (selport != null) { switch (param1) { case "state": if (selport.Read()) sReturn = "Led is On at " + DateTime.Now.ToString(); else sReturn = "Led is Off at " + DateTime.Now.ToString(); break; case "set": if (typeof(selport) == typeof(InputPort)) { selport.Write(param2 == "1"); } break; default: sReturn = "Unknown Parameter at " + DateTime.Now.ToString(); break; } } //-- Optional string to return to caller -- return sReturn; }
Is there an easier way to do this with mixed Input and Output ports?