diff options
Diffstat (limited to 'lib/msp430.c')
-rw-r--r-- | lib/msp430.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/msp430.c b/lib/msp430.c index b2afd25..b74d3ec 100644 --- a/lib/msp430.c +++ b/lib/msp430.c @@ -53,9 +53,9 @@ static ssize_t Fill_Buffer(struct MSP430_Hardware* hw) static int Buffer_Empty(struct MSP430_Hardware* hw) { - return hw->index < BUFFER_SIZE && ( - hw->buffer[hw->index] == 0 || - hw->buffer[hw->index] == 0xff); + return hw->index >= BUFFER_SIZE || + hw->buffer[hw->index] < 8 || + hw->buffer[hw->index] == 0xff; } static struct CEC_Packet* Receive(struct CEC_Device* device) @@ -75,6 +75,7 @@ static struct CEC_Packet* Receive(struct CEC_Device* device) void* packet = &(hw->buffer[hw->index]); hw->index += hw->buffer[hw->index]; + hw->index++; if(hw->index > BUFFER_SIZE) return NULL; return (struct CEC_Packet*)packet; } @@ -219,6 +220,8 @@ struct CEC_Hardware* MSP430_Open_Hardware(const char* device) if(ioctl(result->i2c, I2C_SLAVE, I2C_ADDR) < 0) goto error2; + result->index = BUFFER_SIZE; + return &(result->cec); error2: |