/* * This is a threaded IRQ handler so can access I2C/SPI. Since all * interrupts are clear on read the IRQ line will be reasserted and * the physical IRQ will be handled again if another interrupt is * asserted while we run - in the normal course of events this is a * rare occurrence so we save I2C/SPI reads. We're also assuming that * it's rare to get lots of interrupts firing simultaneously so try to * minimise I/O. */ static irqreturn_t sensor_interrupt(int irq, void *dev_id) { struct sensor_private_data *sensor = (struct sensor_private_data *)dev_id; //use threaded IRQ if (sensor_get_data(sensor->client) < 0) DBG(KERN_ERR "%s: Get data failed\n",__func__); msleep(sensor->pdata->poll_delay_ms); //if((sensor->ops->trig == IRQF_TRIGGER_LOW) || (sensor->ops->trig == IRQF_TRIGGER_HIGH)) //disable_irq_nosync(irq); //schedule_delayed_work(&sensor->delaywork, msecs_to_jiffies(sensor->pdata->poll_delay_ms)); DBG("%s:irq=%d\n",__func__,irq); return IRQ_HANDLED; }
int sensor_light_status() { int value = 0; struct sensor_private_data *sensor = NULL; struct i2c_client *client = NULL; sensor = g_sensor[SENSOR_TYPE_LIGHT]; if (sensor == NULL) return 0; client = sensor->client; value= sensor_get_data(client); if(value < FLASH_LIGHT_SENSOR_THRESHOLD) return 1; else return 0; }
static void sensor_delaywork_func(struct work_struct *work) { struct delayed_work *delaywork = container_of(work, struct delayed_work, work); struct sensor_private_data *sensor = container_of(delaywork, struct sensor_private_data, delaywork); struct i2c_client *client = sensor->client; mutex_lock(&sensor->sensor_mutex); if (sensor_get_data(client) < 0) DBG(KERN_ERR "%s: Get data failed\n",__func__); if(!sensor->pdata->irq_enable)//restart work while polling schedule_delayed_work(&sensor->delaywork, msecs_to_jiffies(sensor->pdata->poll_delay_ms)); //else //{ //if((sensor->ops->trig == IRQF_TRIGGER_LOW) || (sensor->ops->trig == IRQF_TRIGGER_HIGH)) //enable_irq(sensor->client->irq); //} mutex_unlock(&sensor->sensor_mutex); DBG("%s:%s\n",__func__,sensor->i2c_id->name); }
bool mqtt_process(MQTT* mqtt) { if(mqtt->length < sizeof(MQTT_VHeader)) { return false; } MQTT_VHeader* vheader= (MQTT_VHeader*)mqtt->body; ssize_t len = mqtt->length - (sizeof(MQTT_VHeader) + vheader->topic_length); char buf[256] = {0,}; if(len < 0 || len > sizeof(buf)) { return false; } memcpy(buf, (char*)vheader->topic + vheader->topic_length, len); json_object* jso = json_tokener_parse(buf); if(jso) { Sensor* sensor = NULL; char name[64] = {0, }; json_object_object_foreach(jso, key, child_object) { if(!strcmp(key, "name_of_sensor")) { strcpy(name, json_object_to_json_string(child_object)); printf("name %s\n", name); remove_blank(name); sensor = sensor_database_get(name); } #ifdef TIMER_LOG if(!strcmp(key, "id_of_sensor")) { char id[64] = {0, }; strcpy(id, json_object_to_json_string(child_object)); remove_blank(id); extern void timer_check(char* id); timer_check(id); } #endif } if(sensor) { json_object_object_foreach(jso, key1, child_object1) { char name[64] = {0, }; strcpy(name, key1); remove_blank(name); Data* data = sensor_get_data(sensor, name); if(data) { char value[64] = {0, }; strcpy(value, json_object_to_json_string(child_object1)); remove_blank(value); char* ptr; int64_t val = strtol(value, &ptr, 10); #ifdef DEBUG_MSG printf("\t%s: %ld\n", name, val); #endif data_push_value(data, val); } } } #ifdef DEBUG_MSG printf("\n"); #endif json_object_put(jso); //free }