Lizzy project
Dependencies: aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT
Diff: tasks/tasks.cpp
- Branch:
- mbedOsUpdate
- Revision:
- 19:2681edc2f2b9
- Parent:
- 11:4dc690157508
- Child:
- 22:7dae8496b97c
--- a/tasks/tasks.cpp Wed Sep 12 16:21:36 2018 +0200
+++ b/tasks/tasks.cpp Thu Sep 13 12:20:35 2018 +0200
@@ -1,16 +1,14 @@
-#include "main.h"
+/**
+ * Aconno.de
+ */
+
#include "bsp_buzz.h"
-#include "bsp_led.h"
+#include "bspLed.h"
#include "aconno_ble.h"
#include "tasks.h"
#include "GapAdvertisingData.h"
-
-
-DigitalOut redLed(RED_LED_PIN);
-#if NANO_MODULE == 0
-DigitalOut greenLed(GREEN_LED_PIN);
-DigitalOut blueLed(BLUE_LED_PIN);
-#endif
+#include "aconnoConfig.h"
+#include "bsp.h"
Buzz buzzer(NRF_PWM2, BUZZER_PIN);
@@ -25,10 +23,7 @@
void tasks_init()
{
- redLed = 1;
- greenLed = 1;
- blueLed = 1;
-
+
#if TEST_LEDS_BUZZ
test_ticker.attach(led_tick, 0.5);
#endif
@@ -38,7 +33,7 @@
void buzz_tick()
{
static int start = 1;
-
+
if (start)
{
buzzer.enable();
@@ -57,23 +52,23 @@
void led_tick()
{
static int count = 0;
-
+
switch(count)
{
case 0:
redLed = 0;
break;
-
+
case 1:
redLed = 1;
greenLed = 0;
break;
-
+
case 2:
greenLed = 1;
blueLed = 0;
break;
-
+
default:
blueLed = 1;
count = -1;
@@ -81,7 +76,7 @@
test_ticker.detach();
test_ticker.attach(buzz_tick, BUZZ_TIME_S);
}
-
+
count++;
}
#endif
@@ -98,18 +93,36 @@
advertisementPacket.magnetometer[0] = (int16_t)0;
advertisementPacket.magnetometer[1] = (int16_t)0;
advertisementPacket.magnetometer[2] = (int16_t)0;
-
-
+
+ lisPowerCtrl(LIS_ON);
+ wait_ms(POWER_UP_DELAY_MS);
+ /*
+ //mems.setMode(LOW_POWER);
+ mems.setMode(HIGH_RES);
+ mems.enableAxes(X_axis);
+ mems.enableAxes(Y_axis);
+ mems.enableAxes(Z_axis);
+ mems.setODR(ODR_50Hz);
+ //mems.setScale(_16g);
+ mems.setScale(_2g);
+ 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
+ */
+
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 = LSB_VALUE;
-
+
updateServiceT.signal_set(MEAS_DONE);
bleT.signal_set(MEAS_DONE);
-
- wait_ms(MEASURE_INTERVAL_MS);
+
+ lisPowerCtrl(LIS_OFF);
+ Thread::wait(MEASURE_INTERVAL_MS);
}
}
@@ -119,7 +132,7 @@
{
Thread::signal_wait(MEAS_DONE);
updateServiceT.signal_clr(MEAS_DONE);
-
+
lizzy_service->set_acc_data(advertisementPacket.accelerometer);
}
}
@@ -130,7 +143,7 @@
{
Thread::signal_wait(UPDATE_BUZZ_LEDS);
updateBuzzLedsT.signal_clr(UPDATE_BUZZ_LEDS);
-
+
if (buzzer.get_state() != (lizzy_service->get_buzz_state()))
{
if (lizzy_service->get_buzz_state())
@@ -159,7 +172,7 @@
{
Thread::signal_wait(MEAS_DONE);
bleT.signal_clr(MEAS_DONE);
-
+
/*
printf("%6d\t", advertisementPacket.accelerometer[0]);
printf("%6d\t", advertisementPacket.accelerometer[1]);
@@ -167,10 +180,10 @@
*/
//updatePayload(ble, &advertisementPacket);
-
+
/* setup advertising */
-
-
+
+
/*
GapAdvertisingData advetisementData = GapAdvertisingData();
advetisementData = ble->getAdvertisingData();
@@ -180,19 +193,19 @@
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;
@@ -206,4 +219,4 @@
*/
//wait_ms(100);
}
-}
\ No newline at end of file
+}

