From 7059fd523d6514d04e232f1d0acbc983856bd2e6 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 21 Jul 2015 19:10:32 +0100 Subject: first shipped version --- polycom_xmit/Makefile | 2 +- polycom_xmit/gpio.c | 65 +++++++++++++++++++++++++++++++++++++++++------ polycom_xmit/msg.c | 4 +-- polycom_xmit/prototypes.h | 3 ++- polycom_xmit/webserver.c | 8 ++++-- 5 files changed, 68 insertions(+), 14 deletions(-) diff --git a/polycom_xmit/Makefile b/polycom_xmit/Makefile index d90f22c..1711462 100644 --- a/polycom_xmit/Makefile +++ b/polycom_xmit/Makefile @@ -6,7 +6,7 @@ INCLUDES=-Idummy GCCFLAGS=-fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections -PORT=/dev/ttyUSB1 +PORT=/dev/ttyUSB0 #BAUD=-b 921600 #BAUD=-b 460800 #BAUD=-b 200000 diff --git a/polycom_xmit/gpio.c b/polycom_xmit/gpio.c index 04dad5d..8e8c66a 100644 --- a/polycom_xmit/gpio.c +++ b/polycom_xmit/gpio.c @@ -8,20 +8,21 @@ static struct gpio uint32_t pin; uint32_t func; uint32_t bit; + int pull; } gpios[] = { { - 0, PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0, BIT0}, + 0, PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0, BIT0, 1}, { - 2, PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2, BIT2}, + 2, PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2, BIT2, 1}, { - 12, PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12, BIT12}, + 12, PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12, BIT12, 0}, { - 13, PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13, BIT13}, + 13, PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13, BIT13, 1}, { - 14, PERIPHS_IO_MUX_MTMS_U, FUNC_GPIO14, BIT14}, + 14, PERIPHS_IO_MUX_MTMS_U, FUNC_GPIO14, BIT14, 1}, { - 15, PERIPHS_IO_MUX_MTDO_U, FUNC_GPIO15, BIT15} + 15, PERIPHS_IO_MUX_MTDO_U, FUNC_GPIO15, BIT15, 0} }; #define N_GPIOS (sizeof(gpios)/sizeof(gpios[0])) @@ -42,7 +43,10 @@ void ICACHE_FLASH_ATTR gpio_dispatch (void) { uint32_t v = gpio_read (); - msg_send (v); + int red, green; + red = ! !(v & BIT12); + green = ! !(v & BIT14); + msg_send (red,green,v); } @@ -128,6 +132,48 @@ gpio_page (struct espconn *conn) +void ICACHE_FLASH_ATTR +gpio_colour_page (struct espconn *conn) +{ + char *page = os_zalloc (1024); + char *ptr = page; + int i; + uint32_t j, v; + int red, green; + + if (!page) + { + webserver_send_reply (conn, 400, "text/html", + "Out of memory", + 0); + return; + + } + + ptr += os_sprintf (ptr, ""); + ptr += os_sprintf (ptr, ""); + ptr += os_sprintf (ptr, ""); + + v = gpio_read (); + + red = ! !(v & BIT12); + green = ! !(v & BIT14); + + if ((!red) && (!green)) + ptr += os_sprintf (ptr, ""); + else if ((!red) && (green)) + ptr += os_sprintf (ptr, ""); + else if ((red) && (!green)) + ptr += os_sprintf (ptr, ""); + else if ((red) && (green)) + ptr += os_sprintf (ptr, ""); + ptr += os_sprintf (ptr, ""); + webserver_send_reply (conn, 200, "text/html", page, ptr - page); + os_free (page); +} + + + @@ -143,7 +189,10 @@ gpio_init (void) for (i = 0; i < N_GPIOS; ++i) { PIN_FUNC_SELECT (gpios[i].pin, gpios[i].func); - PIN_PULLUP_EN (gpios[i].pin); + if (gpios[i].pull) + PIN_PULLUP_EN (gpios[i].pin); + else + PIN_PULLUP_DIS (gpios[i].pin); /* disable drivers */ gpio_output_set (0, 0, 0, gpios[i].bit); diff --git a/polycom_xmit/msg.c b/polycom_xmit/msg.c index 92931e4..f990a41 100644 --- a/polycom_xmit/msg.c +++ b/polycom_xmit/msg.c @@ -4,12 +4,12 @@ static struct espconn udp; void ICACHE_FLASH_ATTR -msg_send (uint32_t v) +msg_send (int red, int green, uint32_t v) { char buf[32]; size_t len; - len = os_sprintf (buf, "%x\r\n", v); + len = os_sprintf (buf, "%d,%d,%x\r\n", red,green,v); udp.proto.udp->remote_port = 29153; diff --git a/polycom_xmit/prototypes.h b/polycom_xmit/prototypes.h index 3c41147..ee3f7fe 100644 --- a/polycom_xmit/prototypes.h +++ b/polycom_xmit/prototypes.h @@ -21,9 +21,10 @@ void upgrade(void); uint32_t gpio_read(void); void gpio_dispatch(void); void gpio_page(struct espconn *conn); +void gpio_colour_page(struct espconn *conn); void gpio_init(void); /* msg.c */ void msg_send(uint32_t v); void msg_init(void); /* mdns.c */ -void mdns_init(void); +void mdns_start(void); diff --git a/polycom_xmit/webserver.c b/polycom_xmit/webserver.c index d7d6c92..2d34927 100644 --- a/polycom_xmit/webserver.c +++ b/polycom_xmit/webserver.c @@ -334,7 +334,7 @@ webserver_req (struct espconn *conn, http_state * s) 0); crash (); } - else if (os_strstr (s->url, "/upgrade.html")) + else if (!os_strcmp (s->url, "/upgrade.html")) { webserver_send_reply (conn, 200, "text/html", "triggered upgrade", @@ -342,10 +342,14 @@ webserver_req (struct espconn *conn, http_state * s) os_printf ("Upgrading\n"); upgrade (); } - else if (os_strstr (s->url, "/gpio.html")) + else if (!os_strcmp (s->url, "/gpio.html")) { gpio_page (conn); } + else if (!os_strcmp (s->url, "/")) + { + gpio_colour_page (conn); + } else { webserver_send_reply (conn, 404, "text/html", -- cgit v1.2.3