change port manipulation to ardino commands and lets change the pin at runtime possible
This commit is contained in:
parent
1aa694bba2
commit
ff8b6d933b
4 changed files with 54 additions and 129 deletions
|
@ -45,26 +45,13 @@
|
|||
const struct sensors_sensor relay_sensor;
|
||||
static int status(int type);
|
||||
static int enabled = 0;
|
||||
static int relay1=0;
|
||||
static int relay2=0;
|
||||
static int relay3=0;
|
||||
static int relay4=0;
|
||||
|
||||
static int relay[8]={0,0,0,0,0,0,0,0};
|
||||
static int relaypin[8]={RELAY_PIN_1,RELAY_PIN_2,RELAY_PIN_3,RELAY_PIN_4,RELAY_PIN_5,RELAY_PIN_6,RELAY_PIN_7,RELAY_PIN_8};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case RELAY_SENSOR_1:
|
||||
return relay1;
|
||||
case RELAY_SENSOR_2:
|
||||
return relay2;
|
||||
case RELAY_SENSOR_3:
|
||||
return relay2;
|
||||
case RELAY_SENSOR_4:
|
||||
return relay2;
|
||||
}
|
||||
return 0;
|
||||
return relay[type];
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
|
@ -74,6 +61,14 @@ configure(int type, int c)
|
|||
case SENSORS_ACTIVE:
|
||||
if(c) {
|
||||
if(!status(SENSORS_ACTIVE)) {
|
||||
relay_init(relaypin[RELAY_SENSOR_1]);
|
||||
relay_init(relaypin[RELAY_SENSOR_2]);
|
||||
relay_init(relaypin[RELAY_SENSOR_3]);
|
||||
relay_init(relaypin[RELAY_SENSOR_4]);
|
||||
relay_init(relaypin[RELAY_SENSOR_5]);
|
||||
relay_init(relaypin[RELAY_SENSOR_6]);
|
||||
relay_init(relaypin[RELAY_SENSOR_7]);
|
||||
relay_init(relaypin[RELAY_SENSOR_8]);
|
||||
enabled = 1;
|
||||
}
|
||||
} else {
|
||||
|
@ -81,39 +76,19 @@ configure(int type, int c)
|
|||
}
|
||||
break;
|
||||
case RELAY_SENSOR_1:
|
||||
if(c==0){
|
||||
relay1_off();
|
||||
relay1=0;
|
||||
}else{
|
||||
relay1_on();
|
||||
relay1=1;
|
||||
};
|
||||
break;
|
||||
case RELAY_SENSOR_2:
|
||||
if(c==0){
|
||||
relay2_off();
|
||||
relay2=0;
|
||||
}else{
|
||||
relay2_on();
|
||||
relay2=1;
|
||||
};
|
||||
break;
|
||||
case RELAY_SENSOR_3:
|
||||
if(c==0){
|
||||
relay3_off();
|
||||
relay3=0;
|
||||
}else{
|
||||
relay3_on();
|
||||
relay3=1;
|
||||
};
|
||||
break;
|
||||
case RELAY_SENSOR_4:
|
||||
case RELAY_SENSOR_5:
|
||||
case RELAY_SENSOR_6:
|
||||
case RELAY_SENSOR_7:
|
||||
case RELAY_SENSOR_8:
|
||||
if(c==0){
|
||||
relay4_off();
|
||||
relay4=0;
|
||||
relay_off(relaypin[type]);
|
||||
relay[type]=0;
|
||||
}else{
|
||||
relay4_on();
|
||||
relay4=1;
|
||||
relay_on(relaypin[type]);
|
||||
relay[type]=1;
|
||||
};
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -48,5 +48,19 @@ extern const struct sensors_sensor relay_sensor;
|
|||
#define RELAY_SENSOR_2 1
|
||||
#define RELAY_SENSOR_3 2
|
||||
#define RELAY_SENSOR_4 3
|
||||
#define RELAY_SENSOR_5 4
|
||||
#define RELAY_SENSOR_6 5
|
||||
#define RELAY_SENSOR_7 6
|
||||
#define RELAY_SENSOR_8 7
|
||||
|
||||
/* default pins Arduino-Merkurboard */
|
||||
#define RELAY_PIN_1 10
|
||||
#define RELAY_PIN_2 11
|
||||
#define RELAY_PIN_3 12
|
||||
#define RELAY_PIN_4 13
|
||||
#define RELAY_PIN_5 15
|
||||
#define RELAY_PIN_6 16
|
||||
#define RELAY_PIN_7 17
|
||||
#define RELAY_PIN_8 18
|
||||
|
||||
#endif /* __RELAY_SENSOR_H__ */
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
* Harald Pichler harald@the-develop.net
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "relay.h"
|
||||
|
||||
/**
|
||||
|
@ -45,92 +45,32 @@
|
|||
* \{
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* \brief Turns the RELAY1 on.
|
||||
* \brief init RELAY PINS.
|
||||
*/
|
||||
void
|
||||
relay1_off(void)
|
||||
relay_init(uint8_t pin)
|
||||
{
|
||||
PORTB &= ~(1<<PINB0);
|
||||
DDRB |= (1<<DDB0);
|
||||
pinMode(pin, OUTPUT);
|
||||
digitalWrite(pin, LOW);
|
||||
}
|
||||
/**
|
||||
* \brief Turns the RELAY on.
|
||||
*/
|
||||
|
||||
void
|
||||
relay_on(uint8_t pin)
|
||||
{
|
||||
digitalWrite(pin, HIGH);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* \brief Turns the RELAY1 off
|
||||
* \brief Turns the RELAY off
|
||||
*/
|
||||
void
|
||||
relay1_on(void)
|
||||
relay_off(uint8_t pin)
|
||||
{
|
||||
PORTB |= (1<<PINB0);
|
||||
DDRB |= (1<<DDB0);
|
||||
digitalWrite(pin, LOW);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Turns the RELAY2 on.
|
||||
*/
|
||||
void
|
||||
relay2_off(void)
|
||||
{
|
||||
PORTB &= ~(1<<PINB1);
|
||||
DDRB |= (1<<DDB1);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* \brief Turns the RELAY2 off.
|
||||
*/
|
||||
void
|
||||
relay2_on(void)
|
||||
{
|
||||
PORTB |= (1<<PINB1);
|
||||
DDRB |= (1<<DDB1);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Turns the RELAY3 on.
|
||||
*/
|
||||
void
|
||||
relay3_off(void)
|
||||
{
|
||||
PORTB &= ~(1<<PINB2);
|
||||
DDRB |= (1<<DDB2);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* \brief Turns the RELAY3 off.
|
||||
*/
|
||||
void
|
||||
relay3_on(void)
|
||||
{
|
||||
PORTB |= (1<<PINB2);
|
||||
DDRB |= (1<<DDB2);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Turns the RELAY4 on.
|
||||
*/
|
||||
void
|
||||
relay4_off(void)
|
||||
{
|
||||
PORTB &= ~(1<<PINB3);
|
||||
DDRB |= (1<<DDB3);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* \brief Turns the RELAY4 off.
|
||||
*/
|
||||
void
|
||||
relay4_on(void)
|
||||
{
|
||||
PORTB |= (1<<PINB3);
|
||||
DDRB |= (1<<DDB3);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -45,14 +45,10 @@
|
|||
|
||||
/** @name RELAY Functions */
|
||||
/** @{ */
|
||||
void relay1_on(void);
|
||||
void relay1_off(void);
|
||||
void relay2_on(void);
|
||||
void relay2_off(void);
|
||||
void relay3_on(void);
|
||||
void relay3_off(void);
|
||||
void relay4_on(void);
|
||||
void relay4_off(void);
|
||||
void relay_init(uint8_t pin);
|
||||
void relay_on(uint8_t pin);
|
||||
void relay_off(uint8_t pin);
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* __RELAY_H__ */
|
||||
|
|
Loading…
Reference in a new issue