|  |  |  | 
|---|
|  |  |  | #include <getopt.h> | 
|---|
|  |  |  | #include <libgen.h> | 
|---|
|  |  |  | #include <string.h> | 
|---|
|  |  |  | #include <math.h> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #include <cjson/cJSON.h> | 
|---|
|  |  |  | #include <mosquitto.h> | 
|---|
|  |  |  | 
|---|
|  |  |  | int                debug = 0; | 
|---|
|  |  |  | int                opt; | 
|---|
|  |  |  | char              *progname=NULL; | 
|---|
|  |  |  | double             lux = 0.0; | 
|---|
|  |  |  | float              lux = 0.0; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | struct option long_options[] = { | 
|---|
|  |  |  | {"conf", required_argument, NULL, 'c'}, | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | log_nrml("Start infrared monitor thread working...\n"); | 
|---|
|  |  |  | while( ! g_signal.stop ) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | { | 
|---|
|  |  |  | lux = tsl2561_get_lux(); | 
|---|
|  |  |  | if( lux > hal_ctx->lux_threshold ) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | log_nrml("Lux[%.3f] > Treshold[%.3f], don't need auto light.\n", lux, hal_ctx->lux_threshold); | 
|---|
|  |  |  | sleep(30); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | log_nrml("start infrared monitor detect...\n"); | 
|---|
|  |  |  | if( infrared_detect() ) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | log_nrml("Someone incoming detected by infrared\n"); | 
|---|
|  |  |  | turn_light(LIGHT_HALLWAY, ON); | 
|---|
|  |  |  | alarm(hal_ctx->light_intval); | 
|---|
|  |  |  | if( lux < hal_ctx->lux_threshold ) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | log_nrml("Lux[%.3f] < Treshold[%.3f], auto light on now..\n", lux, hal_ctx->lux_threshold); | 
|---|
|  |  |  | turn_light(LIGHT_HALLWAY, ON); | 
|---|
|  |  |  | alarm(hal_ctx->light_intval); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | else if( strcasestr(value, "off") ) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | turn_light(LIGHT_LVROOM_RIGHT, OFF); | 
|---|
|  |  |  | log_nrml("Turn on livingroom right light\n"); | 
|---|
|  |  |  | log_nrml("Turn off livingroom right light\n"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|