
nRF51822_OBS + mocro:bit_ADV
Dependencies: mbed BLE_API Adafruit_GFX nRF51822
Тесты по созданию связи между micro:bit и nRF51822 & BLE400 эта часть под nRF51822
Revision 15:23ce464fa0b5, committed 2019-12-17
- Comitter:
- mamont090671
- Date:
- Tue Dec 17 09:15:36 2019 +0000
- Parent:
- 14:985bfbee997b
- Commit message:
- +3
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 985bfbee997b -r 23ce464fa0b5 main.cpp --- a/main.cpp Mon Dec 16 13:25:59 2019 +0000 +++ b/main.cpp Tue Dec 17 09:15:36 2019 +0000 @@ -17,8 +17,7 @@ #include "mbed.h" #include "BLE.h" #include "Adafruit_SSD1306.h" -//#include "bme280.h" - +//Задаем пины для i2c шины #define SDA P0_0 #define SCL P0_1 @@ -46,7 +45,7 @@ void triggerrise_1(); //Button1 rising interrupt function void triggerfall_2(); //Button2 falling interrupt function void triggerrise_2(); //Button2 rising interrupt function - +//Задаем кнопки DigitalIn sw1(BUTTON1); DigitalIn sw2(BUTTON2); @@ -54,9 +53,6 @@ InterruptIn sw1Press(BUTTON1); InterruptIn sw2Press(BUTTON2); int flag_button; -//float t; -//float pr; -//float h; class I2C2 : public I2C { @@ -70,30 +66,18 @@ I2C2 gI2C(SDA,SCL); Adafruit_SSD1306_I2c gOled2(gI2C, NC, 0x78, 64, 128); - +//Используем BLE BLE ble; -//BME280 bme280; +//Задаем светодиод DigitalOut led1(LED1); - +//Задаем интерфейс rs232 Serial pc(USBTX, USBRX); -/*//bme280 -void i2cWrite(uint8_t i2c_address, uint8_t *p_data, uint8_t data_size, uint8_t repeated_start) -{ -// mbed uses 8-bit addresses, always confusing. - gI2C.write(i2c_address<<1,(const char *)p_data,data_size,repeated_start); -} - -void i2cRead(uint8_t i2c_address, uint8_t *p_data, uint8_t data_size) -{ -// mbed uses 8-bit addresses, always confusing. - gI2C.read(i2c_address<<1,(char *)p_data,data_size); -} -*/ +//Функция вызываемая по таймеру void periodicCallback(void) { led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */ } - +//Функция вызывается при обнаружении ADV пакета void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params) { AdvertisingData_t *pAdvData = NULL; @@ -106,26 +90,36 @@ ApplicationData_t *pAppData = (ApplicationData_t *)pAdvData->data; if(pAppData->applicationSpecificId == APP_SPECIFIC_ID_TEST) { // pc.printf("From [%02x %02x %02x %02x %02x %02x], ", params->peerAddr[5], params->peerAddr[4], params->peerAddr[3], params->peerAddr[2], params->peerAddr[1], params->peerAddr[0]); +//Если MAC заканчивается на 0х38 то .... if(params->peerAddr[0] == 0x38 && flag_button == 1) { pc.printf("Temp is %.02f\r", (float)pAppData->ExtT_Value); // gOled2.clearDisplay(); +//Выводим двойную рамку для веха экрана gOled2.drawRoundRect(0, 0, 127, 15, 3, 1); gOled2.drawRoundRect(1, 1, 125, 13, 2, 1); +//Выводим двойную рамку для низа экрана gOled2.drawRoundRect(0, 16, 127, 47, 3, 1); gOled2.drawRoundRect(1, 17, 125, 45, 2, 1); // gOled2.drawRect(0, 0, 127, 63, 1); // gOled2.drawRect(1, 1, 125, 61, 1); +//Показываем на экране gOled2.display(); +//Устанавливаем курсор gOled2.setTextCursor(4, 4); +//Задаем размер шрифта gOled2.setTextSize(1); gOled2.printf("Observer Init \r"); +//Показываем на экране gOled2.display(); gOled2.setTextCursor(4, 22); gOled2.setTextSize(2); +//Выводим показания внешнего датчика температуры на экран gOled2.printf("ExtT: %.01f", (float)pAppData->ExtT_Value); gOled2.display(); +//Иначе, если MAC другой, то ... } else if (params->peerAddr[0] != 0x38 && flag_button == 2) { +//Выводим показания другого датчика на экран pc.printf("XZ is %.02f\r", (float)pAppData->ExtT_Value); gOled2.setTextCursor(4, 22); gOled2.setTextSize(2); @@ -140,17 +134,7 @@ len += (pAdvData->length + 1); } } -/* -void updateFromBME280() -{ - bme280.read(); - t = bme280.temperature(); - float p = bme280.pressure()/100; - pr = p*0.750062; -// pr = bme280.pressure(); - h = bme280.humidity(); -} -*/ + int main(void) { //Set falling and rising edge to apppropriate interrup function @@ -161,35 +145,27 @@ flag_button = 0; led1 = 1; +//Объявляем таймер Ticker ticker; +//Назначаем таймеру функцию и интервал ticker.attach(periodicCallback, 1); -/* - bme280.begin(BME280_I2C_ADDRESS1); - // Configure for test purposes. - bme280.writeConfigRegister(BME280_STANDBY_500_US,BME280_FILTER_OFF,0); - bme280.writeControlRegisters(BME280_OVERSAMPLING_1X,BME280_OVERSAMPLING_1X,BME280_OVERSAMPLING_1X,BME280_MODE_NORMAL); -*/ + +//инициализируем BLE ble.init(); +//Задаем параметры сканирования ble.gap().setScanParams(1800 /* scan interval */, 1500 /* scan window */); +//Запускаем сканирование ble.gap().startScan(advertisementCallback); +//Задаем параметры порта rs232 pc.baud(9600); pc.printf("Observer Init \r\n"); +//Очищаем экран gOled2.clearDisplay(); gOled2.display(); while (true) { -/* if (flag_button == 2) { - updateFromBME280(); - gOled2.setTextCursor(4, 22); - gOled2.setTextSize(2); - gOled2.printf("IntT: %.01f", t); - gOled2.setTextCursor(4, 42); - gOled2.printf("IntP: %.01f", pr); - gOled2.display(); - } -*/ ble.waitForEvent(); } }