Subversion Repositories HomeAutomation

Rev

Rev 1486 | Rev 1752 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1486 Rev 1745
Line 49... Line 49...
49
        uint16_t avgValue = 0;
49
        uint16_t avgValue = 0;
50
        for (uint8_t i=0; i<NR_AVG_VALUES; i++) {
50
        for (uint8_t i=0; i<NR_AVG_VALUES; i++) {
51
            avgValue += ABS(avgValues[i]);
51
            avgValue += ABS(avgValues[i]);
52
        }
52
        }
53
       
53
       
54
        // TODO: keep motiondetect==1 true for at least one CAN send period, so detections are never lost
54
        /* Or to keep motiondetect==1 true for at least one CAN send period, so detections are never lost */
55
        motionDetect = (avgValue >= 80);
55
        motionDetect |= (avgValue >= 80);
56
       
56
       
57
    }
57
    }
58
    else if (Timer_Expired(sns_PIR_SEND_TIMER)) {
58
    else if (Timer_Expired(sns_PIR_SEND_TIMER)) {
59
        /**
59
        /**
60
         * Read brightness sensor (via internal ADC).
60
         * Read brightness sensor (via internal ADC).
Line 75... Line 75...
75
        txMsg.Data[1] = (uint8_t)((brightness&0xFF00) >> 8);
75
        txMsg.Data[1] = (uint8_t)((brightness&0xFF00) >> 8);
76
        txMsg.Data[2] = (uint8_t)((brightness&0x00FF) >> 0);
76
        txMsg.Data[2] = (uint8_t)((brightness&0x00FF) >> 0);
77
        txMsg.Data[3] = motionDetect;
77
        txMsg.Data[3] = motionDetect;
78
        StdCan_Put(&txMsg);
78
        StdCan_Put(&txMsg);
79
        // also print data to debug
79
        // also print data to debug
80
        printf("M:%u,B:%d\n", motionDetect, brightness);
80
        //printf("M:%u,B:%d\n", motionDetect, brightness);
-
 
81
        motionDetect = 0;
81
    }
82
    }
82
}
83
}
83
 
84
 
84
void sns_PIR_HandleMessage(StdCan_Msg_t *rxMsg)
85
void sns_PIR_HandleMessage(StdCan_Msg_t *rxMsg)
85
{
86
{