Ajout Transmission conditionelle
This commit is contained in:
parent
aad2cc40d4
commit
bacca08b9a
2 changed files with 55 additions and 38 deletions
2
Makefile
2
Makefile
|
|
@ -54,7 +54,7 @@ RESETPORT = /dev/ttyU0
|
||||||
|
|
||||||
|
|
||||||
TARGET = sonde
|
TARGET = sonde
|
||||||
SRC = main.c debug.c analog.c rf24.c spi.c lib/Hamming.c lib/HammingCalculateParitySmallAndFast.c onewire.c
|
SRC = main.c debug.c rf24.c analog.c spi.c lib/Hamming.c lib/HammingCalculateParitySmallAndFast.c onewire.c
|
||||||
CXXSRC =
|
CXXSRC =
|
||||||
ASRC = uart.S
|
ASRC = uart.S
|
||||||
MCU = attiny84a
|
MCU = attiny84a
|
||||||
|
|
|
||||||
71
main.c
71
main.c
|
|
@ -49,7 +49,7 @@ ISR(PCINT0_vect){
|
||||||
pcint_flag = true;
|
pcint_flag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Put in sleep mode until next ISR
|
||||||
void sleep(){
|
void sleep(){
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
@ -75,9 +75,9 @@ void sleep(){
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sleep for c*8s + 0-6s
|
||||||
void wait_for_next(){
|
void wait_for_next(int c){
|
||||||
int cnt=6;
|
int cnt=c;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cnt=2;
|
cnt=2;
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -93,18 +93,20 @@ void wait_for_next(){
|
||||||
sleep();
|
sleep();
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
debughex(&totaltime,2);
|
debughex((char *)(&totaltime),2);
|
||||||
totaltime=0;
|
totaltime=0;
|
||||||
debug("\r");
|
debug("\r");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Energy saving mode
|
||||||
void power_down(){
|
void power_down(){
|
||||||
stopADC();
|
stopADC();
|
||||||
power_all_disable();
|
power_all_disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait until radio tx done & poweroff
|
||||||
void wait_for_radio(){
|
void wait_for_radio(){
|
||||||
|
|
||||||
wdt_enable(WDTO_120MS);
|
wdt_enable(WDTO_120MS);
|
||||||
|
|
@ -131,8 +133,8 @@ void wait_for_radio(){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load nRF lib setup in Ram
|
||||||
void setupRadio(){
|
void setupRadio(){
|
||||||
// Static values in ram.
|
|
||||||
rf24_CONFIG = 0;
|
rf24_CONFIG = 0;
|
||||||
rf24_RF_CH = 90;
|
rf24_RF_CH = 90;
|
||||||
rf24_RF_SETUP = 0x26;
|
rf24_RF_SETUP = 0x26;
|
||||||
|
|
@ -144,6 +146,7 @@ void setupRadio(){
|
||||||
rf24_EN_AA = 0x00;
|
rf24_EN_AA = 0x00;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Restart USI & Reinit nRF24
|
||||||
void initRadio(){
|
void initRadio(){
|
||||||
power_usi_enable();
|
power_usi_enable();
|
||||||
rf24_init();
|
rf24_init();
|
||||||
|
|
@ -151,6 +154,8 @@ void initRadio(){
|
||||||
rf24_writeRegister(TX_ADDR,(uint8_t*)ADDR,5);
|
rf24_writeRegister(TX_ADDR,(uint8_t*)ADDR,5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ****
|
||||||
|
// Transmit data buffer
|
||||||
void txData(){
|
void txData(){
|
||||||
uint8_t crc,cpt,a,b,len;
|
uint8_t crc,cpt,a,b,len;
|
||||||
uint8_t *in, *out;
|
uint8_t *in, *out;
|
||||||
|
|
@ -201,8 +206,9 @@ int main(void)
|
||||||
debug("Sonde Start \r");
|
debug("Sonde Start \r");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t rvcc=0;
|
uint8_t rvcc=0,rtx=0,delay=6;
|
||||||
|
|
||||||
|
uint16_t t_i, lt_i=100;
|
||||||
int vcc;
|
int vcc;
|
||||||
// Setup
|
// Setup
|
||||||
power_down();
|
power_down();
|
||||||
|
|
@ -219,44 +225,51 @@ int main(void)
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
|
|
||||||
|
// each 10 runs => read VCC
|
||||||
if(!(rvcc--)){
|
if(!(rvcc--)){
|
||||||
initADC();
|
initADC();
|
||||||
|
|
||||||
// Read VCC
|
|
||||||
vcc = readVcc();
|
vcc = readVcc();
|
||||||
stopADC();
|
stopADC();
|
||||||
rvcc=4;
|
rvcc=9;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do 8 temp reads over 4s
|
// PowerUp DS18B20
|
||||||
/* int i = 7;
|
|
||||||
long lt=readtemp();
|
|
||||||
while(i--){
|
|
||||||
power_down();
|
|
||||||
wdt_enable(WDTO_500MS);
|
|
||||||
WDTCSR |= _BV(WDIE);
|
|
||||||
sleep();
|
|
||||||
power_up();
|
|
||||||
initADC();
|
|
||||||
lt += readtemp();
|
|
||||||
}
|
|
||||||
wdt_enable(WDTO_8S);
|
|
||||||
float temp = calctemp(lt / 8);*/
|
|
||||||
|
|
||||||
w1_start();
|
w1_start();
|
||||||
|
|
||||||
|
// Wait 15ms (for DS18B20 to start)
|
||||||
wdt_enable(WDTO_15MS);
|
wdt_enable(WDTO_15MS);
|
||||||
WDTCSR |= _BV(WDIE);
|
WDTCSR |= _BV(WDIE);
|
||||||
sleep();
|
sleep();
|
||||||
|
|
||||||
|
// Start DS18B20 Temp conversion
|
||||||
start_meas();
|
start_meas();
|
||||||
|
// Wait for 1s
|
||||||
wdt_enable(WDTO_1S);
|
wdt_enable(WDTO_1S);
|
||||||
WDTCSR |= _BV(WDIE);
|
WDTCSR |= _BV(WDIE);
|
||||||
sleep();
|
sleep();
|
||||||
|
|
||||||
uint16_t t_i = read_meas();//=temp*100;
|
// Read temp & stop DS18B20
|
||||||
|
t_i = read_meas();//=temp*100;
|
||||||
w1_stop();
|
w1_stop();
|
||||||
|
|
||||||
|
// If temp change more than 1 since last tx
|
||||||
|
if(t_i > lt_i+1 || t_i < lt_i -1){
|
||||||
|
// Force Tx
|
||||||
|
rtx=0;
|
||||||
|
} else {
|
||||||
|
delay=6;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If temp change more than 2 => reduced delay
|
||||||
|
if(t_i > lt_i+2 || t_i < lt_i -2){
|
||||||
|
// Force Tx
|
||||||
|
delay=2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(!(rtx--)){
|
||||||
|
|
||||||
// Send data
|
// Send data
|
||||||
initRadio();
|
initRadio();
|
||||||
|
|
||||||
|
|
@ -266,12 +279,16 @@ int main(void)
|
||||||
*(uint16_t*)(buffer+8) = t_i; // 2 o
|
*(uint16_t*)(buffer+8) = t_i; // 2 o
|
||||||
txData(buffer);
|
txData(buffer);
|
||||||
|
|
||||||
|
// keep tx temp
|
||||||
|
lt_i = t_i;
|
||||||
|
rtx=5;
|
||||||
|
|
||||||
//radio off
|
//radio off
|
||||||
rf24_powerDown();
|
rf24_powerDown();
|
||||||
|
}
|
||||||
|
|
||||||
power_down();
|
power_down();
|
||||||
wait_for_next();
|
wait_for_next(delay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue