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

Committer:
tanasaro10
Date:
Mon Apr 25 19:34:39 2016 +0000
Revision:
9:303d3628986a
Parent:
8:f28ad4600b0f
Child:
11:baafa4f7a15e
Major rework on the code and extended functionality added. Detailed explanations are given in read_me.md file.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tanasaro10 9:303d3628986a 1 #include "ble_flash.h"
tanasaro10 9:303d3628986a 2 #include "mbed.h"
tanasaro10 9:303d3628986a 3
tanasaro10 9:303d3628986a 4 #define MAXBUFFER 99u //(((BLE_FLASH_PAGE_SIZE - 4 - sizeof(myData_t))/sizeof(myDataL_t))
tanasaro10 9:303d3628986a 5 #define MAX_WORD_PAGE_DATA 254u // to be computed as round_next_int(MAXBUFFER*sizeof(myDataL_t)+sizeof(myData_t))
tanasaro10 9:303d3628986a 6
tanasaro10 9:303d3628986a 7 #define MAX_PAGE_NUM (NRF_FICR->CODESIZE - 1) // 255
tanasaro10 9:303d3628986a 8 #define MIN_PAGE_NUM 155u
tanasaro10 8:f28ad4600b0f 9
tanasaro10 8:f28ad4600b0f 10 typedef struct{
tanasaro10 8:f28ad4600b0f 11 uint8_t hour;
tanasaro10 8:f28ad4600b0f 12 uint8_t min;
tanasaro10 8:f28ad4600b0f 13 uint8_t sec;
tanasaro10 8:f28ad4600b0f 14 } mtime_t;
tanasaro10 8:f28ad4600b0f 15
tanasaro10 8:f28ad4600b0f 16 typedef struct{
tanasaro10 8:f28ad4600b0f 17 mtime_t currentTime;
tanasaro10 8:f28ad4600b0f 18 mtime_t newTime;
tanasaro10 8:f28ad4600b0f 19 bool updateTime; // true if currentTime needs to be updated with newTime;
tanasaro10 8:f28ad4600b0f 20 } mtime_manager_t;
tanasaro10 8:f28ad4600b0f 21
tanasaro10 8:f28ad4600b0f 22
tanasaro10 8:f28ad4600b0f 23 typedef struct {
tanasaro10 9:303d3628986a 24 uint8_t year; // 20_XX, 2016 => 16;
tanasaro10 8:f28ad4600b0f 25 uint8_t month; // 1..12
tanasaro10 9:303d3628986a 26 uint8_t day; // 1..31
tanasaro10 8:f28ad4600b0f 27 }date_t;
tanasaro10 8:f28ad4600b0f 28
tanasaro10 8:f28ad4600b0f 29
tanasaro10 8:f28ad4600b0f 30 typedef struct{
tanasaro10 8:f28ad4600b0f 31 date_t currentDate;
tanasaro10 8:f28ad4600b0f 32 date_t newDate;
tanasaro10 8:f28ad4600b0f 33 bool updateDate; // true if currentDate needs to be updated with newDate;
tanasaro10 8:f28ad4600b0f 34 } mdate_manager_t;
tanasaro10 8:f28ad4600b0f 35
tanasaro10 9:303d3628986a 36 typedef enum {
tanasaro10 9:303d3628986a 37 eStartAdvertising =0,
tanasaro10 9:303d3628986a 38 eStopAdvertising =1,
tanasaro10 9:303d3628986a 39 eDisconnect =2
tanasaro10 9:303d3628986a 40 } connection_update_t;
tanasaro10 8:f28ad4600b0f 41
tanasaro10 8:f28ad4600b0f 42 typedef struct {
tanasaro10 9:303d3628986a 43 uint16_t light;
tanasaro10 9:303d3628986a 44 uint16_t gndV;
tanasaro10 9:303d3628986a 45 uint16_t temp;
tanasaro10 8:f28ad4600b0f 46 bool led_on;
tanasaro10 9:303d3628986a 47 bool led2_on;
tanasaro10 9:303d3628986a 48 } myPayload_t;
tanasaro10 9:303d3628986a 49
tanasaro10 9:303d3628986a 50
tanasaro10 9:303d3628986a 51 typedef struct {
tanasaro10 9:303d3628986a 52 myPayload_t data;
tanasaro10 9:303d3628986a 53 uint8_t sec;
tanasaro10 9:303d3628986a 54 uint8_t min;
tanasaro10 9:303d3628986a 55 } myDataL_t;
tanasaro10 9:303d3628986a 56
tanasaro10 9:303d3628986a 57 typedef struct {
tanasaro10 9:303d3628986a 58 myPayload_t data;
tanasaro10 8:f28ad4600b0f 59 mtime_t time;
tanasaro10 8:f28ad4600b0f 60 date_t date;
tanasaro10 8:f28ad4600b0f 61 } myData_t;
tanasaro10 8:f28ad4600b0f 62
tanasaro10 9:303d3628986a 63 typedef struct {
tanasaro10 9:303d3628986a 64 myData_t startData;
tanasaro10 9:303d3628986a 65 myDataL_t myData[MAXBUFFER];
tanasaro10 9:303d3628986a 66 } myDataLog_t;
tanasaro10 9:303d3628986a 67
tanasaro10 9:303d3628986a 68 typedef struct {
tanasaro10 9:303d3628986a 69 myData_t startData;
tanasaro10 9:303d3628986a 70 myDataL_t myData;
tanasaro10 9:303d3628986a 71 } myDataLogShort_t;
tanasaro10 9:303d3628986a 72
tanasaro10 9:303d3628986a 73 /* Return current page to be written in Flash */
tanasaro10 9:303d3628986a 74 uint8_t flash_currPage();
tanasaro10 9:303d3628986a 75
tanasaro10 9:303d3628986a 76 /* Return next page to be written in Flash */
tanasaro10 9:303d3628986a 77 uint8_t flash_go_nextPage();
tanasaro10 9:303d3628986a 78
tanasaro10 9:303d3628986a 79 /* Return page-N (thas has been written in Flash) */
tanasaro10 9:303d3628986a 80 uint8_t flash_prev_N_Page(uint8_t nr_of_pages);
tanasaro10 8:f28ad4600b0f 81
tanasaro10 9:303d3628986a 82 /* save the current page Nr to flash*/
tanasaro10 9:303d3628986a 83 void save_flash_curr_pageNr(date_t mdata);
tanasaro10 9:303d3628986a 84
tanasaro10 9:303d3628986a 85 /* load from flash the current PageNr*/
tanasaro10 9:303d3628986a 86 void load_flash_curr_pageNr(date_t* mdata);
tanasaro10 9:303d3628986a 87
tanasaro10 9:303d3628986a 88 /*search the latest page written and extract the page_nr, date, and time*/
tanasaro10 9:303d3628986a 89 void search_latest_in_flash(date_t * outDate, mtime_t * outTime);
tanasaro10 9:303d3628986a 90
tanasaro10 9:303d3628986a 91 /* Update current date and time with tseconds and also if there is a new date/time given */
tanasaro10 9:303d3628986a 92 void update_time(mtime_manager_t* myTimeVar, mdate_manager_t* myDateVar, uint16_t tseconds);
tanasaro10 9:303d3628986a 93
tanasaro10 9:303d3628986a 94 /* Update buzzer with period in ms =0..9 and duty cycle = 0..9*/
tanasaro10 9:303d3628986a 95 int buzz_int(PwmOut* buzzer, uint8_t period, uint8_t duty_cycle);
tanasaro10 9:303d3628986a 96
tanasaro10 9:303d3628986a 97 /* Print on serial some error from main app*/
tanasaro10 9:303d3628986a 98 void assert_error_app(bool condition, Serial *pc, uint16_t error, uint16_t line, const char* file);
tanasaro10 9:303d3628986a 99