From 1f586c7735a1ee5b31dda659eea0c11b900caf84 Mon Sep 17 00:00:00 2001 From: harald Date: Tue, 18 Feb 2014 09:32:01 +0100 Subject: [PATCH] define new tria pins, configurable type ligt or shutter or plug --- .../light-shutter-control/er-example-server.c | 88 ++++++++++++++++++- .../osd/light-shutter-control/project-conf.h | 5 ++ .../osd/light-shutter-control/statusled.c | 8 +- platform/osd-merkur/dev/optriac.c | 18 ++-- 4 files changed, 107 insertions(+), 12 deletions(-) diff --git a/examples/osd/light-shutter-control/er-example-server.c b/examples/osd/light-shutter-control/er-example-server.c index 431e54ceb..aaca90171 100644 --- a/examples/osd/light-shutter-control/er-example-server.c +++ b/examples/osd/light-shutter-control/er-example-server.c @@ -123,10 +123,17 @@ info_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_ /* Some data that has the length up to REST_MAX_CHUNK_SIZE. For more, see the chunk resource. */ // jSON Format - index += sprintf(message + index,"{\n \"Version\" : \"V1.0pre2\",\n"); + index += sprintf(message + index,"{\n \"Version\" : \"V1.0pre3\",\n"); +#ifdef OSDPLUG + index += sprintf(message + index," \"name\" : \"PLUG\"\n"); +#endif +#ifdef OSDLIGHT index += sprintf(message + index," \"name\" : \"light-actor\"\n"); +#endif +#ifdef OSDSHUTTER + index += sprintf(message + index," \"name\" : \"shutter-actor\"\n"); +#endif index += sprintf(message + index,"}\n"); - length = strlen(message); memcpy(buffer, message,length ); @@ -262,9 +269,83 @@ led1_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_ REST.set_response_status(response, REST.status.BAD_REQUEST); } } +/******************************************************************************/ +#if (defined (PLATFORM_HAS_OPTRIAC) && defined (OSDPLUG)) +/******************************************************************************/ +#if REST_RES_OPTRIAC +/*A simple actuator example*/ +RESOURCE(optriac, METHOD_GET | METHOD_POST | METHOD_PUT , "actuators/optriac", "title=\"TRIAC, POST/PUT mode=on|off\";rt=\"Control\""); + +void +optriac_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) +{ + const char *mode = NULL; + static char namea[17]="Triac-a"; + static char nameb[17]="Triac-b"; + + char temp[100]; + int index = 0; + size_t len = 0; + int success = 1; + + switch(REST.get_method_type(request)){ + case METHOD_GET: + // jSON Format + index += sprintf(temp + index,"{\n \"%s\" : ",namea); + if(optriac_sensor.value(OPTRIAC_SENSOR_A) == 0) + index += sprintf(temp + index,"\"off\",\n"); + if(optriac_sensor.value(OPTRIAC_SENSOR_A) == 1) + index += sprintf(temp + index,"\"on\",\n"); + index += sprintf(temp + index," \"%s\" : ",nameb); + if(optriac_sensor.value(OPTRIAC_SENSOR_B) == 0) + index += sprintf(temp + index,"\"off\"\n"); + if(optriac_sensor.value(OPTRIAC_SENSOR_B) == 1) + index += sprintf(temp + index,"\"on\"\n"); + index += sprintf(temp + index,"}\n"); + + len = strlen(temp); + memcpy(buffer, temp,len ); + + REST.set_header_content_type(response, REST.type.APPLICATION_JSON); + REST.set_response_payload(response, buffer, len); + break; + + case METHOD_POST: + success = 0; + break; + case METHOD_PUT: + if (success && (len=REST.get_post_variable(request, "mode", &mode))) { + PRINTF("mode %s\n", mode); + if (strncmp(mode, "on", len)==0) { + optriac_sensor.configure(OPTRIAC_SENSOR_A,1); + optriac_sensor.configure(OPTRIAC_SENSOR_B,1); + statusled_on(); +// led1_on(); // Debug + } else if (strncmp(mode, "off", len)==0) { + optriac_sensor.configure(OPTRIAC_SENSOR_A,0); + optriac_sensor.configure(OPTRIAC_SENSOR_B,0); + statusled_off(); +// led1_off(); // Debug + } else { + success = 0; + } + } else { + success = 0; + } + break; + default: + success = 0; + } + if (!success) { + REST.set_response_status(response, REST.status.BAD_REQUEST); + } +} +#endif +/******************************************************************************/ +#endif /* PLATFORM_HAS_OPTRIAC */ /******************************************************************************/ -#if defined (PLATFORM_HAS_OPTRIAC) +#if (defined (PLATFORM_HAS_OPTRIAC) && defined (OSDLIGHT)) /******************************************************************************/ #if REST_RES_OPTRIAC /*A simple actuator example*/ @@ -494,6 +575,7 @@ void hw_init() { led1_off(); + statusledinit(); key_init(); } diff --git a/examples/osd/light-shutter-control/project-conf.h b/examples/osd/light-shutter-control/project-conf.h index f6305b633..d4babccb5 100644 --- a/examples/osd/light-shutter-control/project-conf.h +++ b/examples/osd/light-shutter-control/project-conf.h @@ -32,6 +32,11 @@ #ifndef PROJECT_RPL_WEB_CONF_H_ #define PROJECT_RPL_WEB_CONF_H_ +#define OSDPLUG +//#define OSDLIGHT +//#define OSDSHUTTER + + //#define PLATFORM_HAS_LEDS 1 //#define PLATFORM_HAS_BUTTON 1 #define PLATFORM_HAS_OPTRIAC 1 diff --git a/examples/osd/light-shutter-control/statusled.c b/examples/osd/light-shutter-control/statusled.c index 2c3f782a3..a5a02005d 100644 --- a/examples/osd/light-shutter-control/statusled.c +++ b/examples/osd/light-shutter-control/statusled.c @@ -51,7 +51,13 @@ void statusledinit(void) { - /* todo disable jtag interface */ + uint8_t temp; + + /* Get MCUCR */ + temp = MCUCR; + /* disable jtag */ + MCUCR = temp|(1<