OutputPacket *packet = output_create_packet();
packet->bit_duration = 4;
packet->repeat_count = 1;
- packet->final_delay = 0;
+ packet->final_delay = 128;
packet->length = 10;
packet->data[0] = 0x9B;
packet->data[1] = 0;
{
uint8_t out_bit = packet->length;
uint8_t out_level = mfx_get_output_level(packet);
+ uint8_t ones_count = state->ones_count;
for(uint8_t i=length; i--; )
{
uint8_t bit = (bits>>i)&1;
- if(state->ones_count>=8)
- {
- ++i;
- bit = 0;
- state->ones_count = 0;
- }
- else if(bit)
- ++state->ones_count;
+ if(bit)
+ ++ones_count;
else
- state->ones_count = 0;
+ ones_count = 0;
if(out_level==bit)
bit ^= 3;
packet->data[out_bit>>3] |= bit<<(out_bit&7);
out_bit += 2;
out_level = bit>>1;
+
+ if(ones_count>=8)
+ {
+ bits &= (1<<i)-1;
+ ++i;
+ }
}
+ state->ones_count = ones_count;
packet->length = out_bit;
}
mfx_encode_bits8_raw(packet, state, state->crc8, 8);
mfx_encode_flag_pairs(packet, 11);
mfx_encode_bits8_raw(packet, state, 0x3, 4);
+ packet->final_delay = 0;
uint8_t fill = (1-mfx_get_output_level(packet))*0xFF;
for(uint8_t i=0; i<2; ++i)
}
mfx_ensure_low_level(packet);
+ packet->final_delay = 128;
}
static void mfx_receive_feedback()
uint8_t speed_dir = cmd[3];
if((speed_dir&0x7F)==0x7F)
return INVALID_VALUE;
- ++speed_dir;
+ // Skip emergency stop
+ if(speed_dir>0)
+ ++speed_dir;
if(cmd[0]==MFX_SPEED)
mfx_speed_packet(addr, speed_dir);