#include "hw.h" #include #include #include #include "hbw.h" uint8_t expled; uint8_t expbutton; uint16_t exptime; uint16_t explong; uint16_t longtime; uint16_t logtime; uint8_t logging; uint8_t scount; void hbw_read_config(void) { uint8_t ee; ee = eeprom_read_byte((const uint8_t *)1); logtime = 100L * ee; ee = eeprom_read_byte((const uint8_t *)6); logging = ee & 0x01; ee = eeprom_read_byte((const uint8_t *)8); if (ee == 0xFF) longtime = 1000; else longtime = 100L * ee; } uint8_t hbw_get_channel(uint8_t channel, uint8_t data[]) { if (channel == 1) { if (bit_is_clear(PIND, ExpButton)) data[0] = 200; else data[0] = 0; return 1; } if (channel == 0) { if (bit_is_clear(PIND, ExpLED)) data[0] = 0; else data[0] = 200; return 1; } return 0; } void hbw_set_channel(uint8_t channel, uint8_t len, uint8_t data[]) { if (channel == 0) { if (data[0]) PORTD |= (1<> 6) & 0x3; break; case 0: type = (type >> 4) & 0x3; break; case 3: type = (type >> 2) & 0x3; break; case 2: type = type & 0x3; } switch (type) { case 0: PORTD |= (1<= 300) { explong = now; state = 3; } } else { if (now - exptime > longtime) { explong = now; expbutton++; state = 3; } } } else { exptime = now; explong = 0; } } if (bit_is_set(PIND, ExpButton)) { if (exptime) { if (now - exptime > 50 && !explong) { expbutton++; state = 2; } if (now - exptime > 50 && explong) state = 0; exptime = 0; } } if (state != 255) if (hbw_send_key(1, expbutton, state)) state = 255; } }