You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.1 KiB
C

#include "hw.h"
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
#include "hbw.h"
uint8_t expled;
uint8_t expbutton;
uint8_t waitforack;
uint8_t waitforsend;
uint8_t acktimer;
int main(void)
{
uint8_t seq;
my_address[0]=eeprom_read_byte((const uint8_t *)0);
my_address[1]=eeprom_read_byte((const uint8_t *)1);
my_address[2]=eeprom_read_byte((const uint8_t *)2);
my_address[3]=eeprom_read_byte((const uint8_t *)3);
if ((my_address[0] == 0xFF) &&
(my_address[1] == 0xFF) &&
(my_address[2] == 0xFF) &&
(my_address[3] == 0xFF))
my_address[0] = 0x74;
init_hbw();
while(1) {
hbw_loop();
if (rready) {
if ((rdest[0] == my_address[0]) &&
(rdest[1] == my_address[1]) &&
(rdest[2] == my_address[2]) &&
(rdest[3] == my_address[3]) &&
(rmessage[0] == 'h')) {
saddress[0] = raddress[0];
saddress[1] = raddress[1];
saddress[2] = raddress[2];
saddress[3] = raddress[3];
seq = (rctl >> 1) & 3;
sctl = 0x18 | (seq << 5);
smessage[0] = HBWTYPE;
smessage[1] = 0;
slen = 2;
sendmsg();
}
if ((rdest[0] == my_address[0]) &&
(rdest[1] == my_address[1]) &&
(rdest[2] == my_address[2]) &&
(rdest[3] == my_address[3]) &&
(rmessage[0] == 'n')) {
saddress[0] = raddress[0];
saddress[1] = raddress[1];
saddress[2] = raddress[2];
saddress[3] = raddress[3];
seq = (rctl >> 1) & 3;
sctl = 0x18 | (seq << 5);
smessage[0] = 'h';
smessage[1] = 'b';
smessage[2] = 'w';
smessage[3] = 'b';
smessage[4] = 'o';
smessage[5] = 'c';
smessage[6] = 'c';
smessage[7] = '0';
smessage[8] = '0';
smessage[9] = '1';
slen = 10;
sendmsg();
}
if ((rdest[0] == my_address[0]) &&
(rdest[1] == my_address[1]) &&
(rdest[2] == my_address[2]) &&
(rdest[3] == my_address[3]) &&
(rmessage[0] == 'v')) {
saddress[0] = raddress[0];
saddress[1] = raddress[1];
saddress[2] = raddress[2];
saddress[3] = raddress[3];
seq = (rctl >> 1) & 3;
sctl = 0x18 | (seq << 5);
smessage[0] = 1;
smessage[1] = 2;
slen = 2;
sendmsg();
}
rready = 0;
}
}
}