serqet2
Dependencies: BLE_API circular_buffer mbed nRF51822
Fork of serqet by
Diff: main.cpp
- Revision:
- 11:d54f92efbe70
- Parent:
- 10:a9db6fc55f1a
- Child:
- 12:7df0f60cf9e5
--- a/main.cpp Tue Mar 24 22:33:50 2015 +0000 +++ b/main.cpp Tue Mar 24 22:59:40 2015 +0000 @@ -12,14 +12,15 @@ //#define DIGITAL_IN_PIN P0_10 //CTS //#define ANALOG_IN_PIN P0_4 //P04 -#define AC_EN_PIN P0_19 //FIXFIXFIXTHIS back // P0_4 +#define AC_EN_PIN P0_4 +#define testLED P0_19 #define DC_EN_PIN P0_5 #define PAIRING_LED_PIN P0_7 #define BYPASS_ADC_PIN P0_4 #define PAIRING_BUTTON_PIN P0_15 #define POS_OFFSET_EN_PIN P0_29 #define NEG_OFFSET_EN_PIN P0_28 -#define STATUS_LED_PIN P0_11 +#define STATUS_LED_PIN P0_19//P0_11 #define RESET_PIN P0_9 #define COUPLING_SETTING 0x1 @@ -147,12 +148,14 @@ void m_test_handle(void) { + static bool sw = false; + sw = !sw; uint8_t buf[20]; for (int i = 0; i < 20; i++) { buf[i] = (uint8_t)(sin(3.14*i/20)*255); } ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), buf, 20); - + STATUS_LED = sw; } #define VOLTAGE_BUFFER_SIZE 512 @@ -161,13 +164,18 @@ void send_buffer_handle(void) { - for (int i = 0; i < TXRX_BUF_LEN || voltage_buffer.get_size() == 0; i++) { + for (int i = 0; i < TXRX_BUF_LEN; i++) { + if (voltage_buffer.get_size() == 0) { + break; + } out_buf[i] = voltage_buffer.front(); voltage_buffer.pop_front(); } ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), out_buf, TXRX_BUF_LEN); - + // pc.printf("sent 20, %d left\n\r", voltage_buffer.get_size()); + if (voltage_buffer.get_size() == 0) { + pc.printf("done sending\n\r"); ticker.detach(); ticker.attach_us(read_analog_handle, 10000); } @@ -182,19 +190,19 @@ float s = ANALOG; uint8_t sample = s*255; voltage_buffer.push_back(sample); - // pc.printf("sampled, %d. %d samples in buffer\r\n", sample, voltage_buffer.get_size()); + // pc.printf("sampled, %d. %d samples in buffer\r\n", sample, voltage_buffer.get_size()); if (((voltage_buffer.get_size() == VOLTAGE_BUFFER_SIZE) && (is_triggered(sample, prev_sample, trigger_dir)))) { - // pc.printf("triggered, %d\n", sample); + pc.printf("triggered, %d\n", sample); // //if (time_shift < time_shift_value) { // is_shifting = true; // time_shift++; //} else { - + ticker.detach(); - ticker.attach_us(send_buffer_handle, 1000); + ticker.attach_us(send_buffer_handle, 10000); // } } @@ -203,8 +211,8 @@ int main(void) { - ticker.attach_us(read_analog_handle, 10000); - // ticker.attach_us(m_test_handle, 100000); + // ticker.attach_us(read_analog_handle, 10000); + ticker.attach_us(m_test_handle, 1000000); ble.init(); ble.onDisconnection(disconnectionCallback); ble.onDataWritten(WrittenHandler);