BigW Consortium Gitlab

Commit b1c86963 by David Frey

Publish light sensor reading to AV in dev day app

parent cffe3853
version: 1.0 version: 2.0
sandboxed: true sandboxed: true
start: auto start: auto
...@@ -33,4 +33,5 @@ bindings: ...@@ -33,4 +33,5 @@ bindings:
wakeupAndTweet.wakeupAndTweet.le_bootReason -> powerMgr.le_bootReason wakeupAndTweet.wakeupAndTweet.le_bootReason -> powerMgr.le_bootReason
wakeupAndTweet.wakeupAndTweet.le_adc -> modemService.le_adc wakeupAndTweet.wakeupAndTweet.le_adc -> modemService.le_adc
wakeupAndTweet.wakeupAndTweet.le_data -> dataConnectionService.le_data wakeupAndTweet.wakeupAndTweet.le_data -> dataConnectionService.le_data
wakeupAndTweet.wakeupAndTweet.le_avdata -> avcService.le_avdata
} }
\ No newline at end of file
...@@ -7,6 +7,7 @@ requires: ...@@ -7,6 +7,7 @@ requires:
le_bootReason.api le_bootReason.api
le_adc.api le_adc.api
le_data.api le_data.api
airVantage/le_avdata.api
} }
} }
...@@ -20,3 +21,14 @@ cxxflags: ...@@ -20,3 +21,14 @@ cxxflags:
{ {
-std=c++11 -std=c++11
} }
assets:
{
LightSensor =
{
variables:
{
int Reading
}
}
}
\ No newline at end of file
...@@ -26,6 +26,10 @@ static const uint32_t UnicodeSleepingFace = 0x1F634; ...@@ -26,6 +26,10 @@ static const uint32_t UnicodeSleepingFace = 0x1F634;
static le_timer_Ref_t LightSensorSampleTimer; static le_timer_Ref_t LightSensorSampleTimer;
static bool TweetPending;
static bool AvConnecting;
static le_avdata_AssetInstanceRef_t LightSensorAsset;
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/** /**
...@@ -96,6 +100,11 @@ static void LightSensorSampleTimerHandler ...@@ -96,6 +100,11 @@ static void LightSensorSampleTimerHandler
LE_DEBUG("Light sensor reports value %d", lightSensorReading); LE_DEBUG("Light sensor reports value %d", lightSensorReading);
} }
if (le_avdata_SetInt(LightSensorAsset, "Reading", lightSensorReading) != LE_OK)
{
LE_WARN("Couldn't publish light sensor reading");
}
if (lightSensorReading < ADC_LEVEL_SLEEP) if (lightSensorReading < ADC_LEVEL_SLEEP)
{ {
LE_INFO( LE_INFO(
...@@ -141,21 +150,62 @@ static void LightSensorSampleTimerHandler ...@@ -141,21 +150,62 @@ static void LightSensorSampleTimerHandler
} }
} }
static bool TryStartTimer(void)
{
const bool start = (!TweetPending && !AvConnecting);
if (start)
{
LE_ASSERT_OK(le_timer_Start(LightSensorSampleTimer));
}
return start;
}
static void AvDataSessionStateHandler
(
le_avdata_SessionState_t sessionState,
void* contextPtr
)
{
switch (sessionState)
{
case LE_AVDATA_SESSION_STARTED:
LE_DEBUG("AV data session started");
AvConnecting = false;
LightSensorAsset = le_avdata_Create("LightSensor");
TryStartTimer();
break;
case LE_AVDATA_SESSION_STOPPED:
LE_WARN("AirVantage session has stopped, but this was not requested");
break;
default:
LE_FATAL("Unhandled AV data session state (%d)", sessionState);
break;
}
}
COMPONENT_INIT COMPONENT_INIT
{ {
LE_DEBUG("wakeupAndTweetApp started"); LE_DEBUG("wakeupAndTweetApp started");
TweetPending = true;
AvConnecting = true;
le_avdata_AddSessionStateHandler(AvDataSessionStateHandler, NULL);
le_avdata_RequestSession();
LightSensorSampleTimer = le_timer_Create("light sensor"); LightSensorSampleTimer = le_timer_Create("light sensor");
LE_ASSERT_OK(le_timer_SetHandler(LightSensorSampleTimer, LightSensorSampleTimerHandler)); LE_ASSERT_OK(le_timer_SetHandler(LightSensorSampleTimer, LightSensorSampleTimerHandler));
LE_ASSERT_OK(le_timer_SetMsInterval(LightSensorSampleTimer, LIGHT_SENSOR_SAMPLE_INTERVAL_MS)); LE_ASSERT_OK(le_timer_SetMsInterval(LightSensorSampleTimer, LIGHT_SENSOR_SAMPLE_INTERVAL_MS));
LE_ASSERT_OK(le_timer_SetRepeat(LightSensorSampleTimer, 0)); LE_ASSERT_OK(le_timer_SetRepeat(LightSensorSampleTimer, 0));
// Only start the timer if it will not be done after the tweet is sent
bool startTimer = true;
if (le_bootReason_WasAdc(LIGHT_SENSOR_ADC_NUM)) if (le_bootReason_WasAdc(LIGHT_SENSOR_ADC_NUM))
{ {
TweetPending = true;
LE_DEBUG("Boot reason was ADC %u", LIGHT_SENSOR_ADC_NUM); LE_DEBUG("Boot reason was ADC %u", LIGHT_SENSOR_ADC_NUM);
size_t emojiLength = 4; size_t emojiLength = 4;
char emoji[emojiLength] = {0}; char emoji[emojiLength] = {0};
...@@ -166,24 +216,17 @@ COMPONENT_INIT ...@@ -166,24 +216,17 @@ COMPONENT_INIT
auto tweet = std::make_shared<std::string>(tweetStream.str()); auto tweet = std::make_shared<std::string>(tweetStream.str());
if (wakeupAndTweet_ConnectAndRun([tweet]{ if (wakeupAndTweet_ConnectAndRun([tweet]{
SendTweet(tweet->c_str()); SendTweet(tweet->c_str());
LE_ASSERT_OK(le_timer_Start(LightSensorSampleTimer)); TweetPending = false;
}) == LE_OK) TryStartTimer();
{ }) != LE_OK)
startTimer = false;
}
else
{ {
LE_ERROR("Couldn't create data connection to send tweet"); LE_ERROR("Couldn't create data connection to send tweet");
TweetPending = false;
} }
} }
else else
{ {
LE_DEBUG("Boot reason was not ADC %u", LIGHT_SENSOR_ADC_NUM); LE_DEBUG("Boot reason was not ADC %u", LIGHT_SENSOR_ADC_NUM);
startTimer = true; TweetPending = false;
}
if (startTimer)
{
LE_ASSERT_OK(le_timer_Start(LightSensorSampleTimer));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment