summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <root@lamia.panaceas.james.local>2015-07-21 10:12:26 +0100
committerroot <root@lamia.panaceas.james.local>2015-07-21 10:12:26 +0100
commita98e5d802b071a240ba38dfa9b039fd3f7d47ffd (patch)
tree292ffdc875fb75bf413f070a58b84f74a911232b
parent16debdbce7a5d92167207c17f18406c6905eb9b5 (diff)
downloadpolycom-a98e5d802b071a240ba38dfa9b039fd3f7d47ffd.tar.gz
polycom-a98e5d802b071a240ba38dfa9b039fd3f7d47ffd.tar.bz2
polycom-a98e5d802b071a240ba38dfa9b039fd3f7d47ffd.zip
fish
-rw-r--r--polycom_xmit/Makefile4
-rw-r--r--polycom_xmit/gpio.c21
-rw-r--r--polycom_xmit/main.c24
-rw-r--r--polycom_xmit/mdns.c57
-rw-r--r--polycom_xmit/prototypes.h3
-rw-r--r--polycom_xmit/wifi.c2
6 files changed, 79 insertions, 32 deletions
diff --git a/polycom_xmit/Makefile b/polycom_xmit/Makefile
index 3e2aae5..d90f22c 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/ttyUSB0
+PORT=/dev/ttyUSB1
#BAUD=-b 921600
#BAUD=-b 460800
#BAUD=-b 200000
@@ -25,7 +25,7 @@ PROG0=${PROG}.0
PROG1=${PROG}.1
PROG2=${PROG}.2
-SRC=main.c webserver.c util.c reset.c wifi.c uart.c upgrade.c gpio.c msg.c
+SRC=main.c webserver.c util.c reset.c wifi.c uart.c upgrade.c gpio.c msg.c mdns.c
UART_BAUD=115200
diff --git a/polycom_xmit/gpio.c b/polycom_xmit/gpio.c
index 8a595ac..04dad5d 100644
--- a/polycom_xmit/gpio.c
+++ b/polycom_xmit/gpio.c
@@ -26,14 +26,22 @@ static struct gpio
#define N_GPIOS (sizeof(gpios)/sizeof(gpios[0]))
+static uint32_t mask;
+
static os_timer_t gpio_timer;
static os_timer_t gpio_intr_timer;
+uint32_t ICACHE_FLASH_ATTR
+gpio_read (void)
+{
+ return gpio_input_get () & mask;
+}
+
void ICACHE_FLASH_ATTR
gpio_dispatch (void)
{
- uint32_t v = gpio_input_get ();
+ uint32_t v = gpio_read ();
msg_send (v);
}
@@ -97,19 +105,19 @@ gpio_page (struct espconn *conn)
"}\n"
"table, th, td {\n"
"border: 1px solid black;\n" "}\n" "</style>");
-
+ ptr += os_sprintf (ptr, "<meta http-equiv='refresh' content='5'>");
ptr += os_sprintf (ptr, "</head><body>");
- v = gpio_input_get ();
+ v = gpio_read ();
ptr += os_sprintf (ptr, "<h2>GPIO: 0x%04x</h2><br/>", v);
ptr += os_sprintf (ptr, "<table>");
- for (i = 0; i < 16; ++i)
+ for (i = 0; i < N_GPIOS; ++i)
{
- j = 1 << i;
ptr +=
os_sprintf (ptr,
"<tr><td>%d</td><td>0x%04x</td><td>%s</td></tr>",
- i, j, (j & v) ? "High" : "Low");
+ gpios[i].id, gpios[i].bit,
+ (gpios[i].bit & v) ? "High" : "Low");
}
@@ -149,6 +157,7 @@ gpio_init (void)
gpio_pin_intr_state_set (GPIO_ID_PIN (gpios[i].id),
GPIO_PIN_INTR_ANYEDGE);
+ mask |= gpios[i].bit;
}
ETS_GPIO_INTR_ENABLE ();
diff --git a/polycom_xmit/main.c b/polycom_xmit/main.c
index d7bc0bf..e04f607 100644
--- a/polycom_xmit/main.c
+++ b/polycom_xmit/main.c
@@ -13,33 +13,11 @@ user_init (void)
os_printf ("SDK version:%s\n", system_get_sdk_version ());
os_printf ("Hello world\n");
-
reset_init ();
wifi_init ();
msg_init ();
gpio_init ();
-
-
-
-
-#if 0
-
- /*Initialization of the peripheral drivers */
- /*For light demo , it is user_light_init(); */
- /* Also check whether assigned ip addr by the router.If so, connect to ESP-server */
- user_esp_platform_init ();
- /*Establish a udp socket to receive local device detect info. */
- /*Listen to the port 1025, as well as udp broadcast.
- /*If receive a string of device_find_request, it rely its IP address and MAC. */
- user_devicefind_init ();
-
- /*Establish a TCP server for http(with JSON) POST or GET command to communicate with the device. */
- /*You can find the command in "2B-SDK-Espressif IoT Demo.pdf" to see the details. */
- /*the JSON command for curl is like: */
- /*3 Channel mode: curl -X POST -H "Content-Type:application/json" -d "{\"period\":1000,\"rgb\":{\"red\":16000,\"green\":16000,\"blue\":16000}}" http://192.168.4.1/config?command=light */
- /*5 Channel mode: curl -X POST -H "Content-Type:application/json" -d "{\"period\":1000,\"rgb\":{\"red\":16000,\"green\":16000,\"blue\":16000,\"cwhite\":3000,\"wwhite\",3000}}" http://192.168.4.1/config?command=light */
-#endif
-
+ mdns_start();
webserver_init ();
}
diff --git a/polycom_xmit/mdns.c b/polycom_xmit/mdns.c
new file mode 100644
index 0000000..e01ba11
--- /dev/null
+++ b/polycom_xmit/mdns.c
@@ -0,0 +1,57 @@
+#include "project.h"
+
+static os_timer_t mdns_timer;
+
+static struct mdns_info *info;
+
+
+
+static void ICACHE_FLASH_ATTR
+check_connexion (void *arg)
+{
+ struct ip_info ipconfig;
+ static ip_addr_t last_ip;
+
+ wifi_get_ip_info (STATION_IF, &ipconfig);
+
+ if (wifi_station_get_connect_status () != STATION_GOT_IP)
+ return;
+
+ if (ipconfig.ip.addr == last_ip.addr)
+ return;
+
+ last_ip.addr = ipconfig.ip.addr;
+
+
+
+ if (info)
+ {
+ espconn_mdns_close ();
+ os_free (info);
+ }
+
+ info = (struct mdns_info *) os_zalloc (sizeof (struct mdns_info));
+
+ if (!info)
+ {
+ last_ip.addr = 0;
+ return;
+ }
+
+
+ info->host_name = "polycom-2w";
+ info->ipAddr = last_ip.addr;
+ info->server_name = "leds";
+ info->server_port = 80;
+ info->txt_data[0] = "version = 1.0.1";
+ espconn_mdns_init (info);
+
+}
+
+void ICACHE_FLASH_ATTR
+mdns_start (void)
+{
+ os_timer_disarm (&mdns_timer);
+ os_timer_setfn (&mdns_timer, (os_timer_func_t *) check_connexion, NULL);
+ os_timer_arm (&mdns_timer, 10000, 1);
+}
diff --git a/polycom_xmit/prototypes.h b/polycom_xmit/prototypes.h
index 0aa91dd..3c41147 100644
--- a/polycom_xmit/prototypes.h
+++ b/polycom_xmit/prototypes.h
@@ -18,9 +18,12 @@ void uart_init(void);
/* upgrade.c */
void upgrade(void);
/* gpio.c */
+uint32_t gpio_read(void);
void gpio_dispatch(void);
void gpio_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);
diff --git a/polycom_xmit/wifi.c b/polycom_xmit/wifi.c
index 0b2c725..9cb31ca 100644
--- a/polycom_xmit/wifi.c
+++ b/polycom_xmit/wifi.c
@@ -4,7 +4,7 @@ wifi_init (void)
{
struct station_config config = { 0 };
- os_strcpy (config.ssid, "haddock-bg");
+ os_strcpy (config.ssid, "medaka-bgn");
os_strcpy (config.password, "fishsoup");
wifi_station_set_config_current (&config);