Felipe Araujo
/
Bluetooth_HC-06
Bluetooth
Fork of Bluetooth_HC-06 by
Diff: main.cpp
- Revision:
- 1:8b636701917b
- Parent:
- 0:feba469f2cf1
--- a/main.cpp Tue Nov 05 00:44:19 2013 +0000 +++ b/main.cpp Sun Jun 24 18:32:10 2018 +0000 @@ -1,17 +1,78 @@ -// Bluetooth HC-06 may work for HC-05 (I didn't try - check https://mbed.org/users/edodm85/notebook/HC-05-bluetooth/) +// Bluetooth HC-06 may work for HC-05 (I didn't try - check https://mbed.org/users/edodm85/notebook/HC-05-bluetooth/) // Use pins (RXD - PTC4, TXD - PTC3) on FRDM-KL25Z // Use both USBs to power the HC-06 (J9_12 - GND, J9_10 - 5V usb(VCC)) +#define NUM_PASS 11 + #include "mbed.h" - -Serial HC06(PTC4,PTC3); - -int main() { - HC06.baud(9600); - HC06.printf("Press 'r'\n"); - while (1) { - char c = HC06.getc(); - if(c == 'r') { - HC06.printf("Hello World\n"); - } + +// Protótipos de funções +bool verificaSenha(char password[], char password_digitado[]); +void cadastrarSenha(char password_repeat1[], char password_repeat2[], char password[]); +void cadastrarRfid(); + +Serial blue(p9, p10); + +int main() +{ + bool a; + char password[NUM_PASS] = "thomazlixo"; + char key,key2,password_digitado[NUM_PASS], password_repeat1[NUM_PASS], password_repeat2[NUM_PASS]; + blue.baud(9600); + while (1) + { + do + { + blue.printf("E - Entrar C - Cadastrar Senha R - Cadastrar RFID P - Sair \n"); + key = blue.getc(); + switch (key) + { + case 'E': + a = verificaSenha(password, password_digitado); + if(a){ + // Verificar se a trava está fechada + + + } + //TODO trava e sensor prox + break; + case 'C': + cadastrarSenha(password_repeat1,password_repeat2,password); + break; + case 'R': + cadastrarRfid(); + } + + } while (key != 'P' || key2 != 'P'); } -} \ No newline at end of file +} + +bool verificaSenha(char password[], char password_digitado[]) +{ + bool a; + blue.printf("Digite a senha:\n"); + blue.scanf("%s", password_digitado); + if (strcmp(password, password_digitado) == 0) + { + blue.printf("Senha Correta! :D\n"); + a = true; + } + else + { + blue.printf("Senha incorreta! Tente Novamente... \n"); + a = false; + } + return a; +} + +void cadastrarSenha(char password_repeat1[], char password_repeat2[], char password[]) +{ + blue.printf("Informe a nova senha: \n"); + blue.scanf("%s", password_repeat1); + blue.printf("Repita a senha: \n"); + blue.scanf("%s", password_repeat2); + if (strcmp(password_repeat2, password_repeat1) == 0) + { + strcpy(password, password_repeat1); + blue.printf("Senha cadastrada com sucesso!!"); + } +}