summaryrefslogtreecommitdiff
path: root/src/controller.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/controller.c')
-rwxr-xr-xsrc/controller.c61
1 files changed, 14 insertions, 47 deletions
diff --git a/src/controller.c b/src/controller.c
index bbb2110..83d2f25 100755
--- a/src/controller.c
+++ b/src/controller.c
@@ -22,7 +22,7 @@
#include <Ecore.h>
#include "log.h"
-#include "resource/resource_infrared_motion_sensor.h"
+#include "resource/resource_infrared_motion.h"
#include "resource/resource_led.h"
// Timer duration
@@ -34,10 +34,6 @@
// LED sensor information
#define SENSOR_LED_GPIO_NUMBER (24)
-typedef struct app_data_s {
- Ecore_Timer *getter_timer;
-} app_data;
-
static int _change_led_state(int state) {
int ret = 0;
@@ -52,31 +48,17 @@ static int _change_led_state(int state) {
return 0;
}
-static Eina_Bool _get_motion_set_led()
+static void motion_interrupted_cb(uint32_t motion_value, void *user_data)
{
- int ret = 0;
- uint32_t value = 0;
-
- if (!ad) {
- _E("failed to get app_data");
- return ECORE_CALLBACK_CANCEL;
- }
-
- // Get value from motion sensor
- ret = resource_read_infrared_motion_sensor(SENSOR_MOTION_GPIO_NUMBER, &value);
- if (ret != 0) {
- _E("cannot read data from the infrared motion sensor");
- return ECORE_CALLBACK_CANCEL;
- }
-
- _D("Detected motion value is: %u", value);
+ _D("Detected motion value is: %u", motion_value);
// Set LED light with value
- _change_led_state(value);
+ _change_led_state(motion_value);
- return ECORE_CALLBACK_RENEW;
+ return;
}
+
static bool service_app_create(void *user_data)
{
return true;
@@ -84,52 +66,37 @@ static bool service_app_create(void *user_data)
static void service_app_control(app_control_h app_control, void *user_data)
{
- app_data *ad = user_data;
-
- // Delete old timer if there is one
- if (ad->getter_timer)
- ecore_timer_del(ad->getter_timer);
+ int ret = 0;
- // Create a timer to call the given function in given period of time
- ad->getter_timer = ecore_timer_add(TIMER_GATHER_INTERVAL, _get_motion_set_led, ad);
- if (!ad->getter_timer) {
- _E("Failed to add getter timer");
+ // Set an interrupted user callback to be invoked when interrupt is triggered on motion sensor
+ ret = resource_set_interrupted_cb_infrared_motion(SENSOR_MOTION_GPIO_NUMBER, motion_interrupted_cb, NULL);
+ if (ret != 0) {
+ _E("cannot set interrupted callback for motion sensor");
return;
}
}
static void service_app_terminate(void *user_data)
{
- app_data *ad = user_data;
-
- // Delete timer
- if (ad->getter_timer)
- ecore_timer_del(ad->getter_timer);
+ resource_unset_interrupted_cb_infrared_motion(SENSOR_MOTION_GPIO_NUMBER);
// Turn off LED light with __set_led()
_change_led_state(0);
// Close Motion and LED resources
- resource_close_infrared_motion_sensor();
+ resource_close_infrared_motion();
resource_close_led();
- // Free app data
- free(ad);
-
FN_END;
}
int main(int argc, char *argv[])
{
- app_data *ad = NULL;
service_app_lifecycle_callback_s event_callback;
- ad = calloc(1, sizeof(app_data));
- retv_if(!ad, -1);
-
event_callback.create = service_app_create;
event_callback.terminate = service_app_terminate;
event_callback.app_control = service_app_control;
- return service_app_main(argc, argv, &event_callback, ad);
+ return service_app_main(argc, argv, &event_callback, NULL);
}