bugfix only one event if pressed
This commit is contained in:
parent
d41197e1e7
commit
0812b89909
|
@ -73,11 +73,12 @@ EVENT_RESOURCE(res_event2,
|
||||||
* Use local resource state that is accessed by res_get_handler() and altered by res_event_handler() or PUT or POST.
|
* Use local resource state that is accessed by res_get_handler() and altered by res_event_handler() or PUT or POST.
|
||||||
*/
|
*/
|
||||||
static int32_t event_counter2 = 0;
|
static int32_t event_counter2 = 0;
|
||||||
|
extern uint8_t but2_status;
|
||||||
static void
|
static void
|
||||||
res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||||
{
|
{
|
||||||
int buttonstate = button_sensor.value(0);
|
// int buttonstate = but2_status;
|
||||||
|
int buttonstate = 1; // Bugfix Demohardware Button 2 is a switch on/off
|
||||||
|
|
||||||
unsigned int accept = -1;
|
unsigned int accept = -1;
|
||||||
REST.get_header_accept(request, &accept);
|
REST.get_header_accept(request, &accept);
|
||||||
|
|
|
@ -36,10 +36,10 @@ extern resource_t
|
||||||
res_server;
|
res_server;
|
||||||
|
|
||||||
uint8_t led_pin=4;
|
uint8_t led_pin=4;
|
||||||
uint8_t led_status;
|
uint8_t led_status=0;
|
||||||
|
|
||||||
uint8_t but2_pin=8;
|
uint8_t but2_pin=20;
|
||||||
uint8_t but2_status;
|
uint8_t but2_status=0;
|
||||||
|
|
||||||
// coap_server_post
|
// coap_server_post
|
||||||
#define REMOTE_PORT UIP_HTONS(COAP_DEFAULT_PORT)
|
#define REMOTE_PORT UIP_HTONS(COAP_DEFAULT_PORT)
|
||||||
|
@ -131,8 +131,9 @@ void setup (void)
|
||||||
pinMode(led_pin, OUTPUT);
|
pinMode(led_pin, OUTPUT);
|
||||||
digitalWrite(led_pin, HIGH);
|
digitalWrite(led_pin, HIGH);
|
||||||
led_status=0;
|
led_status=0;
|
||||||
// init button2
|
// init button2 with pullup on
|
||||||
pinMode(but2_pin, INPUT);
|
pinMode(but2_pin, INPUT);
|
||||||
|
digitalWrite(but2_pin, HIGH);
|
||||||
// init chainable led
|
// init chainable led
|
||||||
leds.init();
|
leds.init();
|
||||||
leds.setColorRGB(0,color_rgb [0], color_rgb [1], color_rgb [2]);
|
leds.setColorRGB(0,color_rgb [0], color_rgb [1], color_rgb [2]);
|
||||||
|
@ -147,7 +148,7 @@ void setup (void)
|
||||||
rest_activate_resource (&res_cputemp, "s/cputemp");
|
rest_activate_resource (&res_cputemp, "s/cputemp");
|
||||||
rest_activate_resource (&res_event1, "s/button1");
|
rest_activate_resource (&res_event1, "s/button1");
|
||||||
rest_activate_resource (&res_event2, "s/button2");
|
rest_activate_resource (&res_event2, "s/button2");
|
||||||
rest_activate_resource (&res_server_ip,"button/ip");
|
rest_activate_resource (&res_server_ip,"server/ip");
|
||||||
rest_activate_resource (&res_red, "led/R");
|
rest_activate_resource (&res_red, "led/R");
|
||||||
rest_activate_resource (&res_green, "led/G");
|
rest_activate_resource (&res_green, "led/G");
|
||||||
rest_activate_resource (&res_blue, "led/B");
|
rest_activate_resource (&res_blue, "led/B");
|
||||||
|
@ -186,6 +187,7 @@ int coap_server_post(void)
|
||||||
|
|
||||||
void button (void)
|
void button (void)
|
||||||
{
|
{
|
||||||
|
if(button_sensor.value(0)==1){
|
||||||
/* Call the event_handler for this application-specific event. */
|
/* Call the event_handler for this application-specific event. */
|
||||||
res_event1.trigger();
|
res_event1.trigger();
|
||||||
|
|
||||||
|
@ -194,16 +196,28 @@ void button (void)
|
||||||
|
|
||||||
/* Call the Coap Server */
|
/* Call the Coap Server */
|
||||||
//coap_server_post();
|
//coap_server_post();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop (void)
|
void loop (void)
|
||||||
{
|
{
|
||||||
if(digitalRead(but2_pin)==0)
|
static int but_io2=0;
|
||||||
{
|
|
||||||
// printf("0\n");
|
but_io2=digitalRead(but2_pin);
|
||||||
|
if(but_io2==0){
|
||||||
|
printf("0");
|
||||||
digitalWrite(led_pin, LOW);
|
digitalWrite(led_pin, LOW);
|
||||||
}else{
|
}else{
|
||||||
// printf("1\n");
|
printf("1");
|
||||||
digitalWrite(led_pin, HIGH);
|
digitalWrite(led_pin, HIGH);
|
||||||
}
|
}
|
||||||
|
if(but2_status != but_io2) {
|
||||||
|
printf("T");
|
||||||
|
/* Call the event_handler for this application-specific event. */
|
||||||
|
res_event2.trigger();
|
||||||
|
|
||||||
|
/* Also call the separate response example handler. */
|
||||||
|
res_separate2.resume();
|
||||||
|
but2_status = but_io2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue