WIZwikiREST-io Reference code for WIZnet Academy
Dependencies: DHT MbedJSONValue_v102 WIZnetInterface mbed-src
Fork of WIZwiki-REST-io_v103 by
Diff: main.cpp
- Revision:
- 6:2974bbc94e7a
- Parent:
- 5:473a66ae9596
- Child:
- 8:60d99da6eeb2
diff -r 473a66ae9596 -r 2974bbc94e7a main.cpp --- a/main.cpp Mon Jul 04 00:14:31 2016 +0000 +++ b/main.cpp Fri Jul 29 08:14:28 2016 +0000 @@ -8,7 +8,7 @@ #define SERVER_PORT 80 -//#define DHCP +#define DHCP //#define DEBUG @@ -22,15 +22,20 @@ start(); }; }; + +//-- I2C OLED -- I2CPreInit gI2C(PA_10,PA_9); Adafruit_SSD1306_I2c gOled(gI2C,NC,0x78,64,128); //-- PWM DC -- PwmOut DC(D6); -//-- GPIO -- +//-- GPIO LED -- DigitalInOut GP05(D5); +//-- ADC -- +AnalogIn ain(A0); + EthernetInterface eth; HTTPServer WIZwikiWebSvr; MbedJSONValue WIZwikiREST; @@ -41,6 +46,7 @@ char ip_addr[] = "192.168.100.100"; char subnet_mask[] = "255.255.255.0"; char gateway_addr[] = "192.168.100.1"; +float ain_value; GetRequestHandler myGetReq; PostRequestHandler myPostReq; @@ -48,7 +54,6 @@ //-- I2C OLED -- bool oled_set(void* param) { - printf("param : %c \r\n", param); char * oled; if(!param) return false; oled = (char*) param; @@ -61,7 +66,6 @@ //-- PWM DC -- bool pwm_set(void* param) { - printf("%d\r\n",(*(int*)param)); if(!param) return false; DC.write((float)(*(int*)param)/100.0); return true; @@ -69,10 +73,16 @@ //-- GPIO -- bool p5_set(void* param) { - if(!param) return false; + if(!param) return false; GP05.write(*(int*)param); return true; } +//-- ADC -- +bool ain_read(void* param) +{ + ((MbedJSONValue*)param)->_value.asDouble = ain.read(); + return true; +} void debug_info() { @@ -104,6 +114,9 @@ //GPIO set & init GP05.output(); GP05.write(1); + + //ADC init + // printf("START \r\n"); printf("sizeof(MbedJSONValue)=%d\r\n",sizeof(MbedJSONValue)); @@ -175,7 +188,7 @@ void WIZwiki_REST_init(void) { //Fill the object - WIZwikiREST["Name"] = "WIZwiki-RESTful-01"; + WIZwikiREST["Name"] = "WIZwikiREST-io ver1.01"; WIZwikiREST["Name"].accessible = false; #ifdef DEBUG debug_info(); @@ -204,6 +217,11 @@ WIZwikiREST["GPIOs"]["P05"] = GP05.read(); WIZwikiREST["GPIOs"]["P05"].accessible = true; WIZwikiREST["GPIOs"]["P05"].cb_action = p5_set; + + // ADC + WIZwikiREST["ADC"]["A0"] = ain.read(); + WIZwikiREST["ADC"]["A0"].accessible = false; + WIZwikiREST["ADC"]["A0"].cb_action = ain_read; #ifdef DEBUG debug_info();