diff --git a/examples/osd/light-actor/Makefile b/examples/osd/light-actor/Makefile index dbd2c1410..9f5e50f5a 100644 --- a/examples/osd/light-actor/Makefile +++ b/examples/osd/light-actor/Makefile @@ -12,6 +12,8 @@ PROJECT_SOURCEFILES += static-routing.c endif endif endif +# pcintkey +PROJECT_SOURCEFILES += pcintkey.c # variable for root Makefile.include WITH_UIP6=1 diff --git a/examples/osd/light-actor/er-example-server.c b/examples/osd/light-actor/er-example-server.c index 60b723ae5..689d34a20 100644 --- a/examples/osd/light-actor/er-example-server.c +++ b/examples/osd/light-actor/er-example-server.c @@ -59,6 +59,7 @@ #endif #include "erbium.h" +#include "pcintkey.h" #include "dev/led.h" #if defined (PLATFORM_HAS_BUTTON) @@ -135,7 +136,61 @@ info_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_ } #endif +// pcintkey_ext +/*A simple actuator example. read the key button status*/ +RESOURCE(extbutton, METHOD_GET | METHOD_PUT , "sensors/extbutton", "title=\"ext.Button\";rt=\"Text\""); +void +extbutton_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) +{ + static char bname1[17]="button1"; + static char bname2[17]="button2"; + int success = 1; + char temp[100]; + int index = 0; + int length = 0; /* |<-------->| */ + const char *name = NULL; + size_t len = 0; + + switch(REST.get_method_type(request)){ + case METHOD_GET: + // jSON Format + index += sprintf(temp + index,"{\n \"%s\" : ",bname1); + if(is_button_ext1()) + index += sprintf(temp + index,"\"on\",\n"); + else + index += sprintf(temp + index,"\"off\",\n"); + index += sprintf(temp + index," \"%s\" : ",bname2); + if(is_button_ext2()) + index += sprintf(temp + index,"\"on\"\n"); + else + index += sprintf(temp + index,"\"off\"\n"); + index += sprintf(temp + index,"}\n"); + + length = strlen(temp); + memcpy(buffer, temp,length ); + + REST.set_header_content_type(response, REST.type.APPLICATION_JSON); + REST.set_response_payload(response, buffer, length); + + break; + case METHOD_PUT: + + if (success && (len=REST.get_post_variable(request, "name", &name))) { + PRINTF("name %s\n", name); + memcpy(bname1, name,len); + bname1[len]=0; + } else { + success = 0; + } + break; + default: + success = 0; + } + if (!success) { + REST.set_response_status(response, REST.status.BAD_REQUEST); + } +} /*A simple actuator example, post variable mode, relay is activated or deactivated*/ RESOURCE(led1, METHOD_GET | METHOD_PUT , "actuators/led1", "title=\"Led1\";rt=\"led\""); void @@ -510,6 +565,7 @@ PROCESS_THREAD(rest_server_example, ev, data) /* Activate the application-specific resources. */ rest_activate_resource(&resource_led1); + rest_activate_resource(&resource_extbutton); #if REST_RES_INFO rest_activate_resource(&resource_info); #endif diff --git a/examples/osd/light-actor/pcintkey.c b/examples/osd/light-actor/pcintkey.c new file mode 100644 index 000000000..4f147ab8f --- /dev/null +++ b/examples/osd/light-actor/pcintkey.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2010 harald pichler + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/** + * \file + * + * \brief + * This file provides Raven KEY support. + * + * \author + * Harald Pichler harald@the-develop.net + * + */ + +#include "key.h" + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will intialize the KEY for button readings. +*/ +void +key_init(void) +{ + // ext1 + DDRB |= (0< +#include + +void key_init(void); +uint8_t is_button_ext1(void); +uint8_t is_button_ext2(void); + +#endif /* __KEY_H__ */