Compare commits

...

No commits in common. 'b5b9383d4e4e8c49d5163cbdf92bf6998f45fb61' and 'b4cc8c2034ce8beb5d2f931f00ddc4dcd2799923' have entirely different histories.

@ -10,8 +10,9 @@ CLDFLAGS += -mmcu=$(CPU) -Wl,-Map=$(@:%.elf=%.map)
TESTOBJS += testnode.o testhbw.o
RELAISOBJS += relaisnode.o relaishbw.o
IO6OBJS += io6node.o io6hbw.o
all: testnode.hex relaisnode.hex
all: testnode.hex relaisnode.hex io6node.hex
testnode.o: testnode.c hbw.h hw.h testhw.h
$(CC) $(CFLAGS) -DTESTNODE -c $< -o $@
@ -31,6 +32,15 @@ relaishbw.o: hbw.c hbw.h hw.h relaishw.h
relaisnode.elf: $(RELAISOBJS)
$(CC) $(CLDFLAGS) -o $@ $(RELAISOBJS)
io6node.o: io6node.c hbw.h hw.h io6hw.h
$(CC) $(CFLAGS) -DIO6NODE -c $< -o $@
io6hbw.o: hbw.c hbw.h hw.h io6hw.h
$(CC) $(CFLAGS) -DIO6NODE -c $< -o $@
io6node.elf: $(IO6OBJS)
$(CC) $(CLDFLAGS) -o $@ $(IO6OBJS)
%hex:%elf
$(OBJCOPY) -j .text -j .data -O srec $< $@

@ -1,7 +0,0 @@
#ifndef __ALARMHW_H__
#define __ALARMHW_H__
#define RedLED PD4
#define GreenLED PD5
#define BuzzerON PD6
#define ReedSwitch PD7
#endif

@ -1,130 +0,0 @@
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
#include "alarmhw.h"
#include "rs485.h"
#include "eb.h"
uint8_t reedstate;
uint8_t buzzerstate;
uint8_t waitforack;
uint8_t waitforsend;
uint8_t acktimer;
int main(void)
{
uint8_t i;
init_rs485();
DDRD |= (1<<RedLED);
DDRD |= (1<<GreenLED);
DDRD |= (1<<BuzzerON);
DDRD &= ~(1<<ReedSwitch);
PORTD &= ~(1<<RedLED);
PORTD |= (1<<GreenLED);
PORTD &= ~(1<<BuzzerON);
PORTD |= (1<<ReedSwitch);
ADMUX = (0<<REFS1) | (1<<REFS0);
ADCSRA = (1<<ADPS2) | (1<<ADPS1);
ADCSRA |= (1<<ADEN);
ADCSRA |= (1<<ADSC);
loop_until_bit_is_clear(ADCSRA, ADSC);
svalue = ADCW;
my_address = eeprom_read_byte((const uint8_t *)0);
my_prio = eeprom_read_byte((const uint8_t *)1);
master = eeprom_read_byte((const uint8_t *)2);
buzzerstate = 0;
reedstate = 0;
waitforsend = 0;
acktimer = 0;
sei();
while(1) {
rs485_loop();
if (rflag) {
if (rsender)
srecv = rsender;
else
srecv = master;
smode = 0;
if ((rrecv == my_address) && (rmode == 2)) {
acktimer = 0;
waitforsend = 0;
}
if ((rrecv == my_address) && (rmode == 0)) {
for (i=0; i<4; i++) {
decodepart(i);
scommand = 0;
schannel = rchannel;
if ((rcommand == 0x40) && (rchannel == 0)) {
scommand = 0x40;
svalue = 2; /* 2 LED keys + 4 ADCs */
}
if ((rcommand == 0x60) && (rchannel == 1)) {
if (rvalue & 0x02) {
buzzerstate = ~0;
PORTD |= (1<<BuzzerON);
} else {
buzzerstate = 0;
PORTD &= ~(1<<BuzzerON);
}
scommand = 0x40;
svalue = (reedstate & 0x01) | (buzzerstate & 0x02);
}
if ((rcommand == 0x40) && (rchannel == 1)) {
scommand = 0x40;
svalue = (reedstate & 0x01) | (buzzerstate & 0x02);
}
if ((rcommand == 0x40) && ((rchannel > 1) && (rchannel < 6))) {
ADMUX = (ADMUX & ~(0x1F)) | (rchannel - 2);
ADCSRA |= (1<<ADSC);
loop_until_bit_is_clear(ADCSRA, ADSC);
scommand = 0x40;
svalue = ADCW;
}
encodepart(i);
}
smode = 0;
sendmsg();
acktimer = 0;
waitforsend = 0;
}
if ((rrecv == 0) && (rmode == 0) && waitforsend) {
if (!acktimer) {
scommand = 0x40;
schannel = 1;
svalue = (reedstate & 0x01) | (buzzerstate & 0x02);
encodepart(0);
scommand = 0;
encodepart(1);
encodepart(2);
encodepart(3);
smode = 1;
sendmsg();
acktimer = my_prio;
} else
acktimer--;
}
rflag = 0;
}
if (bit_is_clear(PIND, ReedSwitch) && (!reedstate)) {
reedstate = ~0;
waitforsend = ~0;
PORTD |= (1<<RedLED);
PORTD &= ~(1<<GreenLED);
}
if (bit_is_set(PIND, ReedSwitch) && reedstate) {
reedstate = 0;
waitforsend = ~0;
PORTD &= ~(1<<RedLED);
PORTD |= (1<<GreenLED);
}
}
}

