Mercurial > tote-had
changeset 4:d279d961c91b
Fix the i2c controller
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Fri, 11 Mar 2016 13:05:41 +0100 |
| parents | f8bffeb4f945 |
| children | 60ccacc24cab |
| files | controller/i2c.ino |
| diffstat | 1 files changed, 5 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/controller/i2c.ino Thu Mar 10 23:08:15 2016 +0100 +++ b/controller/i2c.ino Fri Mar 11 13:05:41 2016 +0100 @@ -4,6 +4,7 @@ const int SLAVE_ADDRESS = 0x09; const int MAX_REGS = 16; + volatile int8_t regs[MAX_REGS] = {}; volatile uint8_t address; @@ -15,21 +16,18 @@ void receive(int bytes) { address = Wire.read(); - while (Wire.available()) { + while (Wire.available() && address < MAX_REGS) { regs[address] = Wire.read(); ++address; - if (address >= MAX_REGS) { - return; - } } } void i2c_loop() { for (int leg = 0; leg < 3; ++leg) { if (regs[leg * 4]) { - move_leg(leg, regs[leg * 4 + 1], - regs[leg * 4 + 2], - regs[leg * 4 + 3]); + move_leg(leg, regs[leg * 4 + 1] + HOME, + regs[leg * 4 + 2] + HOME , + regs[leg * 4 + 3] - TIBIA); regs[leg * 4] = 0; } }
