AirConLibに対応したMSC
Dependencies: BLE_API mbed nRF51822
Fork of nRF51822_SimpleChat_LED_kai by
Diff: main.cpp
- Revision:
- 8:8962bcb7ddc4
- Parent:
- 7:fbaa5e70a60e
--- a/main.cpp Fri Jan 06 07:24:16 2017 +0000 +++ b/main.cpp Sun Feb 12 10:34:03 2017 +0000 @@ -49,12 +49,16 @@ //#define TX_POWER_CALI -10 //const static char DEVICE_NAME[] = "nRF51DK"; // change this -#define TX_POWER_CALI -7 -const static char DEVICE_NAME[] = "51822"; // change this +//#define TX_POWER_CALI -7 +//const static char DEVICE_NAME[] = "51822"; // change this //#define TX_POWER_CALI -15 //const static char DEVICE_NAME[] = "Nano"; // change this +#define TX_POWER_CALI -10 +const static char DEVICE_NAME[] = "MN4"; // change this + + //反映してない 二箇所設定変更する場所ある //static int tx_power = TX_POWER + TX_POWER_CALI; @@ -66,6 +70,9 @@ DigitalOut ledori1(LED1); //DFUService dfu(ble); +PwmOut servo1(P0_23); +//DigitalOut tran(P0_19); + // 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}; static const uint8_t uart_tx_uuid[] = {0x71, 0x3D, 0, 3, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; @@ -83,14 +90,14 @@ uint8_t mscPayload[TXRX_BUF_LEN] = {0,}; static uint8_t msc_buf[TXRX_BUF_LEN]; static uint8_t msc_len=0; -GattCharacteristic mscCharacteristic (msc_uuid, mscPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); //tx power characteristic +GattCharacteristic mscCharacteristic (msc_uuid, mscPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ); //tx power characteristic // TX POWER用 static const uint8_t power_level_uuid[] = {0x71, 0x3D, 0, 4, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; //central_TxPower受信用 uint8_t powerPayload[TXRX_BUF_LEN] = {0,}; static uint8_t power_buf[TXRX_BUF_LEN]; static uint8_t power_len=0; -GattCharacteristic txPowerCharacteristic (power_level_uuid, powerPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); //tx power characteristic +GattCharacteristic txPowerCharacteristic (power_level_uuid, powerPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ); //tx power characteristic Ticker txSteper; //Feature UUID @@ -98,7 +105,7 @@ uint8_t featurePayload[TXRX_BUF_LEN] = {0,}; static uint8_t feature_buf[TXRX_BUF_LEN]; static uint8_t feature_len=0; -GattCharacteristic featureCharacteristic (feature_uuid, featurePayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); //tx power characteristic +GattCharacteristic featureCharacteristic (feature_uuid, featurePayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ); //tx power characteristic // Tx Power Service @@ -122,7 +129,7 @@ //Uart Service associated GattCharacteristic txCharacteristic (uart_tx_uuid, txPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE); -GattCharacteristic rxCharacteristic (uart_rx_uuid, rxPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); +GattCharacteristic rxCharacteristic (uart_rx_uuid, rxPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ); GattCharacteristic *uartChars[] = {&txCharacteristic, &rxCharacteristic, &txPowerCharacteristic, &mscCharacteristic, &featureCharacteristic}; GattService uartService(uart_base_uuid, uartChars, sizeof(uartChars) / sizeof(GattCharacteristic *)); @@ -165,6 +172,16 @@ // if(led1 == 0) { led1 = 1; ledori1 = 0; + + //tran = 1; + //wait(0.5); + for(float pwidth=0.001; pwidth<=0.0013; pwidth+=0.0001) { // 1ms ~ 2ms + servo1.pulsewidth(pwidth); // pulse servo out + wait(0.25); + } + //wait(0.5); + //tran = 0; + // } else { // led1 = 0; // } @@ -204,7 +221,7 @@ //ここから------------- char bufbuf_c[20]; uint8_t bufbuf[40]; - sprintf(bufbuf_c, "%s", "00000001"); + sprintf(bufbuf_c, "%s", "00000007"); //sprintf(bufbuf_c, "%d", "02f3f538-8d11-4802-b6fc-fb6616d4cd70"); int a; for(a=0; bufbuf_c[a] != '\0'; a++) { @@ -221,7 +238,7 @@ //ここから------------- char bufbuf_c[20]; uint8_t bufbuf[40]; - sprintf(bufbuf_c, "%s", "Out.Led"); + sprintf(bufbuf_c, "%s", "Out.AirCon"); int a; for(a=0; bufbuf_c[a] != '\0'; a++) { bufbuf[a] = bufbuf_c[a]; @@ -232,10 +249,6 @@ } -void initChara() { - initMsc(); - initFeature(); -} void txStep() { //ここから------------- @@ -248,10 +261,14 @@ bufbuf[a] = bufbuf_c[a]; } ble.updateCharacteristicValue(txPowerCharacteristic.getValueAttribute().getHandle(), bufbuf, a); - initChara(); } //------------------- +void initChara() { + initMsc(); + initFeature(); + txStep(); +} void uartCB(void) { @@ -275,6 +292,16 @@ int main(void) { + //tran = 1; + //float pwidth; + servo1.period_ms(20);// pulse cycle = 20ms + //servo1.pulsewidth(0.001); + wait(0.25); + for(float pwidth=0.001; pwidth<=0.0013; pwidth+=0.0001) { // 1ms ~ 2ms + servo1.pulsewidth(pwidth); // pulse servo out + wait(0.25); + } + led1 = 0; ledori1 = 0; ble.init(); @@ -319,14 +346,15 @@ pc.printf("Advertising Start \r\n"); //TX POWER用 - txSteper.attach(&txStep, 2.0); txPowerUpdate(TX_POWER); + //txSteper.attach(&initChara, 1.0); initChara(); - + //wait(0.5); + //tran = 0; while(1) { - ble.waitForEvent(); + ble.waitForEvent(); } }