12
hbw.c

@ -239,8 +239,10 @@ static void announce(void)
smessage[11] = HBWSERIAL5;
smessage[12] = HBWSERIAL6;
smessage[13] = HBWSERIAL7;
smessage[14] = HBWSERIAL8;
smessage[15] = HBWSERIAL9;
smessage[14] = 0x30 + ((((uint8_t*)&my_address)[3] >> 4) & 0x0F);
smessage[15] = 0x30 + (((uint8_t*)&my_address)[3] & 0x0F);
if(smessage[14] > 0x39) smessage[14] += 7;
if(smessage[15] > 0x39) smessage[15] += 7;
if (sendmsg())
asent = 1;
@ -445,8 +447,10 @@ static void rprocess(void)
smessage[5] = HBWSERIAL5;
smessage[6] = HBWSERIAL6;
smessage[7] = HBWSERIAL7;
smessage[8] = HBWSERIAL8;
smessage[9] = HBWSERIAL9;
smessage[8] = 0x30 + ((((uint8_t*)&my_address)[3] >> 4) & 0x0F);
smessage[9] = 0x30 + (((uint8_t*)&my_address)[3] & 0x0F);
if(smessage[8] > 0x39) smessage[8] += 7;
if(smessage[9] > 0x39) smessage[9] += 7;
slen = 10;
seq = (rctl >> 1) & 3;
sctl = 0x18 | (seq << 5);

@ -1,34 +0,0 @@
<?xml version="1.0"?>
<device eep_size="512" version="01">
<supported_types>
<type priority="2" id="HBW-EBALARM" name="EBus Alarm HBW">
<parameter const_value="0xAB" size="1" index="0"/>
<parameter const_value="0" size="1" index="1"/>
</type>
</supported_types>
<paramset id="HBW-EBALARM_dev_master" type="MASTER">
<parameter id="LOGGING_TIME">
<logical type="float" unit="s" default="5.0" max="25.5" min="0.1"/>
<physical size="1.0" type="integer" interface="eeprom">
<address index="0x0001"/>
</physical>
<conversion type="float_integer_scale" offset="0.0" factor="10"/>
</parameter>
<parameter id="CENTRAL_ADDRESS" hidden="true">
<logical type="integer"/>
<physical size="4" type="integer" interface="eeprom">
<address index="0x0002"/>
</physical>
</parameter>
<enforce id="CENTRAL_ADDRESS" value="1"/>
</paramset>
<channels>
<channel index="0" type="MAINTENANCE" count="1" class="maintenance" ui_flags="internal">
</channel>
<channel index="1" type="SWITCH" count="1" physical_index_offset="-1">
</channel>
</channels>
</device>

