hardware/Rmodule/main.c

84 lines
1.5 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 "onewire/onewire.h"
2013-11-18 21:27:01 +07:00
#include "res/strings.h"
2013-11-15 14:42:41 +07:00
#define UART_BAUD_RATE 19200
2013-11-18 21:27:01 +07:00
unsigned char get_uart_char(void){
2013-11-15 14:42:41 +07:00
unsigned int res;
do{
res = uart_getc();
} while(res & UART_NO_DATA);
return (unsigned char) res;
}
2013-11-18 21:27:01 +07:00
static int get_uart_line(char *pbuf, int len_ln){
int i = 0;
unsigned char c;
len_ln=len_ln-1;
while((c=get_uart_char()) != 0x0D && i<len_ln){
uart_putc(c);
pbuf[i] = c;
i=i+1;
}
pbuf[i] = '\0';
return i;
}
2013-11-15 14:42:41 +07:00
void getListDevices(void){
uint8_t i;
uint8_t id[OW_ROMCODE_SIZE];
uint8_t diff, nSensors;
2013-11-18 21:27:01 +07:00
uart_puts_p(ScanStr);
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-18 21:27:01 +07:00
if ( diff != OW_PRESENCE_ERR && diff != OW_DATA_ERR) {
2013-11-15 14:42:41 +07:00
for ( i=0; i < OW_ROMCODE_SIZE; i++ ){
2013-11-18 21:27:01 +07:00
uart_puthex_byte(id[i]);
uart_putc(' ');
2013-11-15 14:42:41 +07:00
}
2013-11-18 21:27:01 +07:00
uart_puts(CRLF);
}
2013-11-15 14:42:41 +07:00
nSensors++;
}
2013-11-18 21:27:01 +07:00
uart_put_int(nSensors);
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-18 21:27:01 +07:00
char cmd[5];
unsigned int len_line=0;
while(1){
uart_puts_p(CmdPrompt);
len_line=get_uart_line(&cmd[0],sizeof(cmd));
if (len_line>0){
if (strcmp_P(cmd, CmdLD)==0){
getListDevices();
}
if (strcmp_P(cmd, CmdHelp)==0){
uart_puts_p(HelpTitle);
uart_puts_p(HelpItem1);
uart_puts_p(HelpItem2);
}
2013-11-15 14:42:41 +07:00
}
}
}