X-Git-Url: https://defiant.homedns.org/gitweb/?p=ros_wild_thumper.git;a=blobdiff_plain;f=avr%2Fnano%2Fmain.c;h=5ba30821e26227f6e936fede523b2d80b3dd4964;hp=76ce35a409dd469e05e7be67f4463803b2919251;hb=ed122a75c49ea77b0bcf8e33e1be03e4eecd36a7;hpb=003b8804848207a2403a7e879fc86f34eb631152 diff --git a/avr/nano/main.c b/avr/nano/main.c index 76ce35a..5ba3082 100644 --- a/avr/nano/main.c +++ b/avr/nano/main.c @@ -14,12 +14,21 @@ * 0x02 Distance left LSB * 0x03 Distance right MSB * 0x04 Distance right LSB - * 0x05 Distance forward MSB - * 0x06 Distance forward LSB + * 0x05 Distance forward1 MSB + * 0x06 Distance forward1 LSB * 0x07 Distance backward MSB * 0x08 Distance backward LSB * 0x09 Voltage MSB * 0x0A Voltage LSB + * 0x0B Distance forward2 MSB + * 0x0C Distance forward2 LSB + * + * 0x15 Distance forward1 MSB (read only) + * 0x16 Distance forward1 LSB (read only) + * 0x17 Distance backward MSB (read only) + * 0x18 Distance backward LSB (read only) + * 0x19 Distance forward2 MSB (read only) + * 0x1A Distance forward2 LSB (read only) * * 0xff Bootloader */ @@ -33,11 +42,14 @@ static volatile uint8_t ireg=0; static volatile uint8_t bootloader=0; static volatile uint16_t dist_left=0; static volatile uint16_t dist_right=0; -static volatile uint16_t dist_forward=0; +static volatile uint16_t dist_forward1=0; +static volatile uint16_t dist_forward2=0; static volatile uint16_t dist_backward=0; -static volatile uint8_t start_dist_fwd=0; +static volatile uint8_t start_dist_fwd1=0; +static volatile uint8_t start_dist_fwd2=0; static volatile uint8_t start_dist_bwd=0; static volatile uint16_t voltage=0; +static volatile uint8_t pind_pre=0; ISR(TWI_vect) { @@ -54,8 +66,9 @@ ISR(TWI_vect) case 0x00: // register select ireg = TWDR; - if (ireg == 0x05) start_dist_fwd=1; + if (ireg == 0x05) start_dist_fwd1=1; if (ireg == 0x07) start_dist_bwd=1; + if (ireg == 0x09) start_dist_fwd2=1; ireg--; // because we do ireg++ below TWI_ACK; @@ -88,12 +101,12 @@ ISR(TWI_vect) TWDR = tmp16; TWI_ACK; break; - case 0x05: // Distance forward MSB - tmp16 = dist_forward; + case 0x05: // Distance forward1 MSB + tmp16 = dist_forward1; TWDR = tmp16>>8; TWI_ACK; break; - case 0x06: // Distance forward LSB + case 0x06: // Distance forward1 LSB TWDR = tmp16; TWI_ACK; break; @@ -115,6 +128,42 @@ ISR(TWI_vect) TWDR = tmp16; TWI_ACK; break; + case 0x0B: // Distance forward2 MSB + tmp16 = dist_forward2; + TWDR = tmp16>>8; + TWI_ACK; + break; + case 0x0C: // Distance forward2 LSB + TWDR = tmp16; + TWI_ACK; + break; + case 0x15: // Distance forward1 MSB + tmp16 = dist_forward1; + TWDR = tmp16>>8; + TWI_ACK; + break; + case 0x16: // Distance forward1 LSB + TWDR = tmp16; + TWI_ACK; + break; + case 0x17: // Distance backward MSB + tmp16 = dist_backward; + TWDR = tmp16>>8; + TWI_ACK; + break; + case 0x18: // Distance backward LSB + TWDR = tmp16; + TWI_ACK; + break; + case 0x19: // Distance forward2 MSB + tmp16 = dist_forward2; + TWDR = tmp16>>8; + TWI_ACK; + break; + case 0x1A: // Distance forward2 LSB + TWDR = tmp16; + TWI_ACK; + break; default: TWDR = 0; TWI_NAK; @@ -135,7 +184,7 @@ uint16_t ReadChannel(uint8_t mux) { // setzen auf 8 (1) und ADC aktivieren (1) ADMUX = mux; // Kanal waehlen - ADMUX |= (1<