![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Upper Version Add PUT method Delete POST method
Dependencies: Adafruit_GFX MbedJSONValue_v102 WIZnetInterface mbed
Fork of WIZwiki-REST-io_v102 by
Diff: main.cpp
- Revision:
- 5:473a66ae9596
- Parent:
- 4:0b5a199e91f3
- Child:
- 6:2974bbc94e7a
--- a/main.cpp Tue May 31 10:31:30 2016 +0000 +++ b/main.cpp Mon Jul 04 00:14:31 2016 +0000 @@ -3,13 +3,34 @@ #include "RequestHandler.h" #include "EthernetInterface.h" #include "MbedJSONValue.h" +// 20160630 +#include "Adafruit_SSD1306.h" #define SERVER_PORT 80 -#define DHCP +//#define DHCP //#define DEBUG +//-- I2C OLED -- +class I2CPreInit : public I2C +{ +public: + I2CPreInit(PinName sda, PinName scl) : I2C(sda, scl) + { + frequency(100000); + start(); + }; +}; +I2CPreInit gI2C(PA_10,PA_9); +Adafruit_SSD1306_I2c gOled(gI2C,NC,0x78,64,128); + +//-- PWM DC -- +PwmOut DC(D6); + +//-- GPIO -- +DigitalInOut GP05(D5); + EthernetInterface eth; HTTPServer WIZwikiWebSvr; MbedJSONValue WIZwikiREST; @@ -24,239 +45,34 @@ GetRequestHandler myGetReq; PostRequestHandler myPostReq; -DigitalOut LED_1(PA_1); -DigitalOut LED_2(PA_2); - -DigitalInOut GP05(P5); -DigitalInOut GP06(P6); -DigitalInOut GP07(P7); -DigitalInOut GP08(P8); -DigitalInOut GP09(P9); -DigitalInOut GP10(P10); -DigitalInOut GP11(P11); -DigitalInOut GP12(P12); -DigitalInOut GP13(P13); -DigitalInOut GP14(P14); -DigitalInOut GP15(P15); -DigitalInOut GP16(P16); -DigitalInOut GP17(P17); -DigitalInOut GP18(P18); -DigitalInOut GP19(P19); -DigitalInOut GP20(P20); -DigitalInOut GP21(P21); -DigitalInOut GP22(P22); -DigitalInOut GP23(P23); -DigitalInOut GP24(P24); -DigitalInOut GP25(P25); -DigitalInOut GP26(P26); -DigitalInOut GP27(P27); -DigitalInOut GP28(P28); -DigitalInOut GP29(P29); -DigitalInOut GP30(P30); -DigitalInOut GP31(P31); -DigitalInOut GP32(P32); - - -bool gpio_all(void* param) +//-- I2C OLED -- +bool oled_set(void* param) { + printf("param : %c \r\n", param); + char * oled; if(!param) return false; - GP05.write(*(int*)param); - GP06.write(*(int*)param); - GP07.write(*(int*)param); - GP08.write(*(int*)param); - GP09.write(*(int*)param); - GP10.write(*(int*)param); - GP11.write(*(int*)param); - GP12.write(*(int*)param); - GP13.write(*(int*)param); - GP14.write(*(int*)param); - GP15.write(*(int*)param); - GP16.write(*(int*)param); - GP17.write(*(int*)param); - GP18.write(*(int*)param); - GP19.write(*(int*)param); - GP20.write(*(int*)param); - GP21.write(*(int*)param); - GP22.write(*(int*)param); - GP23.write(*(int*)param); - GP24.write(*(int*)param); - GP25.write(*(int*)param); - GP26.write(*(int*)param); - GP27.write(*(int*)param); - GP28.write(*(int*)param); - GP29.write(*(int*)param); + oled = (char*) param; + gOled.clearDisplay(); + gOled.setTextCursor(0,0); + gOled.printf("%s",oled); + gOled.display(); return true; } - - +//-- 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; +} +//-- GPIO -- bool p5_set(void* param) { if(!param) return false; GP05.write(*(int*)param); return true; } -bool p6_set(void* param) -{ - if(!param) return false; - GP06.write(*(int*)param); - return true; -} -bool p7_set(void* param) -{ - if(!param) return false; - GP07.write(*(int*)param); - return true; -} -bool p8_set(void* param) -{ - if(!param) return false; - GP08.write(*(int*)param); - return true; -} -bool p9_set(void* param) -{ - if(!param) return false; - GP09.write(*(int*)param); - return true; -} -bool p10_set(void* param) -{ - if(!param) return false; - GP10.write(*(int*)param); - return true; -} -bool p11_set(void* param) -{ - if(!param) return false; - GP11.write(*(int*)param); - return true; -} -bool p12_set(void* param) -{ - if(!param) return false; - GP12.write(*(int*)param); - return true; -} -bool p13_set(void* param) -{ - if(!param) return false; - GP13.write(*(int*)param); - return true; -} -bool p14_set(void* param) -{ - if(!param) return false; - GP14.write(*(int*)param); - return true; -} -bool p15_set(void* param) -{ - if(!param) return false; - GP15.write(*(int*)param); - return true; -} -bool p16_set(void* param) -{ - if(!param) return false; - GP16.write(*(int*)param); - return true; -} -bool p17_set(void* param) -{ - if(!param) return false; - GP17.write(*(int*)param); - return true; -} -bool p18_set(void* param) -{ - if(!param) return false; - GP18.write(*(int*)param); - return true; -} -bool p19_set(void* param) -{ - if(!param) return false; - GP19.write(*(int*)param); - return true; -} -bool p20_set(void* param) -{ - if(!param) return false; - GP20.write(*(int*)param); - return true; -} -bool p21_set(void* param) -{ - if(!param) return false; - GP21.write(*(int*)param); - return true; -} -bool p22_set(void* param) -{ - if(!param) return false; - GP22.write(*(int*)param); - return true; -} -bool p23_set(void* param) -{ - if(!param) return false; - GP23.write(*(int*)param); - return true; -} -bool p24_set(void* param) -{ - if(!param) return false; - GP24.write(*(int*)param); - return true; -} -bool p25_set(void* param) -{ - if(!param) return false; - GP25.write(*(int*)param); - return true; -} -bool p26_set(void* param) -{ - if(!param) return false; - GP26.write(*(int*)param); - return true; -} -bool p27_set(void* param) -{ - if(!param) return false; - GP27.write(*(int*)param); - return true; -} -bool p28_set(void* param) -{ - if(!param) return false; - GP28.write(*(int*)param); - return true; -} -bool p29_set(void* param) -{ - if(!param) return false; - GP29.write(*(int*)param); - return true; -} -bool p30_set(void* param) -{ - if(!param) return false; - GP30.write(*(int*)param); - return true; -} -bool p31_set(void* param) -{ - if(!param) return false; - GP31.write(*(int*)param); - return true; -} -bool p32_set(void* param) -{ - if(!param) return false; - GP32.write(*(int*)param); - return true; -} void debug_info() { @@ -277,61 +93,18 @@ #endif sprintf(mac_str, "%02X:%02X:%02X:%02X:%02X:%02X",mac_addr[0],mac_addr[1],mac_addr[2],mac_addr[3],mac_addr[4],mac_addr[5]); - //GPIO Set + // OLED init + gOled.begin(); + gOled.clearDisplay(); + + // PWM init + DC.period_ms(1); + DC.write(0); + + //GPIO set & init GP05.output(); GP05.write(1); - GP06.output(); - GP06.write(1); - GP07.output(); - GP07.write(1); - GP08.output(); - GP08.write(1); - GP09.output(); - GP09.write(1); - GP10.output(); - GP10.write(1); - GP11.output(); - GP11.write(1); - GP12.output(); - GP12.write(1); - GP13.output(); - GP13.write(1); - GP14.output(); - GP14.write(1); - GP15.output(); - GP15.write(1); - GP16.output(); - GP16.write(1); - GP17.output(); - GP17.write(1); - GP18.output(); - GP18.write(1); - GP19.output(); - GP19.write(1); - GP20.output(); - GP20.write(1); - GP21.output(); - GP21.write(1); - GP22.output(); - GP22.write(1); - GP23.output(); - GP23.write(1); - GP24.output(); - GP24.write(1); - GP25.output(); - GP25.write(1); - GP26.output(); - GP26.write(1); - GP27.output(); - GP27.write(1); - GP28.output(); - GP28.write(1); - GP29.output(); - GP29.write(1); - //LED Setbit - //LED_1.write(0); // LED On - //LED_2.write(1); // LED Off printf("START \r\n"); printf("sizeof(MbedJSONValue)=%d\r\n",sizeof(MbedJSONValue)); printf("sizeof(vector)=%d\r\n",sizeof(std::vector<string*>)); @@ -416,91 +189,21 @@ WIZwikiREST["Network"]["SN"].accessible = true; WIZwikiREST["Network"]["GW"] = gateway_addr; WIZwikiREST["Network"]["GW"].accessible = true; - - //LEDs - //WIZwikiREST["LED1"] = (LED_1.read() ? "Off" : "On"); - //WIZwikiREST["LED1"].accessible = true; - //WIZwikiREST["LED2"] = (LED_2.read() ? "Off" : "On"); - //WIZwikiREST["LED2"].accessible = true; + + // I2C OLED + WIZwikiREST["I2C"]["OLED"] = "none"; + WIZwikiREST["I2C"]["OLED"].accessible = true; + WIZwikiREST["I2C"]["OLED"].cb_action = oled_set; - // GPIOs - WIZwikiREST["GPIOs"]["all"].accessible = true; - WIZwikiREST["GPIOs"]["all"].cb_action = gpio_all; + // PWM DC + WIZwikiREST["PWM"]["DC"] = DC.read(); + WIZwikiREST["PWM"]["DC"].accessible = true; + WIZwikiREST["PWM"]["DC"].cb_action = pwm_set; + + // GPIO WIZwikiREST["GPIOs"]["P05"] = GP05.read(); WIZwikiREST["GPIOs"]["P05"].accessible = true; WIZwikiREST["GPIOs"]["P05"].cb_action = p5_set; - WIZwikiREST["GPIOs"]["P06"] = GP06.read(); - WIZwikiREST["GPIOs"]["P06"].accessible = true; - WIZwikiREST["GPIOs"]["P06"].cb_action = p6_set; - WIZwikiREST["GPIOs"]["P07"] = GP07.read(); - WIZwikiREST["GPIOs"]["P07"].accessible = true; - WIZwikiREST["GPIOs"]["P07"].cb_action = p7_set; - WIZwikiREST["GPIOs"]["P08"] = GP08.read(); - WIZwikiREST["GPIOs"]["P08"].accessible = true; - WIZwikiREST["GPIOs"]["P08"].cb_action = p8_set; - WIZwikiREST["GPIOs"]["P09"] = GP09.read(); - WIZwikiREST["GPIOs"]["P09"].accessible = true; - WIZwikiREST["GPIOs"]["P09"].cb_action = p9_set; - WIZwikiREST["GPIOs"]["P10"] = GP10.read(); - WIZwikiREST["GPIOs"]["P10"].accessible = true; - WIZwikiREST["GPIOs"]["P10"].cb_action = p10_set; - WIZwikiREST["GPIOs"]["P11"] = GP11.read(); - WIZwikiREST["GPIOs"]["P11"].accessible = true; - WIZwikiREST["GPIOs"]["P11"].cb_action = p11_set; - WIZwikiREST["GPIOs"]["P12"] = GP12.read(); - WIZwikiREST["GPIOs"]["P12"].accessible = true; - WIZwikiREST["GPIOs"]["P12"].cb_action = p12_set; - WIZwikiREST["GPIOs"]["P13"] = GP13.read(); - WIZwikiREST["GPIOs"]["P13"].accessible = true; - WIZwikiREST["GPIOs"]["P13"].cb_action = p13_set; - WIZwikiREST["GPIOs"]["P14"] = GP14.read(); - WIZwikiREST["GPIOs"]["P14"].accessible = true; - WIZwikiREST["GPIOs"]["P14"].cb_action = p14_set; - WIZwikiREST["GPIOs"]["P15"] = GP15.read(); - WIZwikiREST["GPIOs"]["P15"].accessible = true; - WIZwikiREST["GPIOs"]["P15"].cb_action = p15_set; - WIZwikiREST["GPIOs"]["P16"] = GP16.read(); - WIZwikiREST["GPIOs"]["P16"].accessible = true; - WIZwikiREST["GPIOs"]["P16"].cb_action = p16_set; - WIZwikiREST["GPIOs"]["P17"] = GP17.read(); - WIZwikiREST["GPIOs"]["P17"].accessible = true; - WIZwikiREST["GPIOs"]["P17"].cb_action = p17_set; - WIZwikiREST["GPIOs"]["P18"] = GP18.read(); - WIZwikiREST["GPIOs"]["P18"].accessible = true; - WIZwikiREST["GPIOs"]["P18"].cb_action = p18_set; - WIZwikiREST["GPIOs"]["P19"] = GP19.read(); - WIZwikiREST["GPIOs"]["P19"].accessible = true; - WIZwikiREST["GPIOs"]["P19"].cb_action = p19_set; - WIZwikiREST["GPIOs"]["P20"] = GP20.read(); - WIZwikiREST["GPIOs"]["P20"].accessible = true; - WIZwikiREST["GPIOs"]["P20"].cb_action = p20_set; - WIZwikiREST["GPIOs"]["P21"] = GP21.read(); - WIZwikiREST["GPIOs"]["P21"].accessible = true; - WIZwikiREST["GPIOs"]["P21"].cb_action = p21_set; - WIZwikiREST["GPIOs"]["P22"] = GP22.read(); - WIZwikiREST["GPIOs"]["P22"].accessible = true; - WIZwikiREST["GPIOs"]["P22"].cb_action = p22_set; - WIZwikiREST["GPIOs"]["P23"] = GP23.read(); - WIZwikiREST["GPIOs"]["P23"].accessible = true; - WIZwikiREST["GPIOs"]["P23"].cb_action = p23_set; - WIZwikiREST["GPIOs"]["P24"] = GP24.read(); - WIZwikiREST["GPIOs"]["P24"].accessible = true; - WIZwikiREST["GPIOs"]["P24"].cb_action = p24_set; - WIZwikiREST["GPIOs"]["P25"] = GP25.read(); - WIZwikiREST["GPIOs"]["P25"].accessible = true; - WIZwikiREST["GPIOs"]["P25"].cb_action = p25_set; - WIZwikiREST["GPIOs"]["P26"] = GP26.read(); - WIZwikiREST["GPIOs"]["P26"].accessible = true; - WIZwikiREST["GPIOs"]["P26"].cb_action = p26_set; - WIZwikiREST["GPIOs"]["P27"] = GP27.read(); - WIZwikiREST["GPIOs"]["P27"].accessible = true; - WIZwikiREST["GPIOs"]["P27"].cb_action = p27_set; - WIZwikiREST["GPIOs"]["P28"] = GP28.read(); - WIZwikiREST["GPIOs"]["P28"].accessible = true; - WIZwikiREST["GPIOs"]["P28"].cb_action = p28_set; - WIZwikiREST["GPIOs"]["P29"] = GP29.read(); - WIZwikiREST["GPIOs"]["P29"].accessible = true; - WIZwikiREST["GPIOs"]["P29"].cb_action = p29_set; #ifdef DEBUG debug_info();