1 / 9

Alternate User Interfaces

CS423 Dick Steflik. Alternate User Interfaces. User Interfaces. Traditional User Interfaces for Devices Allow the user control of/over the internal state of the device Buttons/Keys Lamps, LEDs, LCD panels Knobs, sliders

brone
Download Presentation

Alternate User Interfaces

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS423 Dick Steflik Alternate User Interfaces

  2. User Interfaces • Traditional User Interfaces for Devices • Allow the user control of/over the internal state of the device • Buttons/Keys • Lamps, LEDs, LCD panels • Knobs, sliders • On devices with embedded microcontrollers this can also be done via a web based user Interface (web page)‏

  3. Common Gateway Interface • A specification that describes how a web server exchanges data with a web program • How data from a web form is sent to a web server • What the web server does with the data • How the web server activates a specific program • How the program gets the user data and how it responds • http://hoohoo.ncsa.uiuc.edu/cgi/

  4. CGI • Standard HTTP used • can use GET or POST methods to send data • GET sends data (as name/value pairs) attached to URL • POST send data (as name/value pairs) in the HTTP body • Server will receive the request packet and place the data in an environment variable called QUERYSTRING and place it in SYSIN so that it can be retrieved by the processing program • SYSOUT is connected to the outgoing socket of the web server so that whatever is sent to sysout will go back as the body of the response packet (this could be a subsequent web page or just a positive response)‏

  5. Pictorially Browser Request Packet SYSIN Web Server C Program SYSOUT Response Packet

  6. cgipio.c /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <stdio.h> #include <errno.h> #include <fcntl.h> #include <string.h> #include <unistd.h> #define BUFFERSIZE 257 #define LED_OFFSET 19 int main(int argc, char *argv[])‏ { int i = 0; int pio = 0; int retval = 0; int toggle = 0; int led_on = -1; int read_bytes = 0; unsigned int pio_buffer; char buffer[BUFFERSIZE]; /* Read in stuff from stdinn */ while ((i = read(0, buffer, BUFFERSIZE-1)) != 0) { read_bytes += i; } buffer[read_bytes] = '\0'; if(strstr(buffer, "toggle=1") != 0) { toggle = 1; }

  7. (cont.)‏ /* Print basic headers */ printf("HTTP/1.0 200 OK\n"); printf("Content-type: text/html\n\n"); printf( "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n" "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/webif.css\" />" "<?xml-stylesheet href=\"/include/style.css\" type=\"text/css\" media=\"screen\" ?>" "<head>\n" "<title>AVR32 NGW pin toggler</title>\n" "</head>\n" "<body style=\"margin: 30px; color: #C3C4D2; background-color: #213242;\">\n" ); printf("<h1>AVR32 NGW pin toggler</h1>\n"); printf("<p><a style=\"color: inherit;\" href=\"/\">Back to home...</a></p>\n"); printf("<br />"); printf("<p>");

  8. (cont.)‏ /* Get status on LED */ pio = open("/dev/gpio1", O_RDWR|O_NONBLOCK); get_status: if (pio < 0) { printf("Error: I could not open the GPIO device.</p>\n"); goto error; } else { retval = read(pio, &pio_buffer, 4); if (retval == 4) { led_on = pio_buffer & (1<<LED_OFFSET) ? 0 : 1; } else { if (retval >= 0) { printf("Error: I could only read %d bytes from the GPIO device.</p>\n", retval); } else { if (errno != EAGAIN) { printf("Error: I could not read from the GPIO device (%d).</p>\n", errno); } } } }

  9. if (led_on) { printf("LED is on => "); } else { printf("LED is off => "); } if (toggle == 1 && led_on == 1) { unsigned int off = 1<<LED_OFFSET; write(pio, &off, 4); printf("turning LED off => "); toggle = 0; goto get_status; } else if (toggle == 1 && led_on == 0) { unsigned int on = 0; write(pio, &on, 4); printf("turning LED on => "); toggle = 0; goto get_status; } else if (toggle == 1) { printf( "LED was ordered to be toggled, but I could " "not find out if I was supposed to turn it " "off or on, I am very sorry :'(" ); } else if (led_on) { printf("do you want to turn it off?"); } else { printf("do you want to turn it on?"); } printf("</p>\n"); printf("<br />\n"); printf( "<div><form method=\"post\" action=\"cgipio.cgi\" " "name=\"cgipio\">\n" "<input type=\"hidden\" name=\"toggle\" value=\"1\" />\n" "<input type=\"submit\" value=\"Change LED\" />\n" "</form></div>\n" ); close(pio); error: printf("</body></html>\n"); return 0; } (cont.)‏

More Related