timer4 servo pwm
This commit is contained in:
parent
54114b0943
commit
277f63d76a
4 changed files with 100 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011, Matthias Kovatsch and other contributors.
|
* Copyright (C) 2011-2013, Matthias Kovatsch and other contributors.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -46,7 +46,8 @@
|
||||||
|
|
||||||
/* Define which resources to include to meet memory constraints. */
|
/* Define which resources to include to meet memory constraints. */
|
||||||
#define REST_RES_INFO 1
|
#define REST_RES_INFO 1
|
||||||
#define REST_RES_SERVO 1
|
#define REST_RES_SERVO 0
|
||||||
|
#define REST_RES_T4_SERVO 1
|
||||||
#define REST_RES_TEMPERATURE 0
|
#define REST_RES_TEMPERATURE 0
|
||||||
#define REST_RES_EVENT 0
|
#define REST_RES_EVENT 0
|
||||||
#define REST_RES_LEDS 0
|
#define REST_RES_LEDS 0
|
||||||
|
@ -70,6 +71,9 @@
|
||||||
#if defined (PLATFORM_HAS_SERVO)
|
#if defined (PLATFORM_HAS_SERVO)
|
||||||
#include "dev/servo-sensor.h"
|
#include "dev/servo-sensor.h"
|
||||||
#endif
|
#endif
|
||||||
|
#if defined (PLATFORM_HAS_T4_SERVO)
|
||||||
|
#include "dev/t4-servo-sensor.h"
|
||||||
|
#endif
|
||||||
#if defined (PLATFORM_HAS_TEMPERATURE)
|
#if defined (PLATFORM_HAS_TEMPERATURE)
|
||||||
#include "dev/temperature-sensor.h"
|
#include "dev/temperature-sensor.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -134,6 +138,7 @@ info_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined (PLATFORM_HAS_SERVO)
|
||||||
/*A simple actuator example. read the servo status*/
|
/*A simple actuator example. read the servo status*/
|
||||||
RESOURCE(servo, METHOD_GET | METHOD_PUT , "actuators/servo", "title=\"Servo\";rt=\"servo\"");
|
RESOURCE(servo, METHOD_GET | METHOD_PUT , "actuators/servo", "title=\"Servo\";rt=\"servo\"");
|
||||||
void
|
void
|
||||||
|
@ -186,7 +191,86 @@ servo_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred
|
||||||
REST.set_response_status(response, REST.status.BAD_REQUEST);
|
REST.set_response_status(response, REST.status.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined (PLATFORM_HAS_T4_SERVO)
|
||||||
|
RESOURCE(t4_servo, METHOD_GET | METHOD_PUT , "actuators/t4_servo", "title=\"Timer4Servo\";rt=\"t4_servo\"");
|
||||||
|
void
|
||||||
|
t4_servo_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||||
|
{
|
||||||
|
int success = 1;
|
||||||
|
|
||||||
|
char temp[100];
|
||||||
|
int index = 0;
|
||||||
|
int length = 0; /* |<-------->| */
|
||||||
|
const char *value = NULL;
|
||||||
|
size_t len = 0;
|
||||||
|
|
||||||
|
int red = t4_servo_sensor.value(0);
|
||||||
|
int green = t4_servo_sensor.value(1);
|
||||||
|
int blue = t4_servo_sensor.value(2);
|
||||||
|
int white = t4_servo_sensor.value(3);
|
||||||
|
|
||||||
|
switch(REST.get_method_type(request)){
|
||||||
|
case METHOD_GET:
|
||||||
|
// jSON Format
|
||||||
|
index += sprintf(temp + index,"{\n \"red\" : \"%d\",", red);
|
||||||
|
index += sprintf(temp + index, "\n \"green\" : \"%d\",", green);
|
||||||
|
index += sprintf(temp + index, "\n \"blue\" : \"%d\",", blue);
|
||||||
|
index += sprintf(temp + index, "\n \"white\" : \"%d\"", white);
|
||||||
|
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_POST:
|
||||||
|
success = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case METHOD_PUT:
|
||||||
|
// Note that we have to set all at once:
|
||||||
|
// red=255&green=255&blue=255&white=255
|
||||||
|
// otherwise we get "bad request"
|
||||||
|
if (success && (len=REST.get_post_variable(request, "red", &value)))
|
||||||
|
{
|
||||||
|
t4_servo_sensor.configure(0,atoi(value));
|
||||||
|
} else {
|
||||||
|
success = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (success && (len=REST.get_post_variable(request, "green", &value))) {
|
||||||
|
t4_servo_sensor.configure(1,atoi(value));
|
||||||
|
} else {
|
||||||
|
success = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (success && (len=REST.get_post_variable(request, "blue", &value))) {
|
||||||
|
t4_servo_sensor.configure(2,atoi(value));
|
||||||
|
} else {
|
||||||
|
success = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (success && (len=REST.get_post_variable(request, "white", &value))) {
|
||||||
|
t4_servo_sensor.configure(3,atoi(value));
|
||||||
|
} else {
|
||||||
|
success = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
success = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
|
REST.set_response_status(response, REST.status.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*A simple actuator example, post variable mode, relay is activated or deactivated*/
|
/*A simple actuator example, post variable mode, relay is activated or deactivated*/
|
||||||
RESOURCE(led1, METHOD_GET | METHOD_PUT , "aktors/led1", "title=\"Led1\";rt=\"led\"");
|
RESOURCE(led1, METHOD_GET | METHOD_PUT , "aktors/led1", "title=\"Led1\";rt=\"led\"");
|
||||||
|
@ -455,6 +539,10 @@ PROCESS_THREAD(rest_server_example, ev, data)
|
||||||
SENSORS_ACTIVATE(servo_sensor);
|
SENSORS_ACTIVATE(servo_sensor);
|
||||||
rest_activate_resource(&resource_servo);
|
rest_activate_resource(&resource_servo);
|
||||||
#endif
|
#endif
|
||||||
|
#if defined (PLATFORM_HAS_T4_SERVO) && REST_RES_T4_SERVO
|
||||||
|
SENSORS_ACTIVATE(t4_servo_sensor);
|
||||||
|
rest_activate_resource(&resource_t4_servo);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Define application-specific events here. */
|
/* Define application-specific events here. */
|
||||||
while(1) {
|
while(1) {
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
sudo avrdude -pm128rfa1 -c arduino -P/dev/ttyUSB0 -b57600 -e -U flash:w:er-example-server.osd-merkur.hex:a -U eeprom:w:er-example-server.osd-merkur.eep:a
|
avrdude -pm128rfa1 -c arduino -P/dev/ttyUSB0 -b57600 -e -U flash:w:er-example-server.osd-merkur.hex:a -U eeprom:w:er-example-server.osd-merkur.eep:a
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
* Copyright (C) 2010-2013, Swedish Institute of Computer Science.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -34,12 +34,17 @@
|
||||||
|
|
||||||
//#define PLATFORM_HAS_LEDS 1
|
//#define PLATFORM_HAS_LEDS 1
|
||||||
//#define PLATFORM_HAS_BUTTON 1
|
//#define PLATFORM_HAS_BUTTON 1
|
||||||
#define PLATFORM_HAS_SERVO 1
|
//#define PLATFORM_HAS_SERVO 1
|
||||||
|
#define PLATFORM_HAS_T4_SERVO 1
|
||||||
//#define PLATFORM_HAS_TEMPERATURE 1
|
//#define PLATFORM_HAS_TEMPERATURE 1
|
||||||
#define PLATFORM_HAS_BATTERY 1
|
#define PLATFORM_HAS_BATTERY 1
|
||||||
|
|
||||||
#define SICSLOWPAN_CONF_FRAG 1
|
#define SICSLOWPAN_CONF_FRAG 1
|
||||||
|
|
||||||
|
/* Dont allow MCU sleeping between channel checks */
|
||||||
|
#undef RDC_CONF_MCU_SLEEP
|
||||||
|
#define RDC_CONF_MCU_SLEEP 0
|
||||||
|
|
||||||
/* Disabling RDC for demo purposes. Core updates often require more memory. */
|
/* Disabling RDC for demo purposes. Core updates often require more memory. */
|
||||||
/* For projects, optimize memory and enable RDC again. */
|
/* For projects, optimize memory and enable RDC again. */
|
||||||
//#undef NETSTACK_CONF_RDC
|
//#undef NETSTACK_CONF_RDC
|
||||||
|
|
|
@ -20,6 +20,8 @@ CONTIKI_TARGET_SOURCEFILES += optriac.c optriac-sensor.c
|
||||||
CONTIKIAVR=$(CONTIKI)/cpu/avr
|
CONTIKIAVR=$(CONTIKI)/cpu/avr
|
||||||
#Needed for SERVO
|
#Needed for SERVO
|
||||||
CONTIKI_TARGET_SOURCEFILES += servo.c servo-sensor.c
|
CONTIKI_TARGET_SOURCEFILES += servo.c servo-sensor.c
|
||||||
|
#Needed for Timer4 Servo
|
||||||
|
CONTIKI_TARGET_SOURCEFILES += t4-servo.c t4-servo-sensor.c
|
||||||
|
|
||||||
CONTIKIBOARD=.
|
CONTIKIBOARD=.
|
||||||
BOOTLOADER_START = 0x1F000
|
BOOTLOADER_START = 0x1F000
|
||||||
|
|
Loading…
Reference in a new issue