#include "hw.h" #include #include #include #include "hbw.h" uint8_t expled; uint8_t expbutton; uint8_t expdouble; uint16_t exptime; uint16_t explong; uint16_t longtime; uint16_t logtime; uint16_t logtimer; 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 (expdouble == 1) expdouble = 2; } } if (bit_is_set(PIND, ExpButton)) { if (exptime) { if (now - exptime > 50 && !explong && (expdouble == 2)) { expbutton++; state = 1; expdouble = 0; } if (now - exptime > 300 && !explong && (expdouble == 1)) { expbutton++; state = 2; expdouble = 0; } if (now - exptime > 50 && !explong && (expdouble == 0)) expdouble = 1; if (now - exptime > 50 && explong) { state = 0; expdouble = 0; } exptime = 0; } } if (state != 255) if (hbw_send_key(1, expbutton, state)) state = 255; if (logtimer && (hbw_timer - logtimer < 100)) { led = 0; if (bit_is_set(PIND, ExpLED)) led = 200; if (!hbw_send_channel(0, 1, &led)) logtimer += 300; else logtimer = 0; } } }