From 3be0a345c40d7ef9b20e7749a0c73db14f2927e0 Mon Sep 17 00:00:00 2001 From: Olivier Matz Date: Thu, 3 Oct 2013 20:23:40 +0200 Subject: [PATCH] add a 0x00 command that means "I have nothing to say" --- main.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) 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; -- 2.20.1