sync during ir_recv dev
All checks were successful
Deploy Docs / build-and-deploy (push) Successful in 12s
All checks were successful
Deploy Docs / build-and-deploy (push) Successful in 12s
This commit is contained in:
@@ -76,10 +76,10 @@ void ir_recv_sim_thread(void *p1, void *p2, void *p3) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
K_THREAD_DEFINE(sim_tid, 1024, ir_recv_sim_thread, NULL, NULL, NULL, 5, 0, 0);
|
||||
#endif
|
||||
|
||||
/* --- Robust State Machine --- */
|
||||
typedef enum {
|
||||
IR_STATE_IDLE,
|
||||
IR_STATE_HEADER_SYNC,
|
||||
@@ -99,7 +99,7 @@ typedef struct {
|
||||
|
||||
static ir_ctx_t channels[3];
|
||||
|
||||
static void process_sample(ir_ctx_t *ctx, int16_t raw) {
|
||||
static void process_ir_sample(ir_ctx_t *ctx, int16_t raw) {
|
||||
bool active = (raw > 2048);
|
||||
if (IS_ENABLED(CONFIG_IR_RECV_INVERT_SIGNAL)) active = !active;
|
||||
|
||||
@@ -164,27 +164,22 @@ static void process_sample(ir_ctx_t *ctx, int16_t raw) {
|
||||
*/
|
||||
void ir_recv_thread(void *arg1, void *arg2, void *arg3)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
k_sem_take(&adc_sem, K_FOREVER);
|
||||
|
||||
while (read_idx != write_idx)
|
||||
{
|
||||
int16_t *buf = adc_buffers[read_idx];
|
||||
|
||||
for (int i = 0; i < SAMPLES_PER_BUFFER; i++)
|
||||
{
|
||||
/* De-interleave and process IR channels */
|
||||
process_ir_sample(&channels[0], buf[i * ADC_CHANNELS + 0]);
|
||||
process_ir_sample(&channels[1], buf[i * ADC_CHANNELS + 1]);
|
||||
process_ir_sample(&channels[2], buf[i * ADC_CHANNELS + 2]);
|
||||
|
||||
/* Optional: Handle battery sample at buf[i * ADC_CHANNELS + 3] */
|
||||
}
|
||||
|
||||
read_idx = (read_idx + 1) % BUFFER_COUNT;
|
||||
}
|
||||
}
|
||||
while (1)
|
||||
{
|
||||
k_sem_take(&adc_sem, K_FOREVER);
|
||||
while (read_idx != write_idx)
|
||||
{
|
||||
int16_t *buf = adc_buffers[read_idx];
|
||||
for (int i = 0; i < SAMPLES_PER_BUFFER; i++)
|
||||
{
|
||||
/* Now this call matches the static function name above */
|
||||
process_ir_sample(&channels[0], buf[i * ADC_CHANNELS + 0]);
|
||||
process_ir_sample(&channels[1], buf[i * ADC_CHANNELS + 1]);
|
||||
process_ir_sample(&channels[2], buf[i * ADC_CHANNELS + 2]);
|
||||
}
|
||||
read_idx = (read_idx + 1) % BUFFER_COUNT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
K_THREAD_DEFINE(ir_recv_tid, 2048, ir_recv_thread, NULL, NULL, NULL, 2, 0, 0);
|
||||
|
||||
Reference in New Issue
Block a user