Lizzy project
Dependencies: aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT
source/main.cpp
- Committer:
- jurica238814
- Date:
- 2018-03-08
- Revision:
- 2:41a1cdac47a7
- Parent:
- 1:198b9945994e
- Child:
- 4:49b1aeca55e4
File content as of revision 2:41a1cdac47a7:
/* * aconno.de * Made by Jurica Resetar * All right reserved * */ #include "main.h" static advertising_packet advertisementPacket; static GapAdvertisingData adv_data = GapAdvertisingData(); void disableI2C(){ NRF_TWI0->ENABLE = 0; NRF_TWI0->PSELSCL = 0xFFFFFFFF; NRF_TWI1->ENABLE = 0; NRF_TWI1->PSELSCL = 0xFFFFFFFF; NRF_TWIM0->ENABLE = 0; NRF_TWIM0->PSEL.SCL = 0x80000000; NRF_TWIM0->PSEL.SDA = 0x80000000; NRF_TWIM1->ENABLE = 0; NRF_TWIM0->PSEL.SCL = 0x80000000; NRF_TWIM0->PSEL.SDA = 0x80000000; DigitalOut foo(I2C_DATA); DigitalOut bar(I2C_CLK); foo = 1; bar = 1; } void bleF(BLE *ble) { while(true) { advertisementPacket.header = APPLICATION_ID; advertisementPacket.type = 0x00; advertisementPacket.gyroscope[0] = (int16_t)0; advertisementPacket.gyroscope[1] = (int16_t)0; advertisementPacket.gyroscope[2] = (int16_t)0; advertisementPacket.magnetometer[0] = (int16_t)0; advertisementPacket.magnetometer[1] = (int16_t)0; advertisementPacket.magnetometer[2] = (int16_t)0; advertisementPacket.accelerometer[0] = (int16_t)mems.readXAxis(); advertisementPacket.accelerometer[1] = (int16_t)mems.readYAxis(); advertisementPacket.accelerometer[2] = (int16_t)mems.readZAxis(); advertisementPacket.acc_lsb_value = 0xC000; /* printf("%d\t", advertisementPacket.accelerometer[0]); printf("%d\t", advertisementPacket.accelerometer[1]); printf("%d\r\n", advertisementPacket.accelerometer[2]); */ //updatePayload(ble, &advertisementPacket); /* setup advertising */ /* GapAdvertisingData advetisementData = GapAdvertisingData(); advetisementData = ble->getAdvertisingData(); advetisementData.updateData(advetisementData.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(advertising_packet)); ble->setAdvertisingData(advetisementData); */ adv_data = ble->getAdvertisingData(); adv_data.updateData(adv_data.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(advertisementPacket)); ble->setAdvertisingData(adv_data); //printf("Ble advertisement is ON.\r\n"); #if DEBUG_LED redLed = 0; #endif ble->gap().startAdvertising(); wait_ms(1000); //wait_ms(MEASURE_INTERVAL_MS); //wait_ms(1000); //printf("Ble advertisement is OFF.\r\n\r\n"); #if DEBUG_LED redLed = 1; #endif //ble->gap().stopAdvertising(); /* GapAdvertisingData advetisementData = GapAdvertisingData(); advetisementData = ble->getAdvertisingData(); advetisementData.updateData(advetisementData.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(advertising_packet)); ble->setAdvertisingData(advetisementData); */ wait_ms(1000); } } int main(){ printf("Main program started.\r\n"); NRF_NVMC->CONFIG = 0x00000002; // Erase enable UICR NRF_NVMC->ERASEUICR = 0x00000001; // Erase all NRF_NVMC->CONFIG = 0x00000001; // Write enable UICR NRF_UICR->NFCPINS = 0xFFFFFFFE; // Change NFC to GPIO function redLed = 1; AccVcc = 1; wait_ms(POWER_UP_DELAY_MS); /* INT1.rise(int1Handler); NRF_GPIO->PIN_CNF[INT_PIN1] &= 0xFFFFFFF3; // NO PullUps */ BLE &ble = BLE::Instance(); ble.init(bleInitComplete); mems.setMode(LOW_POWER); mems.enableAxes(X_axis); mems.enableAxes(Y_axis); mems.enableAxes(Z_axis); mems.setODR(ODR_50Hz); mems.setScale(_16g); mems.int1Setup(0x40); // IntActivity 1 driven to INT1 pad mems.int1Latch(0x01); // Enable int1 latch mems.int1Threshold(INT1_THRESHOLD); mems.int1Duration(INT1_DUR); mems.int1Config(0x2A); // Enable XHigh, YHigh and ZHigh bleT.start(callback(bleF, &ble)); // Start bleT while(1){ //disableI2C(); Thread::wait(0xFFFFFFFF); } }