@ -0,0 +1,152 @@
<?xml version="1.0"?>
<device eep_size="512" version="01">
<supported_types>
<type priority="2" id="HBW-EBIO6" name="Elektor EBus I/O6 Board">
<parameter const_value="0xE2" size="1" index="0"/>
<parameter const_value="0" size="1" index="1"/>
</type>
</supported_types>
<paramset id="HBW-EBIO6_dev_master" type="MASTER">
<parameter id="LOGGING_TIME">
<logical type="float" unit="s" default="5.0" max="25.5" min="0.1"/>
<physical size="1.0" type="integer" interface="eeprom">
<address index="0x0001"/>
</physical>
<conversion type="float_integer_scale" offset="0.0" factor="10"/>
</parameter>
<parameter id="CENTRAL_ADDRESS" hidden="true">
<logical type="integer"/>
<physical size="4" type="integer" interface="eeprom">
<address index="0x0002"/>
</physical>
</parameter>
<enforce id="CENTRAL_ADDRESS" value="1"/>
</paramset>
<frames>
<frame id="LEVEL_SET" type="#x" channel_field="10" direction="to_device">
<parameter size="1.0" index="11.0" type="integer" param="LEVEL"/>
</frame>
<frame id="LEVEL_GET" type="#S" channel_field="10" direction="to_device"/>
<frame id="INFO_LEVEL" type="#i" channel_field="10" direction="from_device" event="true">
<parameter size="1.0" index="11.0" type="integer" param="LEVEL"/>
</frame>
</frames>
<channels>
<channel index="0" type="MAINTENANCE" count="1" class="maintenance" ui_flags="internal">
</channel>
<channel index="1" type="SWITCH" count="2" physical_index_offset="-1">
<paramset id="hmw_switch_ch_master" type="MASTER" address_step="2" address_start="0x06">
<parameter id="LOGGING">
<logical type="option">
<option id="OFF"/>
<option id="ON" default="true"/>
</logical>
<physical size="0.1" type="integer" interface="eeprom">
<address index="+0"/>
</physical>
</parameter>
</paramset>
<paramset id="hmw_switch_ch_link" type="LINK" count="16" address_start="0x10" address_step="7" peer_param="SENSOR" channel_param="CHANNEL">
<parameter id="SENSOR" hidden="true" operations="none">
<logical type="address"/>
<physical type="array">
<physical size="4.0" type="integer" interface="eeprom">
<address index="+0"/>
</physical>
<physical size="1.0" type="integer" interface="eeprom">
<address index="+4"/>
</physical>
</physical>
</parameter>
<parameter id="CHANNEL" hidden="true" operations="none">
<logical type="integer" min="0" max="255" default="255"/>
<physical size="1.0" type="integer" interface="eeprom">
<address index="+5"/>
</physical>
</parameter>
<parameter id="SHORT_ACTION_TYPE">
<logical type="option">
<option id="ON"/>
<option id="OFF"/>
<option id="INACTIVE"/>
<option id="TOGGLE" default="true"/>
</logical>
<physical size="0.2" type="integer" interface="eeprom">
<address index="+6"/>
</physical>
</parameter>
<parameter id="LONG_ACTION_TYPE">
<logical type="option">
<option id="ON"/>
<option id="OFF"/>
<option id="INACTIVE"/>
<option id="TOGGLE" default="true"/>
</logical>
<physical size="0.2" type="integer" interface="eeprom">
<address index="+6.2"/>
</physical>
</parameter>
<parameter id="LONGRELEASE_ACTION_TYPE">
<logical type="option">
<option id="ON"/>
<option id="OFF"/>
<option id="INACTIVE" default="true"/>
<option id="TOGGLE"/>
</logical>
<physical size="0.2" type="integer" interface="eeprom">
<address index="+6.4"/>
</physical>
</parameter>
<parameter id="DOUBLE_ACTION_TYPE">
<logical type="option">
<option id="ON"/>
<option id="OFF"/>
<option id="INACTIVE" default="true"/>
<option id="TOGGLE"/>
</logical>
<physical size="0.2" type="integer" interface="eeprom">
<address index="+6.6"/>
</physical>
</parameter>
</paramset>
<paramset id="hmw_switch_ch_values" type="VALUES">
<parameter id="STATE" operations="read,write,event" control="SWITCH.STATE">
<logical type="boolean" default="false"/>
<physical type="integer" interface="command" value_id="LEVEL">
<set request="LEVEL_SET"/>
<get request="LEVEL_GET" response="INFO_LEVEL"/>
<event frame="INFO_LEVEL"/>
</physical>
<conversion type="boolean_integer" true="200" false="0" threshold="1"/>
</parameter>
</paramset>
</channel>
<channel index="3" type="SENSOR" count="6" physical_index_offset="-1">
<paramset id="hmw_sensor_ch_master" type="MASTER" address_step="2" address_start="0x0a">
<parameter id="LOGGING">
<logical type="option">
<option id="OFF"/>
<option id="ON" default="true"/>
</logical>
<physical size="0.1" type="integer" interface="eeprom">
<address index="+0"/>
</physical>
</parameter>
</paramset>
<paramset id="hmw_sensor_ch_values" type="VALUES">
<parameter id="STATE" operations="read,event" control="SWITCH.STATE">
<logical type="boolean" default="false"/>
<physical type="integer" interface="command" value_id="LEVEL">
<get request="LEVEL_GET" response="INFO_LEVEL"/>
<event frame="INFO_LEVEL"/>
</physical>
<conversion type="boolean_integer" true="200" false="0" threshold="1"/>
</parameter>
</paramset>
</channel>
</channels>
</device>

