void handle_input(uint8 type) { /* check click times */ if (ClickNum > MAX_INPUT) { if (type != LETTER || type != WORD) reset_buff(); beer(WARN); return; } if (type == DOT || type ==DASH) { beer(type); /* the ascii of '\0' is equal to number zero it may cause some trouble */ buff[ClickNum++] = type + 1; return; } if (type == LETTER || type == WORD) { buff[ClickNum] = '\0'; /* decoding*/ for (p = &letter_a;p != NULL;p = p->next) { if (strcmp(buff,p->morse_mask) == 0) { /* send */ uart_send_byte(p->output); if (type == WORD) uart_send_byte(SPACE); reset_buff(); return; } } /* not match */ reset_buff(); beer(WARN); } }
void main() { Display_Init(); MCU_Init(); #ifdef INIT_BLE BLE_Init(); delay_ms(2000); #else RN_WAKE = 1; wait_response("CMD"); #endif DrawFrame(); InitTimer2(); while(1) { if(data_ready) { //If characteristic is configured as write //received messages come here Display_Message(); reset_buff(); } else { //Test: every 5sec increase baterry level (0 to 100%) //and send value via Bluetooth Low Energy if (tmr_flg) { batt_level++; if(batt_level > 100) { batt_level = 0; } Display_BatteryLevel(); if(RN_CONN) { //send battery level value if BLE connected shorttohex(batt_level, batt_level_txt); ltrim(batt_level_txt); ble2_write_server_characteristic_value_via_UUID("2A19",batt_level_txt); } tmr_flg = 0; } } } }