diff options
-rw-r--r-- | .project | 2 | ||||
-rw-r--r-- | .tproject | 2 | ||||
-rw-r--r-- | shared/res/icon.png (renamed from shared/res/motion.png) | bin | 57662 -> 57662 bytes | |||
-rwxr-xr-x | src/controller.c | 20 | ||||
-rw-r--r-- | tizen-manifest.xml | 4 |
5 files changed, 18 insertions, 10 deletions
@@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <projectDescription> - <name>smart-light</name> + <name>smart-light-basic</name> <comment></comment> <projects> </projects> @@ -2,7 +2,7 @@ <tproject xmlns="http://www.tizen.org/tproject"> <platforms> <platform> - <name>iot-headed-5.0</name> + <name>iot-headless-5.0</name> </platform> </platforms> <package> diff --git a/shared/res/motion.png b/shared/res/icon.png Binary files differindex 9765b1b..9765b1b 100644 --- a/shared/res/motion.png +++ b/shared/res/icon.png diff --git a/src/controller.c b/src/controller.c index ba706bf..bbb2110 100755 --- a/src/controller.c +++ b/src/controller.c @@ -38,9 +38,10 @@ typedef struct app_data_s { Ecore_Timer *getter_timer; } app_data; -static int _set_led_data(app_data *ad, int state) { +static int _change_led_state(int state) { int ret = 0; + // Write state to LED light ret = resource_write_led(SENSOR_LED_GPIO_NUMBER, state); if (ret != 0) { _E("cannot write led data"); @@ -51,17 +52,17 @@ static int _set_led_data(app_data *ad, int state) { return 0; } -static Eina_Bool _get_motion_sensor_data(void *user_data) +static Eina_Bool _get_motion_set_led() { int ret = 0; uint32_t value = 0; - app_data *ad = user_data; 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"); @@ -70,7 +71,8 @@ static Eina_Bool _get_motion_sensor_data(void *user_data) _D("Detected motion value is: %u", value); - _set_led_data(ad, value); + // Set LED light with value + _change_led_state(value); return ECORE_CALLBACK_RENEW; } @@ -84,10 +86,12 @@ 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); - ad->getter_timer = ecore_timer_add(TIMER_GATHER_INTERVAL, _get_motion_sensor_data, ad); + // 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"); return; @@ -98,8 +102,12 @@ 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); + // Turn off LED light with __set_led() - _set_led_data(ad, 0); + _change_led_state(0); // Close Motion and LED resources resource_close_infrared_motion_sensor(); diff --git a/tizen-manifest.xml b/tizen-manifest.xml index 83d5397..26e3a1e 100644 --- a/tizen-manifest.xml +++ b/tizen-manifest.xml @@ -1,9 +1,9 @@ <?xml version="1.0" encoding="UTF-8" standalone="no"?> <manifest xmlns="http://tizen.org/ns/packages" api-version="5.0" package="org.example.smart-light" version="1.0.0"> - <profile name="iot-headed"/> + <profile name="iot-headless"/> <service-application appid="org.example.smart-light" exec="smart-light" multiple="false" nodisplay="true" on-boot="true" taskmanage="false" type="capp"> <label>smart-light</label> - <icon>smart-light.png</icon> + <icon>icon.png</icon> <metadata key="http://tizen.org/iot/metadata/master" value="shared/res/master.json"/> <metadata key="http://tizen.org/iot/metadata/resource" value="shared/res/resource.json"/> <background-category value="background-network"/> |