@ -125,7 +125,7 @@
</parameter>
</paramset>
</channel>
<channel index="3" type="SENSOR" count="2" physical_index_offset="-1">
<channel index="3" type="SENSOR" count="4" physical_index_offset="-1">
<paramset id="hmw_sensor_ch_master" type="MASTER" address_step="2" address_start="0x0a">
<parameter id="LOGGING">
<logical type="option">

@ -9,6 +9,9 @@
#ifdef RELAISNODE
#include "relaishw.h"
#endif
#ifdef IO6NODE
#include "io6hw.h"
#endif
#ifndef F_CPU
#define F_CPU 16000000L
@ -27,8 +30,6 @@
#define HBWSERIAL5 'D'
#define HBWSERIAL6 'E'
#define HBWSERIAL7 'V'
#define HBWSERIAL8 '0'
#define HBWSERIAL9 '0'
#endif
#ifndef HBWMAJOR

@ -0,0 +1,30 @@
#ifndef __ALARMHW_H__
#define __ALARMHW_H__
#define ConfigLED PD4
#define ConfigButton PD5
#define Out0 PD6
#define Out1 PD7
#define In0 PC0
#define In1 PC1
#define In2 PC2
#define In3 PC3
#define In4 PC4
#define In5 PC5
#define RedLED PB0
#define GreenLED PB1
#define HBWTYPE 0xE2
#define HBWMAJOR 1
#define HBWMINOR 2
#define HBWSERIAL0 'C'
#define HBWSERIAL1 'O'
#define HBWSERIAL2 'L'
#define HBWSERIAL3 'A'
#define HBWSERIAL4 'B'
#define HBWSERIAL5 'I'
#define HBWSERIAL6 'O'
#define HBWSERIAL7 '4'
#endif

