Exemple #1
0
static void
po188_get_sensor_status(void)
{
	
	/* begin: added by z00168965 for light sensor */    
    po188_driver.voltage_now = po188_read_adc(CHANNEL_ADC_LIGHT, NULL);
    return ;
    /* end: added by z00168965 for light sensor */ 
}
Exemple #2
0
static void po188_work_func(struct work_struct *work)
{     
    /*static int voltage[TIMES];//remember the last 3 value
    static int iVolIndex=0;   
    static int iSumCount=0;
    int i       = 0;
    int iSum    = 0;
    int iAveVol = 0;*/
    int iVoltage_new = 0;
    int iVoltage_last = 0;
    int ret = 0; 
     
    ret = po188_read_adc(PO188_ADC_CHANNEL);    
    if (ret < 0) //read value failed. invalid value, don't report. 
    {
        PO188_ERRMSG("po188 have not read adc value");
        msleep(5000);  //sleep 5s

        //delay 1s to read.
        mod_timer(&po188_driver.timer, jiffies + msecs_to_jiffies(po188_driver.delay_time));
        return;
    }

    //iVoltage_new = po188_get_converted_level(ret);
    iVoltage_new = ret;
/*    voltage[iVolIndex]=po188_driver.voltage_now;
    iVolIndex = (iVolIndex+1)%TIMES;

    if (iSumCount<TIMES)
    {
        iSumCount++;
    }

    for(i=0; i<iSumCount; i++)// count the current average value
    {
        iSum += voltage[i];
    }
    //remember the last 3 average voltage value
    iAveVol = iSum / iSumCount;  */

    spin_lock(&po188_driver.s_lock);
    po188_driver.voltage_now = iVoltage_new;
    iVoltage_last = po188_driver.last_voltage;
    spin_unlock(&po188_driver.s_lock);

    //check if it's reach the threshold data and report to hal level        
/*    if ( (po188_driver.last_voltage - iAveVol >= PO188_REPORT_THRESHOLD) ||
         (iAveVol - po188_driver.last_voltage >= PO188_REPORT_THRESHOLD) )
    {
        po188_report_data();
    }  */
//    if ( (iVoltage_last - iVoltage_new >= PO188_REPORT_THRESHOLD) ||
//         (iVoltage_new - iVoltage_last >= PO188_REPORT_THRESHOLD) )
    {    
        po188_report_data(iVoltage_new);
        spin_lock(&po188_driver.s_lock);
        po188_driver.last_voltage = iVoltage_new;
        spin_unlock(&po188_driver.s_lock);
    }

    mod_timer(&po188_driver.timer, jiffies + msecs_to_jiffies(po188_driver.delay_time));
}