From 4ed9588545a4ad398095ef772ac70f8c111d00c5 Mon Sep 17 00:00:00 2001
From: Martin/Geno <geno+dev@fireorbit.de>
Date: Wed, 14 Aug 2019 22:34:30 +0200
Subject: [PATCH] light sensor: run on startup of card10

---
 Documentation/pycardium/light-sensor.rst | 4 ++--
 epicardium/ble/card10.c                  | 2 --
 epicardium/main.c                        | 4 ++++
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/Documentation/pycardium/light-sensor.rst b/Documentation/pycardium/light-sensor.rst
index 353f6cf5..199bb68e 100644
--- a/Documentation/pycardium/light-sensor.rst
+++ b/Documentation/pycardium/light-sensor.rst
@@ -8,8 +8,8 @@ be fairly stable.
 
 .. py:function:: light_sensor.start()
 
-   Turn on the ADC and start reading brightness values.  This function must be
-   called before any measurements can be taken.
+   Turn on the ADC and start reading brightness values.  (In past this function must be
+   called before any measurements can be taken.)
 
 .. py:function:: light_sensor.get_reading()
 
diff --git a/epicardium/ble/card10.c b/epicardium/ble/card10.c
index 6c82d1a8..9adfd649 100644
--- a/epicardium/ble/card10.c
+++ b/epicardium/ble/card10.c
@@ -233,9 +233,7 @@ static uint8_t readCard10CB(
 
 	switch (handle) {
 	case CARD10_LIGHT_SENSOR_VAL_HDL:
-		epic_light_sensor_run();
 		epic_light_sensor_get(&ui16);
-		// epic_light_sensor_stop(); stop it everywhere, also in py
 		*pAttr->pValue = ui16;
 		APP_TRACE_INFO1("ble-card10: read lightsensor: %d\n", ui16);
 		return ATT_SUCCESS;
diff --git a/epicardium/main.c b/epicardium/main.c
index f97d8f3d..56f532a6 100644
--- a/epicardium/main.c
+++ b/epicardium/main.c
@@ -126,6 +126,10 @@ int main(void)
 	LOG_INFO("startup", "Initializing dispatcher ...");
 	api_dispatcher_init();
 
+	/* light sensor */
+	LOG_INFO("startup", "starting light sensor ...");
+	epic_light_sensor_run();
+
 	/*
 	 * See if there's a l0dable.elf to run. If not, run pycardium.
 	 * This is temporary until epicardium gets a l0dable API from pycardium.
-- 
GitLab