serqet2

Dependencies:   BLE_API circular_buffer mbed nRF51822

Fork of serqet by Serqet

Revision:
9:b527643b8c93
Parent:
8:7a3b7d1c8393
Child:
10:a9db6fc55f1a
--- a/main.cpp	Tue Mar 24 02:41:05 2015 +0000
+++ b/main.cpp	Tue Mar 24 21:43:55 2015 +0000
@@ -49,6 +49,7 @@
 uint8_t averaging_amount = 1;
 uint8_t time_shift_value = 0;
 uint8_t time_range_value = 0;
+bool trigger_sign = 1; // 0 is negative, 1 is positive
 
 BLEDevice  ble;
 
@@ -62,7 +63,7 @@
 DigitalOut      POS_OFFSET_EN(POS_OFFSET_EN_PIN);
 DigitalOut      STATUS_LED(STATUS_LED_PIN);
 
-//Serial pc(USBTX, USBRX);
+Serial pc(USBTX, USBRX);
 
 // The Nordic UART Service
 static const uint8_t uart_base_uuid[] = {0x71, 0x3D, 0, 0, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
@@ -89,8 +90,8 @@
 
 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
 {
-    //pc.printf("Disconnected \r\n");
-    //pc.printf("Restart advertising \r\n");
+    pc.printf("Disconnected \r\n");
+    pc.printf("Restart advertising \r\n");
     ble.startAdvertising();
 }
 
@@ -106,35 +107,17 @@
 
         //for(index=0; index<bytesRead; index++)
         //pc.putc(buf[index]);
-
-        if(buf[0] == COUPLING_SETTING) {
-            coupling_type = buf[1];
-            if (coupling_type == AC_COUPLING) {
-                AC_EN = 1;
-                DC_EN = 0;
-            } else // DC coupling
-                AC_EN = 0;
-            DC_EN = 1;
-        }
-    } else if(buf[0] == TRIGGER_DIR_SETTING) {
-        trigger_dir = buf[1];
-    } else if(buf[0] == AVERAGING_SETTING) {
-        averaging_amount = buf[0];
-    } else if(buf[0] == TIME_SHIFT_SETTING) {
-        time_shift_value = buf[1];
-    } else if(buf[0] == TIME_RANGE_SETTING) {
-        time_range_value = buf[1];
-    } else if(buf[0] == OFFSET_SETTING) {
+        
+        coupling_type = (bool) buf[0];
         offset_value = buf[1];
-        if (offset_dir == POS_OFFSET) { // postitive offset
-            NEG_OFFSET_EN = 0;
-            POS_OFFSET_EN = 1;
-        } else { // negative offset
-            NEG_OFFSET_EN = 1;
-            POS_OFFSET_EN = 0;
-        }
-    } else if(buf[0] == TRIGGER_VALUE_SETTING) {
-        trigger_level = buf[1];
+        trigger_dir = (bool) buf[2];
+        trigger_level = buf[3];
+        averaging_amount = buf[4];
+        voltage_range = buf[5];
+        time_shift_value = buf[6];
+        time_range_value = buf[7];
+        offset_dir = (bool) buf[8];
+        trigger_sign = (bool) buf[9];
     }
 }
 
@@ -148,7 +131,8 @@
     return (current_sample > trigger_level && previous_sample < trigger_level);
 }
 
-bool is_triggered (uint8_t current_sample, uint8_t previous_sample, bool dir) {
+bool is_triggered (uint8_t current_sample, uint8_t previous_sample, bool dir)
+{
     if (dir == RISING_EDGE) {
         return is_rising_edge (current_sample, previous_sample);
     } else {
@@ -156,6 +140,16 @@
     }
 }
 
+void m_test_handle(void)
+{
+    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);
+
+}
+
 #define VOLTAGE_BUFFER_SIZE 1024
 circular_buffer<uint8_t> voltage_buffer(VOLTAGE_BUFFER_SIZE);
 uint8_t out_buf[VOLTAGE_BUFFER_SIZE];
@@ -186,69 +180,40 @@
         }
         prev_sample = sample;
     }
-    }
-
-    int main(void) {
-        Ticker ticker;
-        ticker.attach_us(m_status_check_handle, 1000);
-
-        ble.init();
-        ble.onDisconnection(disconnectionCallback);
-        ble.onDataWritten(WrittenHandler);
-
-        //pc.baud(9600);
-        //pc.printf("SimpleChat Init \r\n");
-
-        //pc.attach( uartCB , pc.RxIrq);
+}
 
-        // setup advertising
-        //ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
-        ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
-        ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
-                                         (const uint8_t *)"Serqet", sizeof("Serqet") - 1);
-        ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
-                                         (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid));
-        // 100ms; in multiples of 0.625ms.
-        ble.setAdvertisingInterval(160);
-
-        ble.addService(uartService);
-
-        ble.startAdvertising();
-
-        //pc.printf("Advertising Start \r\n");
+int main(void)
+{
+    Ticker ticker;
+//    ticker.attach_us(m_status_check_handle, 1000);
+    ticker.attach_us(m_test_handle, 100000);
+    ble.init();
+    ble.onDisconnection(disconnectionCallback);
+    ble.onDataWritten(WrittenHandler);  
+    
+    pc.baud(9600);
+    pc.printf("serqet Init \r\n");
 
-        while(1) {
-            ble.waitForEvent();
-        }
-    }
-
-
-
-
-
-
-
-
-
-
-
-
-
+    //pc.attach( uartCB , pc.RxIrq);
+    
+    // setup advertising 
+    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
+    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
+    ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
+                                    (const uint8_t *)"Serqet", sizeof("Serqet") - 1);
+    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
+                                    (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid));
+    // 100ms; in multiples of 0.625ms. 
+    ble.setAdvertisingInterval(160);
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+    ble.addService(uartService);
+    
+    ble.startAdvertising(); 
+    
+    //pc.printf("Advertising Start \r\n");
+    
+    while(1)
+    {
+        ble.waitForEvent(); 
+    }
+}