X-Git-Url: http://git.droids-corp.org/?p=protos%2Frc_servos.git;a=blobdiff_plain;f=main.c;fp=main.c;h=9c368d5aa27b08f19da25d12c75249adc95f99ba;hp=82739b098a90a178ea284306fad53e127a9589e8;hb=3be0a345c40d7ef9b20e7749a0c73db14f2927e0;hpb=31b666597c0014c64be6230df6451ec062524522 diff --git a/main.c b/main.c index 82739b0..9c368d5 100644 --- a/main.c +++ b/main.c @@ -52,11 +52,13 @@ static uint16_t icp_prev; /* * SPI protocol: * - * A command is stored on 2 bytes. The first one has its msb to 0, and the - * second one to 1. The first received byte contains the command number, and the - * msb of the servo value. The second byte contains the lsb of the servo value. + * A command is stored on 2 bytes (except command 0). The first byte + * has its most significant bit to 0, and the second one to 1. The + * first received byte contains the command number, and the msb of the + * servo value. The second byte contains the lsb of the servo value. * - * Commands 0 to NB_SERVO are to set the value of servo. + * Command 0 is only one byte long, it means "I have nothing to say". + * Commands 1 to NB_SERVO+1 are to set the value of servo. * Command 14 is to enable bypass mode. * Command 15 is to disable bypass mode. */ @@ -106,6 +108,10 @@ static void poll_spi(void) if (rxidx == 0) { byte0.u8 = c; + + /* command num 0 is ignored */ + if (byte0.cmd_num == 0) + return; } else { uint16_t val; @@ -114,10 +120,10 @@ static void poll_spi(void) /* process command */ - if (byte0.cmd_num < NB_SERVO) { + if (byte0.cmd_num < NB_SERVO+1) { val = (uint16_t)byte0.val_msb << 7; val += byte1.val_lsb; - servo_table[byte0.cmd_num].command = val; + servo_table[byte0.cmd_num-1].command = val; } else if (byte0.cmd_num == BYPASS_ENABLE) { bypass = 1;