@ -0,0 +1,309 @@
#include "hw.h"
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
#include "hbw.h"
uint8_t in0state;
uint8_t in1state;
uint8_t in2state;
uint8_t in3state;
uint8_t in4state;
uint8_t in5state;
uint8_t scount;
uint16_t logtime;
uint8_t logging0;
uint8_t logging1;
uint16_t logtimer0;
uint16_t logtimer1;
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);
logging0 = ee & 0x01;
ee = eeprom_read_byte((const uint8_t *)8);
logging1 = ee & 0x01;
}
uint8_t hbw_get_channel(uint8_t channel, uint8_t data[])
{
if (channel == 0) {
if (bit_is_clear(PINB, RedLED))
data[0] = 0;
else
data[0] = 200;
return 1;
}
if (channel == 1) {
if (bit_is_clear(PINB, GreenLED))
data[0] = 0;
else
data[0] = 200;
return 1;
}
if (channel == 2) {
if (bit_is_clear(PINC, In0))
data[0] = 200;
else
data[0] = 0;
return 1;
}
if (channel == 3) {
if (bit_is_clear(PINC, In1))
data[0] = 200;
else
data[0] = 0;
return 1;
}
if (channel == 4) {
if (bit_is_clear(PINC, In2))
data[0] = 200;
else
data[0] = 0;
return 1;
}
if (channel == 5) {
if (bit_is_clear(PINC, In3))
data[0] = 200;
else
data[0] = 0;
return 1;
}
if (channel == 6) {
if (bit_is_clear(PINC, In4))
data[0] = 200;
else
data[0] = 0;
return 1;
}
if (channel == 7) {
if (bit_is_clear(PINC, In5))
data[0] = 200;
else
data[0] = 0;
return 1;
}
return 0;
}
void hbw_set_channel(uint8_t channel, uint8_t len, uint8_t data[])
{
if (channel == 0) {
if (data[0])
PORTB |= (1<<RedLED);
else
PORTB &= ~(1<<RedLED);
}
if (channel == 1) {
if (data[0])
PORTB |= (1<<GreenLED);
else
PORTB &= ~(1<<GreenLED);
}
}
void hbw_receive_key(uint32_t saddress, uint8_t schannel, uint8_t channel, uint8_t countflag)
{
uint8_t i, type;
if (channel > 1)
return;
if (scount == countflag)
return;
for (i=0; i < 16; i++) {
if ((eeprom_read_byte((const uint8_t *)(i*7)+0x10) == ((uint8_t*)&saddress)[0]) &&
(eeprom_read_byte((const uint8_t *)(i*7)+0x11) == ((uint8_t*)&saddress)[1]) &&
(eeprom_read_byte((const uint8_t *)(i*7)+0x12) == ((uint8_t*)&saddress)[2]) &&
(eeprom_read_byte((const uint8_t *)(i*7)+0x13) == ((uint8_t*)&saddress)[3]) &&
(eeprom_read_byte((const uint8_t *)(i*7)+0x14) == schannel) &&
(eeprom_read_byte((const uint8_t *)(i*7)+0x15) == channel)) {
type = eeprom_read_byte((const uint8_t *)(i*7)+0x16);
switch (countflag & 3) {
case 1:
type = (type >> 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:
if(channel == 0)
PORTB |= (1<<RedLED);
else
PORTB |= (1<<GreenLED);
break;
case 1:
if(channel == 0)
PORTB &= ~(1<<RedLED);
else
PORTB &= ~(1<<GreenLED);
break;
case 3:
if(channel == 0)
PORTB ^= (1<<RedLED);
else
PORTB ^= (1<<GreenLED);
}
if ((channel == 0) && logging0) {
logtimer0 = hbw_timer + logtime;
if (!logtimer0) logtimer0 = 1;
}
if ((channel == 1) && logging1) {
logtimer1 = hbw_timer + logtime;
if (!logtimer1) logtimer1 = 1;
}
return;
}
}
}
int main(void)
{
uint8_t state;
DDRB |= (1<<RedLED);
DDRB |= (1<<GreenLED);
DDRC &= ~(1<<In0);
DDRC &= ~(1<<In1);
DDRC &= ~(1<<In2);
DDRC &= ~(1<<In3);
DDRC &= ~(1<<In4);
DDRC &= ~(1<<In5);
PORTB &= ~(1<<RedLED);
PORTB &= ~(1<<GreenLED);
PORTC |= (1<<In0);
PORTC |= (1<<In1);
PORTC |= (1<<In2);
PORTC |= (1<<In3);
PORTC |= (1<<In4);
PORTC |= (1<<In5);
hbw_init();
while(1) {
hbw_loop();
if (bit_is_clear(PINC, In0) && (!in0state)) {
state = 200;
if (hbw_send_channel(2, 1, &state))
in0state = ~0;
}
if (bit_is_set(PINC, In0) && in0state) {
state = 0;
if (hbw_send_channel(2, 1, &state))
in0state = 0;
}
if (bit_is_clear(PINC, In1) && (!in1state)) {
state = 200;
if (hbw_send_channel(3, 1, &state))
in1state = ~0;
}
if (bit_is_set(PINC, In1) && in1state) {
state = 0;
if (hbw_send_channel(3, 1, &state))
in1state = 0;
}
if (bit_is_clear(PINC, In2) && (!in2state)) {
state = 200;
if (hbw_send_channel(4, 1, &state))
in2state = ~0;
}
if (bit_is_set(PINC, In2) && in2state) {
state = 0;
if (hbw_send_channel(4, 1, &state))
in2state = 0;
}
if (bit_is_clear(PINC, In3) && (!in3state)) {
state = 200;
if (hbw_send_channel(5, 1, &state))
in3state = ~0;
}
if (bit_is_set(PINC, In3) && in3state) {
state = 0;
if (hbw_send_channel(5, 1, &state))
in3state = 0;
}
if (bit_is_clear(PINC, In4) && (!in4state)) {
state = 200;
if (hbw_send_channel(6, 1, &state))
in4state = ~0;
}
if (bit_is_set(PINC, In4) && in4state) {
state = 0;
if (hbw_send_channel(6, 1, &state))
in4state = 0;
}
if (bit_is_clear(PINC, In5) && (!in5state)) {
state = 200;
if (hbw_send_channel(7, 1, &state))
in5state = ~0;
}
if (bit_is_set(PINC, In5) && in5state) {
state = 0;
if (hbw_send_channel(7, 1, &state))
in5state = 0;
}
if (hbw_timer - logtimer0 < 100) {
state = 0;
if (bit_is_clear(PINB, RedLED))
state = 200;
if (!hbw_send_channel(0, 1, &state))
logtimer0 += 300;
else
logtimer0 = 0;
}
if (hbw_timer - logtimer1 < 100) {
state = 0;
if (bit_is_clear(PINB, GreenLED))
state = 200;
if (!hbw_send_channel(1, 1, &state))
logtimer1 += 300;
else
logtimer1 = 0;
}
}
}

@ -3,9 +3,15 @@
#define ConfigLED PD4
#define ConfigButton PD5
#define Relais1 PB0
#define Relais2 PB1
#define In0 PC0
#define In1 PC1
#define In2 PC2
#define In3 PC3
#define HBWTYPE 0xE1
#define HBWMAJOR 1
#define HBWMINOR 2
@ -17,7 +23,5 @@
#define HBWSERIAL5 'R'
#define HBWSERIAL6 'E'
#define HBWSERIAL7 'L'
#define HBWSERIAL8 '0'
#define HBWSERIAL9 '1'
#endif

@ -4,14 +4,31 @@
#include <avr/eeprom.h>
#include "hbw.h"
uint8_t relais1state;
uint8_t relais2state;
uint8_t pc0state;
uint8_t pc1state;
uint8_t in0state;
uint8_t in1state;
uint8_t in2state;
uint8_t in3state;
uint8_t scount;
uint16_t logtime;
uint8_t logging0;
uint8_t logging1;
uint16_t logtimer0;
uint16_t logtimer1;
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);
logging0 = ee & 0x01;
ee = eeprom_read_byte((const uint8_t *)8);
logging1 = ee & 0x01;
}
uint8_t hbw_get_channel(uint8_t channel, uint8_t data[])
@ -25,20 +42,34 @@ uint8_t hbw_get_channel(uint8_t channel, uint8_t data[])
}
if (channel == 1) {
if (bit_is_clear(PINB, Relais2))
data[0] = 200;
else
data[0] = 0;
else
data[0] = 200;
return 1;
}
if (channel == 2) {
if (bit_is_clear(PINC, PC0))
if (bit_is_clear(PINC, In0))
data[0] = 200;
else
data[0] = 0;
return 1;
}
if (channel == 3) {
if (bit_is_clear(PINC, PC1))
if (bit_is_clear(PINC, In1))
data[0] = 200;
else
data[0] = 0;
return 1;
}
if (channel == 4) {
if (bit_is_clear(PINC, In2))
data[0] = 200;
else
data[0] = 0;
return 1;
}
if (channel == 5) {
if (bit_is_clear(PINC, In3))
data[0] = 200;
else
data[0] = 0;
@ -113,6 +144,14 @@ void hbw_receive_key(uint32_t saddress, uint8_t schannel, uint8_t channel, uint8
else
PORTB ^= (1<<Relais2);
}
if ((channel == 0) && logging0) {
logtimer0 = hbw_timer + logtime;
if (!logtimer0) logtimer0 = 1;
}
if ((channel == 1) && logging1) {
logtimer1 = hbw_timer + logtime;
if (!logtimer1) logtimer1 = 1;
}
return;
}
}
@ -125,55 +164,98 @@ int main(void)
DDRB |= (1<<Relais1);
DDRB |= (1<<Relais2);
DDRC &= ~(1<<PC0);
DDRC &= ~(1<<PC1);
DDRC &= ~(1<<In0);
DDRC &= ~(1<<In1);
DDRC &= ~(1<<In2);
DDRC &= ~(1<<In3);
PORTB &= ~(1<<Relais1);
PORTB &= ~(1<<Relais2);
PORTC |= (1<<PC0);
PORTC |= (1<<PC1);
relais1state = 0;
relais2state = 0;
pc0state = 0;
pc1state = 0;
PORTC |= (1<<In0);
PORTC |= (1<<In1);
PORTC |= (1<<In2);
PORTC |= (1<<In3);
hbw_init();
while(1) {
hbw_loop();
if (bit_is_clear(PINC, PC0) && (!pc0state)) {
if (bit_is_clear(PINC, In0) && (!in0state)) {
state = 200;
if (hbw_send_channel(2, 1, &state)) {
pc0state = ~0;
}
if (hbw_send_channel(2, 1, &state))
in0state = ~0;
}
if (bit_is_set(PINC, PC0) && pc0state) {
if (bit_is_set(PINC, In0) && in0state) {
state = 0;
if (hbw_send_channel(2, 1, &state)) {
pc0state = 0;
}
if (hbw_send_channel(2, 1, &state))
in0state = 0;
}
if (bit_is_clear(PINC, PC1) && (!pc1state)) {
if (bit_is_clear(PINC, In1) && (!in1state)) {
state = 200;
if (hbw_send_channel(3, 1, &state)) {
pc1state = ~0;
}
if (hbw_send_channel(3, 1, &state))
in1state = ~0;
}
if (bit_is_set(PINC, PC1) && pc1state) {
if (bit_is_set(PINC, In1) && in1state) {
state = 0;
if (hbw_send_channel(3, 1, &state)) {
pc1state = 0;
}
if (hbw_send_channel(3, 1, &state))
in1state = 0;
}
if (bit_is_clear(PINC, In2) && (!in2state)) {
state = 200;
if (hbw_send_channel(4, 1, &state))
in2state = ~0;
}
if (bit_is_set(PINC, In2) && in2state) {
state = 0;
if (hbw_send_channel(4, 1, &state))
in2state = 0;
}
if (bit_is_clear(PINC, In3) && (!in3state)) {
state = 200;
if (hbw_send_channel(5, 1, &state))
in3state = ~0;
}
if (bit_is_set(PINC, In3) && in3state) {
state = 0;
if (hbw_send_channel(5, 1, &state))
in3state = 0;
}
if (hbw_timer - logtimer0 < 100) {
state = 0;
if (bit_is_clear(PINB, Relais1))
state = 200;
if (!hbw_send_channel(0, 1, &state))
logtimer0 += 300;
else
logtimer0 = 0;
}
if (hbw_timer - logtimer1 < 100) {
state = 0;
if (bit_is_clear(PINB, Relais2))
state = 200;
if (!hbw_send_channel(1, 1, &state))
logtimer1 += 300;
else
logtimer1 = 0;
}
}
}

@ -17,8 +17,6 @@
#define HBWSERIAL5 'T'
#define HBWSERIAL6 'S'
#define HBWSERIAL7 'T'
#define HBWSERIAL8 '0'
#define HBWSERIAL9 '1'
#define HBW_MAXLINKS 16
#define HBW_LINKOFFS 0x80

@ -10,6 +10,7 @@ uint16_t exptime;
uint16_t explong;
uint16_t longtime;
uint16_t logtime;
uint16_t logtimer;
uint8_t logging;
uint8_t scount;
@ -101,6 +102,10 @@ void hbw_receive_key(uint32_t saddress, uint8_t schannel, uint8_t channel, uint8
case 3:
PORTD ^= (1<<ExpLED);
}
if (logging) {
logtimer = hbw_timer + logtime;
if (!logtimer) logtimer = 1;
}
return;
}
}
@ -110,6 +115,7 @@ int main(void)
{
uint16_t now;
uint8_t state;
uint8_t led;
DDRD |= (1<<ExpLED);
DDRD &= ~(1<<ExpButton);
@ -122,6 +128,8 @@ int main(void)
exptime = 0;
explong = 0;
logtimer = 0;
hbw_init();
state = 255;
@ -165,5 +173,15 @@ int main(void)
if (state != 255)
if (hbw_send_key(1, expbutton, state))
state = 255;
if (hbw_timer - logtimer < 100) {
led = 0;
if (bit_is_clear(PIND, ExpLED))
led = 200;
if (!hbw_send_channel(0, 1, &led))
logtimer += 300;
else
logtimer = 0;
}
}
}

Loading…
Cancel
Save