/* ============================================== Function: initialize_all(void) Initialize oscillator, radio, bluetooth, twi and vibration ============================================== */ static void initialize_all() { char buf[30]; // Start 16 MHz crystal oscillator. NRF_CLOCK->EVENTS_HFCLKSTARTED = 0; NRF_CLOCK->TASKS_HFCLKSTART = 1; // oscillator while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) { // busy wait until the oscilator is up and running } simple_uart_config(0, 23, 0, 22, 0); simple_uart_putstring("INIT\n"); // initiliaze radio radio_configure(); simple_uart_putstring("Configured radio\n"); // initialize bluetooth start_ble(MUG_LIST); simple_uart_putstring("BLUETOOTH STARTED\n"); // initialize twi twi_master_init(); simple_uart_putstring("TWI master init\n"); init_vibration(); simple_uart_putstring("Vibration init\n"); }
/** * @brief Function for application main entry. * @return 0. int return type required by ANSI/ISO standard. */ int main(void) { init(); simple_uart_putstring((const uint8_t *)"\n\rPress '0' or '1': "); while(true) { uint8_t c = simple_uart_get(); if (c != '0' && c != '1') continue; simple_uart_put(c); // Place the read character in the payload, enable the radio and // send the packet: packet[0] = c; NRF_RADIO->EVENTS_READY = 0U; NRF_RADIO->TASKS_TXEN = 1; while (NRF_RADIO->EVENTS_READY == 0U) { } NRF_RADIO->TASKS_START = 1U; NRF_RADIO->EVENTS_END = 0U; while(NRF_RADIO->EVENTS_END == 0U) { } NRF_RADIO->EVENTS_DISABLED = 0U; // Disable radio NRF_RADIO->TASKS_DISABLE = 1U; while(NRF_RADIO->EVENTS_DISABLED == 0U) { } } }
static void accel_timeout_handler(void* p_context) { update_xyz(xyz); ble_acc_accel_level_update(&m_acc, swapbytes(xyz[1])); uart_put_dec32bit((uint32_t)xyz[1]); UNUSED_PARAMETER(p_context); simple_uart_putstring((const uint8_t*) "acc\r\n"); }
void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name) { char* buf[32]; sprintf((char*)buf, "ec: %d\nline: %d\n", error_code, line_num); simple_uart_putstring(buf); //NVIC_SystemReset(); }
/** * @brief Function for application main entry. * @return 0. int return type required by ANSI/ISO standard. */ int main(void) { init(); simple_uart_putstring((const uint8_t *)"Press Button 0 or Button 1 on the transmitter\n\r"); while(true) { NRF_RADIO->EVENTS_READY = 0U; // Enable radio and wait for ready NRF_RADIO->TASKS_RXEN = 1U; while(NRF_RADIO->EVENTS_READY == 0U) { } NRF_RADIO->EVENTS_END = 0U; // Start listening and wait for address received event NRF_RADIO->TASKS_START = 1U; // Wait for end of packet while(NRF_RADIO->EVENTS_END == 0U) { } // Write received data to LED0 and LED1 on CRC match if (NRF_RADIO->CRCSTATUS == 1U) { switch(packet[0]) { case 1: simple_uart_putstring((const uint8_t *)"Button 0 pressed\n\r"); break; case 2: simple_uart_putstring((const uint8_t *)"Button 1 pressed\n\r"); break; case 3: simple_uart_putstring((const uint8_t *)"Both buttons pressed\n\r"); break; } } NRF_RADIO->EVENTS_DISABLED = 0U; // Disable radio NRF_RADIO->TASKS_DISABLE = 1U; while (NRF_RADIO->EVENTS_DISABLED == 0U) { } } }
static void ext_sensors_init(void) { ACCEL_INIT(); while(reg_write_ver(CTRL_REG1, 0x97)!=1){ simple_uart_putstring((const uint8_t*)"retrying cr1 tx\r\n"); } while(reg_write_ver(CTRL_REG2, 0x80)!=1){ simple_uart_putstring((const uint8_t*)"retrying cr2 tx\r\n"); } while(reg_write_ver(CTRL_REG4, 0x08)!=1){ simple_uart_putstring((const uint8_t*)"retrying cr4 tx\r\n"); } accel_timeout_handler(NULL); }
void log_uart(const char *format, ...) { va_list args; va_start(args, format); vsnprintf(buffer, BUFFER_LEN, format, args); simple_uart_putstring((const uint8_t *) buffer); va_end(args); }
int reconfig(){ int tx; int ptx; simple_uart_putstring((uint8_t *)"Digte uma nova potencia\n"); ptx = simple_uart_get(); radio_configure(1, (uint32_t)ptx); NRF_RADIO->PACKETPTR = (uint32_t)packet; }
int packet_info(){ simple_uart_putstring((const uint8_t *)"Digite a ID do atleta: \n"); for(int i = 0; i <= 3; i++){ packet[i + 2] = simple_uart_get(); } simple_uart_putstring((const uint8_t *)"Digite a potencia de transmissão: \n"); if(simple_uart_get_with_timeout(10000, &packet[1])){ } else { packet[0] = NRF_RADIO->POWER; } simple_uart_putstring((const uint8_t *)"Digite o intervalo de transmissão: \n"); if(simple_uart_get_with_timeout(10000, &packet[2])){ } else { packet[1] = 200; } simple_uart_putstring((const uint8_t *)"Digite a nova ID: \n"); if(simple_uart_get_with_timeout(10000, &packet[6]) && simple_uart_get_with_timeout(10000, &packet[7]) && simple_uart_get_with_timeout(10000, &packet[8]) && simple_uart_get_with_timeout(10000, &packet[9])){ } else { packet[6] = packet[2]; packet[7] = packet[3]; packet[8] = packet[4]; packet[9] = packet[5]; } }
void parse(int y, int z){ int sum; double dsum, s; dsum = y*y+z*z; sum = sqrt(dsum); char c[30]; sprintf(c,"%d",sum); simple_uart_putstring((const uint8_t *) "\r\n"); simple_uart_putstring((const uint8_t *) c); if(min_val > sum){ state = true; // min } else if(max_val < sum){ state = false; // max } if(!state && prev_state){ jcnt++; } prev_state = state; }
/**@brief Function for adding the Heart Rate Measurement characteristic. * * @param[in] p_hrs Heart Rate Service structure. * @param[in] p_hrs_init Information needed to initialize the service. * * @return NRF_SUCCESS on success, otherwise an error code. */ static uint32_t heart_rate_measurement_char_add(ble_hrs_t * p_hrs, const ble_hrs_init_t * p_hrs_init) { simple_uart_putstring("add heart rate measurement"); ble_gatts_char_md_t char_md; ble_gatts_attr_md_t cccd_md; ble_gatts_attr_t attr_char_value; ble_uuid_t ble_uuid; ble_gatts_attr_md_t attr_md; uint8_t encoded_initial_hrm[MAX_HRM_LEN]; memset(&cccd_md, 0, sizeof(cccd_md)); BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm); cccd_md.write_perm = p_hrs_init->hrs_hrm_attr_md.cccd_write_perm; cccd_md.vloc = BLE_GATTS_VLOC_STACK; memset(&char_md, 0, sizeof(char_md)); char_md.char_props.notify = 1; char_md.p_char_user_desc = NULL; char_md.p_char_pf = NULL; char_md.p_user_desc_md = NULL; char_md.p_cccd_md = &cccd_md; char_md.p_sccd_md = NULL; BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_HEART_RATE_MEASUREMENT_CHAR); memset(&attr_md, 0, sizeof(attr_md)); attr_md.read_perm = p_hrs_init->hrs_hrm_attr_md.read_perm; attr_md.write_perm = p_hrs_init->hrs_hrm_attr_md.write_perm; attr_md.vloc = BLE_GATTS_VLOC_STACK; attr_md.rd_auth = 0; attr_md.wr_auth = 0; attr_md.vlen = 1; memset(&attr_char_value, 0, sizeof(attr_char_value)); attr_char_value.p_uuid = &ble_uuid; attr_char_value.p_attr_md = &attr_md; attr_char_value.init_len = hrm_encode(p_hrs, INITIAL_VALUE_HRM, encoded_initial_hrm); attr_char_value.init_offs = 0; attr_char_value.max_len = MAX_HRM_LEN; attr_char_value.p_value = encoded_initial_hrm; return sd_ble_gatts_characteristic_add(p_hrs->service_handle, &char_md, &attr_char_value, &p_hrs->hrm_handles); }
//reads a String from the terminal (until the user has pressed ENTER) //offset can be set to a value above 0 if the readBuffer already contains text void Terminal::ReadlineUART(char* readBuffer, u8 readBufferLength, u8 offset) { #ifdef ENABLE_TERMINAL if (!terminalIsInitialized) return; u8 byteBuffer; u8 counter = offset; //Read in an infinite loop until \r is recognized while (true) { //Read from terminal byteBuffer = simple_uart_get(); //BACKSPACE if (byteBuffer == 127) { if (counter > 0) { //Output Backspace if(promptAndEchoMode) simple_uart_put(byteBuffer); readBuffer[counter - 1] = 0; counter--; } //ALL OTHER CHARACTERS } else { //Display entered character in terminal if(promptAndEchoMode) simple_uart_put(byteBuffer); if (byteBuffer == '\r' || counter >= readBufferLength || counter >= 250) { readBuffer[counter] = '\0'; if(promptAndEchoMode) simple_uart_putstring((const u8*) EOL); break; } else { memcpy(readBuffer + counter, &byteBuffer, sizeof(u8)); } counter++; } } #endif }
/**@brief Function for error handling, which is called when an error has occurred. * * @warning This handler is an example only and does not fit a final product. You need to analyze * how your product is supposed to react in case of error. * * @param[in] error_code Error code supplied to the handler. * @param[in] line_num Line number where the handler is called. * @param[in] p_file_name Pointer to the file name. */ void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name) { nrf_gpio_pin_set(ASSERT_LED_PIN_NO); // This call can be used for debug purposes during application development. // @note CAUTION: Activating this code will write the stack to flash on an error. // This function should NOT be used in a final product. // It is intended STRICTLY for development/debugging purposes. // The flash write will happen EVEN if the radio is active, thus interrupting // any communication. // Use with care. Un-comment the line below to use. // ble_debug_assert_handler(error_code, line_num, p_file_name); // On assert, the system can only recover with a reset. simple_uart_putstring((const uint8_t*) "app error\r\n"); simple_uart_putstring(p_file_name); simple_uart_putstring((const uint8_t*) "\r\n"); uart_put_dec32bit(line_num); simple_uart_putstring((const uint8_t*) "\r\n"); uart_put_dec32bit(error_code); simple_uart_putstring((const uint8_t*) "\r\n"); NVIC_SystemReset(); }
/**@brief Logging function, used for formated output on the UART. */ void test_logf(const char *fmt, ...) { int16_t res = 0; static uint8_t buf[150]; va_list args; va_start(args, fmt); res = vsnprintf((char*) buf, sizeof(buf), fmt, args); ASSERT(res >= 0 && res <= (sizeof buf) - 1); simple_uart_putstring(buf); va_end(args); }
/** * @brief Function for application main entry. * @return 0. int return type required by ANSI/ISO standard. */ int main(void) { const uint8_t *key_packet; uint8_t key_packet_size; #ifdef USE_UART simple_uart_config(0, SIMPLE_UART_TXD_PIN_NUMBER, 0, SIMPLE_UART_RXD_PIN_NUMBER, false); // Hardware flow control not used in this example. #else // Configure pins 24-30 for LEDs. Note that pin 31 is not connected. nrf_gpio_range_cfg_output(24, 30); #endif // Enable pulldowns on row port, see matrix_row_port. nrf_gpio_range_cfg_input(16, 23, NRF_GPIO_PIN_PULLDOWN); // Column pin configuration, see matrix_column_port. nrf_gpio_range_cfg_output(0, 15); if (cherry8x16_init(matrix_row_port, matrix_column_port, CHERRY8x16_DEFAULT_KEY_LOOKUP_MATRIX) != CHERRY8x16_OK) { #ifdef USE_UART simple_uart_putstring((const uint8_t *)"Init failed."); #else nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT3, 0x55); #endif while (true) { // Do nothing. } } while(true) { if (cherry8x16_new_packet(&key_packet, &key_packet_size)) { #ifdef USE_UART // Send the whole key packet over UART. uart_puthidstring((char*)&key_packet[KEY_PACKET_KEY_INDEX]); #else // Show modifier key state using the LEDs. Note LED's use GPIO pins from 8 to 15. nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT3, key_packet[KEY_PACKET_MODIFIER_KEY_INDEX]); #endif } nrf_delay_ms(25); } }
static void send_string(max30100_sample_t sample){ int i; uint8_t red[20]; uint8_t infrared[20]; uint32_t err_code; sprintf(infrared, "%d\r\n", sample.ir); err_code = ble_nus_send_string(&m_nus, infrared, strlen(infrared)); if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_INVALID_STATE)&& (err_code != BLE_ERROR_NO_TX_BUFFERS)&& (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)) { APP_ERROR_HANDLER(err_code); } simple_uart_putstring(infrared); }
uint32_t ble_hrs_init(ble_hrs_t * p_hrs, const ble_hrs_init_t * p_hrs_init) { simple_uart_putstring("Heart rate service initialised"); uint32_t err_code; ble_uuid_t ble_uuid; // Initialize service structure p_hrs->evt_handler = p_hrs_init->evt_handler; p_hrs->is_sensor_contact_supported = p_hrs_init->is_sensor_contact_supported; p_hrs->conn_handle = BLE_CONN_HANDLE_INVALID; p_hrs->is_sensor_contact_detected = false; p_hrs->rr_interval_count = 0; // Add service BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_HEART_RATE_SERVICE); err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_hrs->service_handle); if (err_code != NRF_SUCCESS) { return err_code; } // Add heart rate measurement characteristic err_code = heart_rate_measurement_char_add(p_hrs, p_hrs_init); if (err_code != NRF_SUCCESS) { return err_code; } if (p_hrs_init->p_body_sensor_location != NULL) { // Add body sensor location characteristic err_code = body_sensor_location_char_add(p_hrs, p_hrs_init); if (err_code != NRF_SUCCESS) { return err_code; } } return NRF_SUCCESS; }
void DbgPrintf( const char * format, ... ) { // int ret=0; #if DEBUG_UART_EN #ifndef ENABLE_SIMPLE_UART //kevin add /* char tx_buf[256]; int msg_len,len; va_list args; va_start(args, format); msg_len = vsprintf(tx_buf, format, args); va_end(args); for(len=0;len<msg_len;len++) { simple_uart_put(tx_buf[len]); //while(app_uart_put(tx_buf[len]) != NRF_SUCCESS); //simple_uart_put(tx_buf[len]); }*/ #else #if ENABLE_COS char tx_buf[256]; //int msg_len,len; va_list args; va_start(args, format); vsprintf(tx_buf, format, args); va_end(args); simple_uart_putstring((const uint8_t *)tx_buf); //simple_uart_putstringbuff(tx_buf,msg_len); #endif #endif #endif // return ret; }
/**@brief Application main function. */ int main(void) { // Initialize leds_init(); timers_init(); buttons_init(); uart_init(); ble_stack_init(); device_manager_init(); gap_params_init(); services_init(); advertising_init(); conn_params_init(); simple_uart_putstring(START_STRING); advertising_start(); // Enter main loop for (;;) { power_manage(); } }
int main(){ initialize_all(); char buf[30]; uint8_t uart_data; // Print Device ID uint64_t this_device_id = (((uint64_t) NRF_FICR->DEVICEID[1] << 32) | ((uint64_t) NRF_FICR->DEVICEID[0])); sprintf((char*)buf, "ID: %llx\n", this_device_id); simple_uart_putstring(buf); uint8_t availability; bool radio_executed = false; // main application loop while (1) { //All the mugs that will be invited have been set if (is_connected()) { // Deal with radios sd_softdevice_disable(); radio_configure(); // simple_uart_putstring("Configured radio\n"); // simple_uart_putstring("Disabled soft device\n"); // END - Deal with radios bool disovery_complete = false; bool all_final_state = true; int8_t current_mug = 0; while (!disovery_complete){ uint64_t device_id = 0; // vibration_update(); if (receive_packet(20)){ device_id = packet[1]; if (this_device_id == device_id){ if (packet[0] == 0xcfcf){ // Master init sequence simple_uart_putstring("Got init!\n"); packet[0] = 0xaf; // Send ACK to Master send_packet(1); // ... 3 times ... simple_uart_putstring("[a]ccept or [r]eject:\n"); uart_data = simple_uart_get(); switch (uart_data) { case 'a': availability = 0xaa; simple_uart_putstring("Accepted\n"); break; case 'r': availability = 0xff; simple_uart_putstring("Rejected\n"); break; } uart_data = simple_uart_get(); } else if (packet[0] == 0xabab) { // Master poll availability simple_uart_putstring("Sent availability status!\n"); packet[0] = availability; // Send ACK to Master send_packet(1); } else if (packet[0] == 0xdede) { // Master kettle boiling simple_uart_putstring("Got invitation!\n"); packet[0] = 0xaf; // Send ACK to Master send_packet(1); // ... 3 times ... for (uint8_t i=0; i<100; i++){ nrf_gpio_pin_toggle(0); nrf_delay_ms(200); } } else { sprintf((char*)buf, "Brocken command: %llx\n", packet[0]); simple_uart_putstring(buf); } } else { simple_uart_putstring("Not applicable packet\n"); sprintf((char*)buf, "Target: %llx\n", packet[1]); simple_uart_putstring(buf); sprintf((char*)buf, "Command: %llx\n", packet[0]); simple_uart_putstring(buf); } } if (bump_action()) { disovery_complete = true; // uint8_t bump_evt = 1; // ble_update_bump(&bump_evt) } } // Deal with radios sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_RC_250_PPM_1000MS_CALIBRATION,app_error_handler); // simple_uart_putstring("Enabled soft device\n"); // END - Deal with radios // uint8_t bump_val = 1; // ble_update_bump(&bump_val); // simple_uart_putstring("They see me bumpin', I see 'em hatin'!\n"); disovery_complete = false; // RSVP_App(); //sends MUG information back to app via ble, defined in slip_ble.c } //debug_ble_ids(); // vibration_update(); app_sched_execute(); nrf_delay_ms(500); } }
/**@brief Function for application main entry. */ int main(void) { // Initialize app_trace_init(); simple_uart_putstring((const uint8_t*) "trace init\r\n"); leds_init(); simple_uart_putstring((const uint8_t*) "leds init\r\n"); timers_init(); simple_uart_putstring((const uint8_t*) "timers init\r\n"); gpiote_init(); simple_uart_putstring((const uint8_t*) "gpiote init\r\n"); buttons_init(); simple_uart_putstring((const uint8_t*) "buttons init\r\n"); ble_stack_init(); simple_uart_putstring((const uint8_t*) "stack init\r\n"); scheduler_init(); simple_uart_putstring((const uint8_t*) "schedler init\r\n"); gap_params_init(); simple_uart_putstring((const uint8_t*) "gap init\r\n"); advertising_init(); simple_uart_putstring((const uint8_t*) "adv init\r\n"); services_init(); simple_uart_putstring((const uint8_t*) "services init\r\n"); conn_params_init(); simple_uart_putstring((const uint8_t*) "conn init\r\n"); sec_params_init(); simple_uart_putstring((const uint8_t*) "sec init\r\n"); ext_sensors_init(); simple_uart_putstring((const uint8_t*) "ext init\r\n"); // lfclk_config(); // simple_uart_putstring((const uint8_t*) "lfk init\r\n"); // Start execution timers_start(); advertising_start(); simple_uart_putstring((const uint8_t*) "main\r\n"); // Enter main loop for (;;) { app_sched_execute(); power_manage(); } }
/** * @brief Function for application main entry. */ int main(void) { uint8_t data; bool who_am_i; bool init = true; nrf_gpio_cfg_output (LED_0); nrf_gpio_cfg_output (LED_1); nrf_gpio_pin_set(LED_0); simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, HWFC); simple_uart_putstring((const uint8_t *)" \r\nStart I2C \r\n"); nrf_delay_ms(500); if(!twi_master_init()){ while (true) { nrf_gpio_pin_set(LED_0); nrf_delay_ms(500); nrf_gpio_pin_clear(LED_0); nrf_delay_ms(500); } } nrf_gpio_pin_set(LED_1); nrf_gpio_pin_clear(LED_0); who_am_i = read_register(MMA8452_ADDRESS << 1,WHO_AM_I,&data); if(who_am_i){ //data == 0x2A nrf_delay_us(100); write_register(MMA8452_ADDRESS << 1,XYZ_DATA_CFG, 0x02); nrf_delay_us(100); write_register(MMA8452_ADDRESS << 1,CTRL_REG1, 0x33); nrf_gpio_pin_clear(LED_1); nrf_gpio_pin_set(LED_0); char c[30]; sprintf(c,"%d",data); simple_uart_putstring((const uint8_t *) "\r\n WHO_AM_I : "); simple_uart_putstring((const uint8_t *) c); data = '0'; simple_uart_putstring((const uint8_t *) "\r\nMMA8452Q is online..."); } else{ nrf_gpio_pin_clear(LED_0); nrf_gpio_pin_clear(LED_1); simple_uart_putstring((const uint8_t *) "\r\nMMA8452Q is offline..."); } short int x[3]; while(1){ readAccelData(x); float accelG[3]; // Stores the real accel value in g's for (int i = 0 ; i < 3 ; i++) { // accelG[i] = (float) x[i] / ((1<<12)/(2*GSCALE)); // get actual g value, this depends on scale being set accelG[i] = (float) x[i] / 256; // get actual g value, this depends on scale being set accelG[i] *= 10; } // int a = accelG[1]*10; // int b = accelG[2]*10; //// parse(a,b); // char c[30]; sprintf(c,"%d",x[0]); simple_uart_putstring((const uint8_t *) "\r\n"); simple_uart_putstring((const uint8_t *) c); sprintf(c,"%d",x[1]); simple_uart_putstring((const uint8_t *) " "); simple_uart_putstring((const uint8_t *) c); sprintf(c,"%d",x[2]); simple_uart_putstring((const uint8_t *) " "); simple_uart_putstring((const uint8_t *) c); } }
int main(void) { // Start 16 MHz crystal oscillator. NRF_CLOCK->EVENTS_HFCLKSTARTED = 0; NRF_CLOCK->TASKS_HFCLKSTART = 1; // Wait for the external oscillator to start up. while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) {} // Enable UART comms simple_uart_config(0, 23, 0, 22, 0); unsigned char buf[32]; uint8_t uart_data; // Enable LED nrf_gpio_cfg_output(0); // Set radio configuration parameters. radio_configure(); // Print Device ID uint64_t this_device_id = (((uint64_t) NRF_FICR->DEVICEID[1] << 32) | ((uint64_t) NRF_FICR->DEVICEID[0])); sprintf((char*)buf, "ID: %llx\n", this_device_id); simple_uart_putstring(buf); // Initialise LibAlek // init_vibration(); uint8_t availability; while(true){ uint64_t device_id = 0; // vibration_update(); if (receive_packet()){ device_id = packet[1]; if (this_device_id == device_id){ if (packet[0] == 0xcfcf){ // Master init sequence simple_uart_putstring("Got init!\n"); packet[0] = 0xaf; // Send ACK to Master send_packet(1); // ... 3 times ... simple_uart_putstring("[a]ccept or [r]eject:\n"); uart_data = simple_uart_get(); switch (uart_data) { case 'a': availability = 0xaa; simple_uart_putstring("Accepted\n"); break; case 'r': availability = 0xff; simple_uart_putstring("Rejected\n"); break; } uart_data = simple_uart_get(); } else if (packet[0] == 0xabab) { // Master poll availability simple_uart_putstring("Sent availability status!\n"); packet[0] = availability; // Send ACK to Master send_packet(1); } else if (packet[0] == 0xdede) { // Master kettle boiling simple_uart_putstring("Got invitation!\n"); packet[0] = 0xaf; // Send ACK to Master send_packet(1); // ... 3 times ... for (uint8_t i=0; i<100; i++){ nrf_gpio_pin_toggle(0); nrf_delay_ms(200); } } else { sprintf((char*)buf, "Brocken command: %llx\n", packet[0]); simple_uart_putstring(buf); } } else { simple_uart_putstring("Not applicable packet\n"); sprintf((char*)buf, "Target: %llx\n", packet[1]); simple_uart_putstring(buf); sprintf((char*)buf, "Command: %llx\n", packet[0]); simple_uart_putstring(buf); } } } }
/** Sends 'Start: ' string to UART. Execution is blocked until UART peripheral detects all characters have been sent. */ static __INLINE void uart_start() { simple_uart_putstring((const uint8_t *)" \n\rStart: "); }
//Initialize the mhTerminal void Terminal::Init() { #ifdef ENABLE_TERMINAL registeredCallbacks = new SimplePushStack(MAX_TERMINAL_COMMAND_LISTENER_CALLBACKS); //Start UART communication simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, HWFC); char versionString[15]; Utility::GetVersionStringFromInt(Config->firmwareVersion, versionString); if (promptAndEchoMode) { //Send Escape sequence simple_uart_put(27); //ESC simple_uart_putstring((const u8*) "[2J"); //Clear Screen simple_uart_put(27); //ESC simple_uart_putstring((const u8*) "[H"); //Cursor to Home //Send App start header simple_uart_putstring((const u8*) "--------------------------------------------------" EOL); simple_uart_putstring((const u8*) "Terminal started, compile date: "); simple_uart_putstring((const u8*) __DATE__); simple_uart_putstring((const u8*) " "); simple_uart_putstring((const u8*) __TIME__); simple_uart_putstring((const u8*) ", version: "); simple_uart_putstring((const u8*) versionString); #ifdef NRF52 simple_uart_putstring((const u8*) ", nRF52"); #else simple_uart_putstring((const u8*) ", nRF51"); #endif simple_uart_putstring((const u8*) EOL "--------------------------------------------------" EOL); } terminalIsInitialized = true; #endif }
void readAccelData(short int *destination) { uint8_t rawData[6]; // x/y/z accel register data stored here bool init = true; init &= read_registers(MMA8452_ADDRESS << 1,OUT_X_MSB, 6, rawData); // Read the six raw data registers into data array // ACC_getdata(rawData); nrf_delay_ms(1); char c[30]; sprintf(c,"%d",rawData[0]); simple_uart_putstring((const uint8_t *) "\r\n"); simple_uart_putstring((const uint8_t *) c); sprintf(c,"%d",rawData[1]); simple_uart_putstring((const uint8_t *) " "); simple_uart_putstring((const uint8_t *) c); sprintf(c,"%d",rawData[2]); simple_uart_putstring((const uint8_t *) " "); simple_uart_putstring((const uint8_t *) c); sprintf(c,"%d",rawData[3]); simple_uart_putstring((const uint8_t *) " "); simple_uart_putstring((const uint8_t *) c); sprintf(c,"%d",rawData[4]); simple_uart_putstring((const uint8_t *) " "); simple_uart_putstring((const uint8_t *) c); sprintf(c,"%d",rawData[5]); simple_uart_putstring((const uint8_t *) " "); simple_uart_putstring((const uint8_t *) c); // Loop to calculate 12-bit ADC and g value for each axis for(int i = 0; i < 3 ; i++) { short int gCount = (rawData[i*2] << 8) | rawData[(i*2)+1]; //Combine the two 8 bit registers into one 12-bit number gCount = gCount >> 4; //The registers are left align, here we right align the 12-bit integer // // If the number is negative, we have to make it so manually (no 12-bit data type) if (rawData[i*2] > 0x7F) { gCount = ~gCount + 1; gCount *= -1; // Transform into negative 2's complement # } destination[i] = gCount; //Record this gCount into the 3 int array } }
void Terminal::PollUART() { #ifdef ENABLE_TERMINAL if (!terminalIsInitialized) return; static char readBuffer[250] = { 0 }; static char testCopy[250] = {0}; readBuffer[0] = 0; if (simple_uart_get_with_timeout(0, (u8*) readBuffer)) { //Output query string and typed symbol to terminal if (promptAndEchoMode) { simple_uart_putstring((const u8*) EOL "mhTerm: "); //Display prompt simple_uart_put(readBuffer[0]); //echo back symbol } //Read line from uart ReadlineUART(readBuffer, 250, 1); //FIXME: remove after finding problem memcpy(testCopy, readBuffer, 250); //Clear previous command commandName.clear(); commandArgs.clear(); //Tokenize input string into vector char* token = strtok(readBuffer, " "); if (token != NULL) commandName.assign(token); while (token != NULL) { token = strtok(NULL, " "); if (token != NULL) commandArgs.push_back(string(token)); } //Check for clear screen if (commandName == "cls") { //Send Escape sequence simple_uart_put(27); //ESC simple_uart_putstring((const u8*) "[2J"); //Clear Screen simple_uart_put(27); //ESC simple_uart_putstring((const u8*) "[H"); //Cursor to Home } else { //Call all callbacks int handled = 0; for(u32 i=0; i<registeredCallbacks->size(); i++){ handled += ((TerminalCommandListener*)registeredCallbacks->GetItemAt(i))->TerminalCommandHandler(commandName, commandArgs); } if (handled == 0){ if(promptAndEchoMode){ simple_uart_putstring((const u8*)"Command not found" EOL); } else { uart_error(Logger::COMMAND_NOT_FOUND); } //FIXME: to find problems with uart input uart("ERROR", "{\"user_input\":\"%s\"}" SEP, testCopy); } } } #endif }
/** Sends ' Exit!' string to UART. Execution is blocked until UART peripheral detects all characters have been sent. */ static __INLINE void uart_quit() { simple_uart_putstring((const uint8_t *)" \n\rExit!\n\r"); }