int cgiMain() { int sensor_num,sensor_idx; int i,j,k; char name[81]; light_sensor *p_sensor ; cgiFormInteger("sensor_num", &sensor_num, 0); if(sensor_num > 100) sensor_num = 100; cgiWriteEnvironment("/CHANGE/THIS/PATH/capcgi.dat"); cgiHeaderContentType("text/html"); OutHead(); OutBodyStart(); if(0 == check_password()) return 0; if(0 == sensor_num) { fprintf(cgiOut, "<p>数据出错,退出!!</p>\n"); OutBodyEnd(); return 0; } else { pwsw_h.sensor_num= sensor_num; for(i=0;i<sensor_num;i++) { p_sensor = &pwsw_h.sensor[i]; p_sensor->lux = get_lux(i+1); p_sensor->voltage = get_voltage(i+1); } } save_to_xml_file(); fprintf(cgiOut, "<p>保存成功,请返回!</p>\n"); fprintf(cgiOut, " <input type=\"button\" name=\"rest\" onclick=\"javascript:history.go(-1)\" value=\"重新载入\" />\n"); OutBodyEnd(); return 0; }
static int polling_function(void *arg) { uint32_t lux; uint32_t delay; init_completion(&thread_completion); while (1) { STK_LOCK(1); delay = pStkAlsData->als_delay; lux = get_lux(); update_and_check_report_als(lux); if (pStkAlsData->bThreadRunning == 0) break; STK_LOCK(0); msleep(delay); }; STK_LOCK(0); complete(&thread_completion); return 0; }