/* * This protocol has 30 bits. The format is one IMON_UNIT header pulse, * followed by 30 bits. Each bit is one IMON_UNIT check field, and then * one IMON_UNIT field with the actual bit (1=space, 0=pulse). * The check field is always space for some bits, for others it is pulse if * both the preceding and current bit are zero, else space. IMON_CHKBITS * defines which bits are of type check. * * There is no way to distinguish an incomplete message from one where * the lower bits are all set, iow. the last pulse is for the lowest * bit which is 0.
*/ enum imon_state {
STATE_INACTIVE,
STATE_BIT_CHK,
STATE_BIT_START,
STATE_FINISHED,
STATE_ERROR,
};
/** * ir_imon_decode() - Decode one iMON pulse or space * @dev: the struct rc_dev descriptor of the device * @ev: the struct ir_raw_event descriptor of the pulse/space * * This function returns -EINVAL if the pulse violates the state machine
*/ staticint ir_imon_decode(struct rc_dev *dev, struct ir_raw_event ev)
{ struct imon_dec *data = &dev->raw->imon;
if (!is_timing_event(ev)) { if (ev.overflow)
data->state = STATE_INACTIVE; return 0;
}
dev_dbg(&dev->dev, "iMON decode started at state %d bitno %d (%uus %s)\n",
data->state, data->count, ev.duration, TO_STR(ev.pulse));
/* * Since iMON protocol is a series of bits, if at any point * we encounter an error, make sure that any remaining bits * aren't parsed as a scancode made up of less bits. * * Note that if the stick is held, then the remote repeats * the scancode with about 12ms between them. So, make sure * we have at least 10ms of space after an error. That way, * we're at a new scancode.
*/ if (data->state == STATE_ERROR) { if (!ev.pulse && ev.duration > MS_TO_US(10))
data->state = STATE_INACTIVE; return 0;
}
for (;;) { if (!geq_margin(ev.duration, IMON_UNIT, IMON_UNIT / 2)) return 0;
decrease_duration(&ev, IMON_UNIT);
switch (data->state) { case STATE_INACTIVE: if (ev.pulse) {
data->state = STATE_BIT_CHK;
data->bits = 0;
data->count = IMON_BITS;
} break; case STATE_BIT_CHK: if (IMON_CHKBITS & BIT(data->count))
data->last_chk = ev.pulse; elseif (ev.pulse) goto err_out;
data->state = STATE_BIT_START; break; case STATE_BIT_START:
data->bits <<= 1; if (!ev.pulse)
data->bits |= 1;
if (IMON_CHKBITS & BIT(data->count)) { if (data->last_chk != !(data->bits & 3)) goto err_out;
}
if (!data->count--)
data->state = STATE_FINISHED; else
data->state = STATE_BIT_CHK; break; case STATE_FINISHED: if (ev.pulse) goto err_out;
ir_imon_decode_scancode(dev);
data->state = STATE_INACTIVE; break;
}
}
err_out:
dev_dbg(&dev->dev, "iMON decode failed at state %d bitno %d (%uus %s)\n",
data->state, data->count, ev.duration, TO_STR(ev.pulse));
data->state = STATE_ERROR;
return -EINVAL;
}
/** * ir_imon_encode() - Encode a scancode as a stream of raw events * * @protocol: protocol to encode * @scancode: scancode to encode * @events: array of raw ir events to write into * @max: maximum size of @events * * Returns: The number of events written. * -ENOBUFS if there isn't enough space in the array to fit the * encoding. In this case all @max events will have been written.
*/ staticint ir_imon_encode(enum rc_proto protocol, u32 scancode, struct ir_raw_event *events, unsignedint max)
{ struct ir_raw_event *e = events; int i, pulse;
if (!max--) return -ENOBUFS;
init_ir_raw_event_duration(e, 1, IMON_UNIT);
for (i = IMON_BITS; i >= 0; i--) { if (BIT(i) & IMON_CHKBITS)
pulse = !(scancode & (BIT(i) | BIT(i + 1))); else
pulse = 0;
if (pulse == e->pulse) {
e->duration += IMON_UNIT;
} else { if (!max--) return -ENOBUFS;
init_ir_raw_event_duration(++e, pulse, IMON_UNIT);
}
pulse = !(scancode & BIT(i));
if (pulse == e->pulse) {
e->duration += IMON_UNIT;
} else { if (!max--) return -ENOBUFS;
init_ir_raw_event_duration(++e, pulse, IMON_UNIT);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.