Bluetooth hc05 library
Diff: hc05.cpp
- Revision:
- 11:770663228ced
- Parent:
- 10:2e1538dc2e1a
- Child:
- 12:4a779fa69f6b
--- a/hc05.cpp Sun Aug 19 17:00:22 2018 +0000 +++ b/hc05.cpp Tue Aug 21 15:11:34 2018 +0000 @@ -5,7 +5,9 @@ void bt_modul_hc05::initUART(UART num, unsigned long baudrate, _IRQ interrupt) { - switch(num) { + t_uart = num; + + switch(t_uart) { case UART1 : at0.device_init(baudrate, interrupt); t_interrupt = interrupt; @@ -18,9 +20,9 @@ } -char *bt_modul_hc05::get_version(UART num) +char *bt_modul_hc05::get_version() { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+VERSION?\r\n", ""); if(t_interrupt == OFF) { @@ -41,9 +43,9 @@ return 0; } -char *bt_modul_hc05::set_reset(UART num) +char *bt_modul_hc05::set_reset() { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+RESET\r\n", ""); if(t_interrupt == OFF) { @@ -64,9 +66,9 @@ return 0; } -char *bt_modul_hc05::set_default_settings(UART num) +char *bt_modul_hc05::set_default_settings() { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+ORGL\r\n", ""); if(t_interrupt == OFF) { @@ -88,9 +90,9 @@ } -char *bt_modul_hc05::get_modul_address(UART num) +char *bt_modul_hc05::get_modul_address() { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+ADDR?\r\n", ""); if(t_interrupt == OFF) { @@ -112,9 +114,9 @@ } -char *bt_modul_hc05::get_modul_name(UART num) +char *bt_modul_hc05::get_modul_name() { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+NAME?\r\n", ""); if(t_interrupt == OFF) { @@ -136,9 +138,9 @@ } -char *bt_modul_hc05::get_device_name(UART num) +char *bt_modul_hc05::get_device_name() { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+RNAME?\r\n", ""); if(t_interrupt == OFF) { @@ -160,9 +162,9 @@ } -char *bt_modul_hc05::get_modul_role(UART num) +char *bt_modul_hc05::get_modul_role() { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+ROLE?\r\n", ""); if(t_interrupt == OFF) { @@ -184,9 +186,9 @@ } -char *bt_modul_hc05::get_device_class(UART num) +char *bt_modul_hc05::get_device_class() { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+CLASS?\r\n", ""); if(t_interrupt == OFF) { @@ -208,9 +210,9 @@ } -char *bt_modul_hc05::get_modul_giac(UART num) +char *bt_modul_hc05::get_modul_giac() { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+IAC?\r\n", ""); if(t_interrupt == OFF) { @@ -232,9 +234,9 @@ } -char *bt_modul_hc05::get_modul_inquiry(UART num) +char *bt_modul_hc05::get_modul_inquiry() { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+INQM?\r\n", ""); if(t_interrupt == OFF) { @@ -256,9 +258,9 @@ } -char *bt_modul_hc05::get_modul_pincode(UART num) +char *bt_modul_hc05::get_modul_pincode() { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+PSWD?\r\n", ""); if(t_interrupt == OFF) { @@ -280,9 +282,9 @@ } -char *bt_modul_hc05::get_modul_uart(UART num) +char *bt_modul_hc05::get_modul_uart() { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+UART?\r\n", ""); if(t_interrupt == OFF) { @@ -304,14 +306,14 @@ } -char *bt_modul_hc05::get_modul_inqm(UART num) +char *bt_modul_hc05::get_modul_inqm() { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+INQ\r\n", ""); if(t_interrupt == OFF) { - return at0.getAnswer(600); + return at0.getAnswer(20000); } else { return at0.buffer; } @@ -320,7 +322,7 @@ at1.at_send1("AT+INQ\r\n", ""); if(t_interrupt1 == OFF) { - return at1.getAnswer(600); + return at1.getAnswer(20000); } else { return at1.buffer; } @@ -330,9 +332,9 @@ } -char *bt_modul_hc05::get_modul_init(UART num) +char *bt_modul_hc05::get_modul_init() { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+INIT\r\n", ""); @@ -358,9 +360,9 @@ } -char *bt_modul_hc05::get_modul_state(UART num) +char *bt_modul_hc05::get_modul_state() { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+STATE?\r\n", ""); if(t_interrupt == OFF) { @@ -382,9 +384,9 @@ } -char *bt_modul_hc05::get_addr_mode(UART num) +char *bt_modul_hc05::get_addr_mode() { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+CMODE?\r\n", ""); if(t_interrupt == OFF) { @@ -406,9 +408,9 @@ } -char *bt_modul_hc05::get_fixed_addr(UART num) +char *bt_modul_hc05::get_fixed_addr() { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+BIND?\r\n", ""); if(t_interrupt == OFF) { @@ -430,10 +432,10 @@ } -char *bt_modul_hc05::set_modul_role(UART num, ROLE role) +char *bt_modul_hc05::set_modul_role(ROLE role) { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+ROLE=%i\r\n", (char*)role); if(t_interrupt == OFF) { @@ -455,9 +457,9 @@ } -char *bt_modul_hc05::set_device_class(UART num, int dclass) +char *bt_modul_hc05::set_device_class(int dclass) { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+CLASS=%i\r\n", (char*) dclass); if(t_interrupt == OFF) { @@ -479,9 +481,9 @@ } -char *bt_modul_hc05::set_modul_giac(UART num, char *giac) +char *bt_modul_hc05::set_modul_giac(char *giac) { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+IAC=%s\r\n", giac); if(t_interrupt == OFF) { @@ -503,9 +505,9 @@ } -char *bt_modul_hc05::set_modul_pincode(UART num, char *pin) +char *bt_modul_hc05::set_modul_pincode(char *pin) { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+PSWD=%s\r\n", pin); if(t_interrupt == OFF) { @@ -527,9 +529,9 @@ } -char *bt_modul_hc05::set_modul_inquiry(UART num, char *inqparams) +char *bt_modul_hc05::set_modul_inquiry(char *inqparams) { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+INQM=%s\r\n", inqparams); if(t_interrupt == OFF) { @@ -551,9 +553,9 @@ } -char *bt_modul_hc05::set_modul_name(UART num, char *name) +char *bt_modul_hc05::set_modul_name(char *name) { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+NAME=%s\r\n", name); if(t_interrupt == OFF) { @@ -575,9 +577,9 @@ } -char *bt_modul_hc05::set_modul_uart(UART num, char *uartparams) +char *bt_modul_hc05::set_modul_uart(char *uartparams) { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+UART=%s\r\n", uartparams); if(t_interrupt == OFF) { @@ -599,9 +601,9 @@ } -char *bt_modul_hc05::set_fixed_addr(UART num, char *address) +char *bt_modul_hc05::set_fixed_addr(char *address) { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+BIND=\r\n", address); if(t_interrupt == OFF) { @@ -624,9 +626,9 @@ } -char *bt_modul_hc05::set_addr_mode(UART num, CMODE mode) +char *bt_modul_hc05::set_addr_mode(CMODE mode) { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+CMODE=%i\r\n", (char*)mode); if(t_interrupt == OFF) { @@ -647,9 +649,9 @@ return 0; } -char *bt_modul_hc05::search_device(UART num, char *address) +char *bt_modul_hc05::search_device(char *address) { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+FSAD=%s\r\n", address); if(t_interrupt == OFF) { @@ -670,9 +672,9 @@ return 0; } -char *bt_modul_hc05::delete_device(UART num, char *address) +char *bt_modul_hc05::delete_device(char *address) { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+PMSAD=%s\r\n", address); if(t_interrupt == OFF) { @@ -693,9 +695,9 @@ return 0; } -char *bt_modul_hc05::delete_all(UART num) +char *bt_modul_hc05::delete_all() { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+RMAAD\r\n", ""); if(t_interrupt == OFF) { @@ -716,9 +718,9 @@ return 0; } -char *bt_modul_hc05::connect_device(UART num, char *address) +char *bt_modul_hc05::connect_device(char *address) { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+LINK=%s\r\n", address); if(t_interrupt == OFF) { @@ -739,9 +741,9 @@ return 0; } -char *bt_modul_hc05::disconnect_device(UART num, char *address) +char *bt_modul_hc05::disconnect_device(char *address) { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("AT+DISC=%s\r\n", address); if(t_interrupt == OFF) { @@ -762,9 +764,9 @@ return 0; } -bool bt_modul_hc05::data_send(UART num, char *data) +bool bt_modul_hc05::data_send(char *data) { - switch(num) { + switch(t_uart) { case UART1 : at0.at_send("%s\r\n", data); return true; @@ -775,9 +777,9 @@ return false; } -char *bt_modul_hc05::data_receive(UART num) +char *bt_modul_hc05::data_receive() { - switch(num) { + switch(t_uart) { case UART1 : if(t_interrupt == OFF) { return at0.getAnswer(800); @@ -796,9 +798,9 @@ } -void bt_modul_hc05::flush(UART num) +void bt_modul_hc05::flush() { - switch(num) { + switch(t_uart) { case UART1 : if(t_interrupt == ON) { at0.clear(); @@ -811,18 +813,21 @@ } } -char *bt_modul_hc05::search(UART num) +char *bt_modul_hc05::search() { - // bt_modul_hc05::set_modul_role(UART6, MASTER); - bt_modul_hc05::get_modul_init(num); - bt_modul_hc05::set_modul_giac(num, "9e8b33"); - bt_modul_hc05::set_device_class(num, 0); - bt_modul_hc05::set_modul_inquiry(num, "1,5,10"); - return bt_modul_hc05::get_modul_inqm(num); + // + bt_modul_hc05::get_modul_init(); + bt_modul_hc05::set_modul_giac("9e8b33"); + bt_modul_hc05::set_device_class(0); + bt_modul_hc05::set_modul_inquiry("1,5,20"); + return bt_modul_hc05::get_modul_inqm(); } -char *bt_modul_hc05::link_device(UART num, char *address) +char *bt_modul_hc05::link_device(char *address) { - bt_modul_hc05::search_device(num, address); - return bt_modul_hc05::connect_device(num, address); + if(strncmp(bt_modul_hc05::get_modul_role(), "+ROLE:1", 7) == 0) { + bt_modul_hc05::search_device(address); + return bt_modul_hc05::connect_device(address); + } + return '\0'; } \ No newline at end of file