hardware/Rmodule/main.c

71 lines
1.4 KiB
C
Raw Normal View History

2013-11-15 14:42:41 +07:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#include <avr/io.h>
#include <stdio.h>
#include <avr/interrupt.h>
#include "uart/uart.h"
#include "uart/uart_addon.h"
#include "res/strings.h"
#include "onewire/onewire.h"
#define UART_BAUD_RATE 19200
unsigned char getcmd(void){
unsigned int res;
do{
res = uart_getc();
} while(res & UART_NO_DATA);
return (unsigned char) res;
}
void getListDevices(void){
uint8_t i;
uint8_t id[OW_ROMCODE_SIZE];
uint8_t diff, nSensors;
2013-11-17 21:26:03 +07:00
char buffer[40];
2013-11-15 14:42:41 +07:00
2013-11-17 21:26:03 +07:00
uart_puts("\r\nScanning 1-wire bus\r\n");
2013-11-15 14:42:41 +07:00
ow_reset();
nSensors = 0;
diff = OW_SEARCH_FIRST;
while ( diff != OW_LAST_DEVICE) {
diff = ow_rom_search( diff, &id[0] );
2013-11-17 21:26:03 +07:00
//if ( diff != OW_PRESENCE_ERR && diff != OW_DATA_ERR && diff != OW_LAST_DEVICE ) {
2013-11-15 14:42:41 +07:00
for ( i=0; i < OW_ROMCODE_SIZE; i++ ){
2013-11-17 21:26:03 +07:00
sprintf(buffer,"%02X ",id[i]);
uart_puts(buffer);
2013-11-15 14:42:41 +07:00
}
uart_puts("\r\n");
2013-11-17 21:26:03 +07:00
//}
2013-11-15 14:42:41 +07:00
nSensors++;
}
2013-11-17 21:26:03 +07:00
sprintf(buffer,"Found %d devices",nSensors);
uart_puts(buffer);
2013-11-15 14:42:41 +07:00
}
2013-11-17 21:26:03 +07:00
int main(void){
2013-11-15 14:42:41 +07:00
uart_init(UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU));
2013-11-17 21:26:03 +07:00
#ifndef OW_ONE_BUS
ow_set_bus(&PIND,&PORTD,&DDRD,PD6);
#endif
sei();
2013-11-15 14:42:41 +07:00
char cmd = '0';
while (cmd != 'q'){
uart_puts_p(MainMenuItemTitle);
uart_puts_p(MainMenuItem1);
uart_puts_p(MainMenuItem2);
uart_puts_p(MainMenuItemQuit);
uart_puts_p(MainMenuItemPrompt);
cmd = getcmd();
if (cmd == '1'){
getListDevices();
}
}
while(1){ }
}