63 lines
1.2 KiB
C
63 lines
1.2 KiB
C
// Ïðîøèâêà äëÿ óäàëåííîãî ðàäèîìîäóëÿ
|
|
|
|
#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;
|
|
|
|
uart_puts_p("\r\nScanning 1-wire bus\r\n");
|
|
ow_reset();
|
|
nSensors = 0;
|
|
diff = OW_SEARCH_FIRST;
|
|
while ( diff != OW_LAST_DEVICE) {
|
|
diff = ow_rom_search( diff, &id[0] );
|
|
if ( diff != OW_PRESENCE_ERR && diff != OW_DATA_ERR && diff != OW_LAST_DEVICE ) {
|
|
for ( i=0; i < OW_ROMCODE_SIZE; i++ ){
|
|
uart_puthex_byte(id[i]);
|
|
uart_puts_p( " " );
|
|
}
|
|
uart_puts("\r\n");
|
|
}
|
|
nSensors++;
|
|
}
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
uart_init(UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU));
|
|
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){ }
|
|
|
|
}
|