This commit is contained in:
harald42 2013-04-15 10:28:03 +02:00 committed by harald
parent 25fb513164
commit 797c3da239
3 changed files with 51 additions and 12 deletions

View file

@ -144,6 +144,7 @@ extbutton_handler(void* request, void* response, uint8_t *buffer, uint16_t prefe
{ {
static char bname1[17]="button1"; static char bname1[17]="button1";
static char bname2[17]="button2"; static char bname2[17]="button2";
static char bname3[17]="button3";
int success = 1; int success = 1;
char temp[100]; char temp[100];
@ -156,12 +157,17 @@ extbutton_handler(void* request, void* response, uint8_t *buffer, uint16_t prefe
case METHOD_GET: case METHOD_GET:
// jSON Format // jSON Format
index += sprintf(temp + index,"{\n \"%s\" : ",bname1); index += sprintf(temp + index,"{\n \"%s\" : ",bname1);
if(is_button_ext1()) if(is_button_ext4())
index += sprintf(temp + index,"\"on\",\n"); index += sprintf(temp + index,"\"on\",\n");
else else
index += sprintf(temp + index,"\"off\",\n"); index += sprintf(temp + index,"\"off\",\n");
index += sprintf(temp + index," \"%s\" : ",bname2); index += sprintf(temp + index,"{\n \"%s\" : ",bname2);
if(is_button_ext2()) if(is_button_ext5())
index += sprintf(temp + index,"\"on\",\n");
else
index += sprintf(temp + index,"\"off\",\n");
index += sprintf(temp + index," \"%s\" : ",bname3);
if(is_button_ext6())
index += sprintf(temp + index,"\"on\"\n"); index += sprintf(temp + index,"\"on\"\n");
else else
index += sprintf(temp + index,"\"off\"\n"); index += sprintf(temp + index,"\"off\"\n");
@ -540,10 +546,12 @@ AUTOSTART_PROCESSES(&rest_server_example, &sensors_process);
PROCESS_THREAD(rest_server_example, ev, data) PROCESS_THREAD(rest_server_example, ev, data)
{ {
static struct etimer ds_periodic_timer; static struct etimer ds_periodic_timer;
static int ext1; static int ext4;
static int ext2; static int ext5;
ext1 = is_button_ext1(); static int ext6;
ext2 = is_button_ext2(); ext4 = is_button_ext4();
ext5 = is_button_ext5();
ext6 = is_button_ext6();
PROCESS_BEGIN(); PROCESS_BEGIN();

View file

@ -38,22 +38,41 @@
* *
*/ */
#include "key.h" #include <avr/interrupt.h>
#include "dev/led.h"
#include "pcintkey.h"
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
ISR(PCINT0_vect)
{
// if(BUTTON_CHECK_IRQ()) {
// if(timer_expired(&debouncetimer)) {
led1_on();
// timer_set(&debouncetimer, CLOCK_SECOND / 4);
// sensors_changed(&button_sensor);
led1_off();
// }
// }
}
/** /**
* \brief This will intialize the KEY for button readings. * \brief This will intialize the KEY for button readings.
*/ */
void void
key_init(void) key_init(void)
{ {
// Pairing Button
DDRB |= (0<<DDB4); // Set pin as input
PORTB |= (1<<PORTB4); // Set port PORTE bint 5 with pullup resistor
// ext1 // ext1
DDRB |= (0<<DDB5); // Set pin as input DDRB |= (0<<DDB5); // Set pin as input
PORTB |= (1<<PORTB5); // Set port PORTE bint 5 with pullup resistor PORTB |= (1<<PORTB5); // Set port PORTE bint 5 with pullup resistor
// ext2 // ext2
DDRB |= (0<<DDB6); // Set pin as input DDRB |= (0<<DDB6); // Set pin as input
PORTB |= (1<<PORTB6); // Set port PORTE bint 5 with pullup resistor PORTB |= (1<<PORTB6); // Set port PORTE bint 5 with pullup resistor
// Interrupt
PCICR |= _BV(PCIE0);
PCMSK0 |= _BV(PCINT4) | _BV(PCINT5) | _BV(PCINT6);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -65,7 +84,18 @@ key_init(void)
* \retval False if button is not pressed * \retval False if button is not pressed
*/ */
uint8_t uint8_t
is_button_ext1(void) is_button_ext4(void)
{
/* Return true if button has been pressed. */
if ( PINB & (1<<PINB4) ) {
return 0;
}
else{
return 1;
}
}
uint8_t
is_button_ext5(void)
{ {
/* Return true if button has been pressed. */ /* Return true if button has been pressed. */
if ( PINB & (1<<PINB5) ) { if ( PINB & (1<<PINB5) ) {
@ -76,7 +106,7 @@ is_button_ext1(void)
} }
} }
uint8_t uint8_t
is_button_ext2(void) is_button_ext6(void)
{ {
/* Return true if button has been pressed. */ /* Return true if button has been pressed. */
if ( PINB & (1<<PINB6) ) { if ( PINB & (1<<PINB6) ) {

View file

@ -45,7 +45,8 @@
#include <avr/io.h> #include <avr/io.h>
void key_init(void); void key_init(void);
uint8_t is_button_ext1(void); uint8_t is_button_ext4(void);
uint8_t is_button_ext2(void); uint8_t is_button_ext5(void);
uint8_t is_button_ext6(void);
#endif /* __KEY_H__ */ #endif /* __KEY_H__ */