Subversion Repositories HomeAutomation

Rev

Rev 2198 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 2198 Rev 2199
Line 191... Line 191...
191
    }
191
    }
192
 
192
 
193
    /* Disable ISR */
193
    /* Disable ISR */
194
    IR_MASK_TIMEOUT();
194
    IR_MASK_TIMEOUT();
195
#endif
195
#endif
196
//  gpio_toggle_pin(EXP_J);
-
 
197
}
196
}
198
#endif
197
#endif
199
 
198
 
200
 
199
 
201
/*-----------------------------------------------------------------------------
200
/*-----------------------------------------------------------------------------
Line 216... Line 215...
216
void IrTransceiver_Store_ch2(uint8_t id, uint8_t status)
215
void IrTransceiver_Store_ch2(uint8_t id, uint8_t status)
217
{
216
{
218
    IrTransceiver_Store(2);
217
    IrTransceiver_Store(2);
219
}
218
}
220
 
219
 
221
 
-
 
222
///////////// DEBUG!!!!
-
 
223
//#include <drivers/mcu/gpio.h>
-
 
224
void IrTransceiver_Store(uint8_t channel)
220
void IrTransceiver_Store(uint8_t channel)
225
{
221
{
226
    static uint16_t prev_time[3];
222
    static uint16_t prev_time[3];
227
    uint16_t pulsewidth;
223
    uint16_t pulsewidth;
228
 
224
 
Line 233... Line 229...
233
    pulsewidth = time - prev_time[channel];
229
    pulsewidth = time - prev_time[channel];
234
    prev_time[channel] = time;
230
    prev_time[channel] = time;
235
 
231
 
236
#if IR_MIN_STARTPULSE_WIDTH>0
232
#if IR_MIN_STARTPULSE_WIDTH>0
237
    if ((pulsewidth <= IR_MIN_STARTPULSE_WIDTH) && (drvIrRxChannel[channel].storeEnable == TRUE) && (drvIrRxChannel[channel].len == 0))
233
    if ((pulsewidth <= IR_MIN_STARTPULSE_WIDTH) && (drvIrRxChannel[channel].storeEnable == TRUE) && (drvIrRxChannel[channel].len == 0))
238
    {
234
    {
239
        IR_MASK_TIMEOUT();
235
        IR_MASK_TIMEOUT();
240
        return;
236
        return;
241
    }
237
    }
242
    else
238
    else
243
    {
239
    {
244
        IR_UNMASK_TIMEOUT();
240
        IR_UNMASK_TIMEOUT();
245
    }
241
    }
246
#endif
242
#endif
247
//gpio_toggle_pin(EXP_K);
-
 
248
 
243
 
249
#if IR_RX_CONTINUOUS_MODE==1
244
#if IR_RX_CONTINUOUS_MODE==1
250
/* in continuous mode when short pulse arrives received len should be set to zero */
245
/* in continuous mode when short pulse arrives received len should be set to zero */
251
//TODO?
246
//TODO?
252
    if ((pulsewidth < (IR_MIN_PULSE_WIDTH*CYCLES_PER_US/TIMER_PRESC)) && (drvIrRxChannel[channel].storeEnable == TRUE))
247
    if ((pulsewidth < (IR_MIN_PULSE_WIDTH*CYCLES_PER_US/TIMER_PRESC)) && (drvIrRxChannel[channel].storeEnable == TRUE))
253
    {
248
    {
254
///////////// DEBUG!!!!
-
 
255
//gpio_toggle_pin(EXP_A);
-
 
256
        drvIrRxChannel[channel].len = 0;
249
        drvIrRxChannel[channel].len = 0;
257
        return;
250
        return;
258
    }
251
    }
259
    else
252
    else
260
    {
253
    {
261
    }
254
    }
262
#endif
255
#endif
263
//gpio_toggle_pin(EXP_A);
-
 
264
 
-
 
265
 
256
 
266
    if (drvIrRxChannel[channel].storeEnable)
257
    if (drvIrRxChannel[channel].storeEnable)
267
    {
258
    {
-
 
259
#if IR_RX_CONTINUOUS_MODE==0
268
        /* Store the measurement. */
260
        /* Store the measurement. */
269
        drvIrRxChannel[channel].buf[drvIrRxChannel[channel].len++] = pulsewidth;
261
        drvIrRxChannel[channel].buf[drvIrRxChannel[channel].len++] = pulsewidth;
270
 
262
 
271
        /* Disable future measurements if we've filled the buffer. */
263
        /* Disable future measurements if we've filled the buffer. */
272
        //TODO: Report overflow to application
264
        //TODO: Report overflow to application
Line 274... Line 266...
274
        {
266
        {
275
            drvIrRxChannel[channel].len = MAX_NR_TIMES-1;
267
            drvIrRxChannel[channel].len = MAX_NR_TIMES-1;
276
        }
268
        }
277
        else
269
        else
278
        {
270
        {
279
#if IR_RX_CONTINUOUS_MODE==0
-
 
280
            /* Set the timeout for detection of the end of the pulse train. */
271
            /* Set the timeout for detection of the end of the pulse train. */
281
            drvIrRxChannel[channel].timeout = time + (IR_MAX_PULSE_WIDTH*CYCLES_PER_US/TIMER_PRESC);
272
            drvIrRxChannel[channel].timeout = time + (IR_MAX_PULSE_WIDTH*CYCLES_PER_US/TIMER_PRESC);
282
            IR_TIMEOUT_REG = drvIrRxChannel[channel].timeout;
273
            IR_TIMEOUT_REG = drvIrRxChannel[channel].timeout;
-
 
274
        }
283
#else
275
#else
-
 
276
        /* Store the measurement. */
-
 
277
        drvIrRxChannel[channel].buf[drvIrRxChannel[channel].index++] = pulsewidth;
-
 
278
 
-
 
279
        if (drvIrRxChannel[channel].index == MAX_NR_TIMES)
-
 
280
        {
-
 
281
            drvIrRxChannel[channel].index = 0;
-
 
282
        }
-
 
283
        if (drvIrRxChannel[channel].len++ == MAX_NR_TIMES)
-
 
284
        {
-
 
285
            drvIrRxChannel[channel].len = MAX_NR_TIMES-1;
-
 
286
        }
284
            /* Notify the application that a pulse has been received. */
287
        /* Notify the application that a pulse has been received. */
285
            drvIrRxChannel[channel].callback(channel, drvIrRxChannel[channel].buf, drvIrRxChannel[channel].len, drvIrRxChannel[channel].index);
288
        drvIrRxChannel[channel].callback(channel, drvIrRxChannel[channel].buf, drvIrRxChannel[channel].len, drvIrRxChannel[channel].index);
286
#endif
289
#endif
287
 
290
 
288
        }
-
 
289
    }
291
    }
290
    else if (drvIrRxChannel[channel].enable == TRUE)
292
    else if (drvIrRxChannel[channel].enable == TRUE)
291
    {
293
    {
292
        /* The first edge of the pulse train has been detected. Enable the storage of the following pulsewidths. */
294
        /* The first edge of the pulse train has been detected. Enable the storage of the following pulsewidths. */
293
        drvIrRxChannel[channel].storeEnable = TRUE;
295
        drvIrRxChannel[channel].storeEnable = TRUE;