This program is given as a sample exercise. It has all the functionality to be used on a BLE Nano device and to connect to SimpleChat application for Android/ iOS from RebBearLab. The aim of the exercise is to read a voltage and then to convert as good as possible the appropriate temperature in Celsius degrees. AI5 pin is considered for reading the voltage for the termistor. The ADC of AI5 is called every second. The function to be updated : update_measurements() from main.cpp file.

Dependencies:   BLE_API mbed nRF51822

Fork of nRF51822_DataLogger_with_Chat by Valentin Tanasa

Revision:
9:303d3628986a
Parent:
8:f28ad4600b0f
Child:
11:baafa4f7a15e
diff -r f28ad4600b0f -r 303d3628986a myData.h
--- a/myData.h	Mon Apr 11 17:21:14 2016 +0000
+++ b/myData.h	Mon Apr 25 19:34:39 2016 +0000
@@ -1,3 +1,11 @@
+#include "ble_flash.h"
+#include "mbed.h"
+
+#define MAXBUFFER  99u //(((BLE_FLASH_PAGE_SIZE - 4 - sizeof(myData_t))/sizeof(myDataL_t))
+#define MAX_WORD_PAGE_DATA 254u // to be computed as round_next_int(MAXBUFFER*sizeof(myDataL_t)+sizeof(myData_t))
+
+#define MAX_PAGE_NUM (NRF_FICR->CODESIZE - 1) // 255
+#define MIN_PAGE_NUM 155u
 
 typedef struct{
     uint8_t hour;
@@ -13,9 +21,9 @@
 
 
 typedef struct {
+    uint8_t year;  // 20_XX, 2016 => 16;
     uint8_t month; // 1..12
-    uint8_t day;  // 1..31
-    uint8_t year;  // 20_XX, 2016 => 16;
+    uint8_t day;  // 1..31    
 }date_t;
 
 
@@ -25,17 +33,67 @@
     bool updateDate;  // true if currentDate needs to be updated with newDate;
 } mdate_manager_t;
 
+typedef enum {
+        eStartAdvertising =0,
+        eStopAdvertising =1,
+        eDisconnect =2
+} connection_update_t;
 
 typedef struct {
-    float light;
-    float gndV;
-    float temp;
+    uint16_t light;
+    uint16_t gndV;
+    uint16_t temp;
     bool led_on;
+    bool led2_on;    
+} myPayload_t;
+
+
+typedef struct {
+    myPayload_t data;
+    uint8_t sec;
+    uint8_t min;    
+} myDataL_t;
+
+typedef struct {
+    myPayload_t data;
     mtime_t time;
     date_t date;
 } myData_t;
 
-#define MAXBUFFER  90
-// bool isInputValid(uint8_t * buffer);
+typedef struct {
+    myData_t startData;
+    myDataL_t myData[MAXBUFFER];
+} myDataLog_t;
+
+typedef struct {
+    myData_t startData;
+    myDataL_t myData;
+} myDataLogShort_t;
+
+/* Return current page to be written in Flash */
+uint8_t flash_currPage();
+
+/* Return next page to be written in Flash */
+uint8_t flash_go_nextPage();
+
+/* Return  page-N (thas has been written in Flash) */
+uint8_t flash_prev_N_Page(uint8_t nr_of_pages);
 
-uint8_t eNrDaysPerMonth[12]= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
\ No newline at end of file
+/* save the current page Nr to flash*/
+void save_flash_curr_pageNr(date_t mdata);
+
+/* load from flash the current PageNr*/
+void load_flash_curr_pageNr(date_t* mdata);
+
+/*search the latest page written and extract the page_nr, date, and time*/
+void search_latest_in_flash(date_t * outDate, mtime_t * outTime);
+
+/* Update current date and time with tseconds and also if there is a new date/time given */
+void update_time(mtime_manager_t* myTimeVar, mdate_manager_t* myDateVar, uint16_t tseconds);
+
+/* Update buzzer with period in ms =0..9 and duty cycle = 0..9*/
+int buzz_int(PwmOut* buzzer, uint8_t period, uint8_t duty_cycle);
+
+/* Print on serial some error from main app*/
+void assert_error_app(bool condition, Serial *pc, uint16_t error, uint16_t line, const char* file);
+