Algoritmo funcionando com a biblioteca de inatividade utilizando dos dados do acelerômetro e a biblioteca de PeakSearch se utilizando dos dados filtrados pelo filtro Kalman.

Dependencies:   mbed MatrixMath Matrix nrf51_rtc BMP180 MPU9250

Committer:
Rogercl
Date:
Sun Aug 04 11:38:08 2019 +0000
Revision:
6:e9a2bc040ada
Parent:
0:095b19b8fb7e
Algoritmo funcionando com a biblioteca de inatividade utilizando dos dados do acelerometro e a biblioteca de PeakSearch se utilizando dos dados filtrados pelo filtro Kalman.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rogercl 0:095b19b8fb7e 1 #ifndef TIME_CONFIG_H
Rogercl 0:095b19b8fb7e 2 #define TIME_CONFIG_H
Rogercl 0:095b19b8fb7e 3
Rogercl 0:095b19b8fb7e 4 #include "mbed.h"
Rogercl 0:095b19b8fb7e 5
Rogercl 0:095b19b8fb7e 6 time_t example_time()
Rogercl 0:095b19b8fb7e 7 {
Rogercl 0:095b19b8fb7e 8 // set an intial time
Rogercl 0:095b19b8fb7e 9 // ...not really necessary for this example, but it beats setting it to 0 or some non-obvious large integer (# of seconds since 1/1/1970)
Rogercl 0:095b19b8fb7e 10 time_t rawtime=0;
Rogercl 0:095b19b8fb7e 11
Rogercl 0:095b19b8fb7e 12 struct tm * init_timeinfo;
Rogercl 0:095b19b8fb7e 13
Rogercl 0:095b19b8fb7e 14 // initialize time
Rogercl 0:095b19b8fb7e 15 init_timeinfo = localtime(&rawtime); // note: must initialize the struct with this before trying to set components
Rogercl 0:095b19b8fb7e 16 // ...else code goes into the weeds!!
Rogercl 0:095b19b8fb7e 17 /*
Rogercl 0:095b19b8fb7e 18 init_timeinfo->tm_sec = atoi(ss);
Rogercl 0:095b19b8fb7e 19 init_timeinfo->tm_min = atoi(mm);
Rogercl 0:095b19b8fb7e 20 init_timeinfo->tm_hour = atoi(hh);
Rogercl 0:095b19b8fb7e 21 init_timeinfo->tm_mday = atoi(DD);
Rogercl 0:095b19b8fb7e 22 init_timeinfo->tm_mon = atoi(MM) - 1;
Rogercl 0:095b19b8fb7e 23 init_timeinfo->tm_year = (2000+atoi(AA)) - 1900;
Rogercl 0:095b19b8fb7e 24 */
Rogercl 0:095b19b8fb7e 25 int Day=01;
Rogercl 0:095b19b8fb7e 26 int Month=01;
Rogercl 0:095b19b8fb7e 27 int Year=2019;
Rogercl 0:095b19b8fb7e 28 int Hour=0;
Rogercl 0:095b19b8fb7e 29 int Minutes=0;
Rogercl 0:095b19b8fb7e 30 int Seconds=00;
Rogercl 0:095b19b8fb7e 31
Rogercl 0:095b19b8fb7e 32 init_timeinfo->tm_sec = Seconds;
Rogercl 0:095b19b8fb7e 33 init_timeinfo->tm_min = Minutes;
Rogercl 0:095b19b8fb7e 34 init_timeinfo->tm_hour = Hour;
Rogercl 0:095b19b8fb7e 35 init_timeinfo->tm_mday = Day;
Rogercl 0:095b19b8fb7e 36 init_timeinfo->tm_mon = Month - 1;
Rogercl 0:095b19b8fb7e 37 init_timeinfo->tm_year = Year - 1900;
Rogercl 0:095b19b8fb7e 38
Rogercl 0:095b19b8fb7e 39 // compute the proper value for time in time_t type
Rogercl 0:095b19b8fb7e 40 rawtime = mktime(init_timeinfo);
Rogercl 0:095b19b8fb7e 41 return rawtime;
Rogercl 0:095b19b8fb7e 42
Rogercl 0:095b19b8fb7e 43 } //end time_t example_time()
Rogercl 0:095b19b8fb7e 44
Rogercl 0:095b19b8fb7e 45 void update_rtc()
Rogercl 0:095b19b8fb7e 46 {
Rogercl 0:095b19b8fb7e 47 // for use as interrupt routine, to insure that RTC is updated periodically
Rogercl 0:095b19b8fb7e 48 // ...if rtc is not read before the underlying counter rolls over (typically 512 seconds), the RTC value will be wrong
Rogercl 0:095b19b8fb7e 49 // ...ideally this would be done as part of the nrf51_rtc method, but I couldn't get it to behave (see nrf51_rtc.cpp for details)
Rogercl 0:095b19b8fb7e 50 rtc.time();
Rogercl 0:095b19b8fb7e 51
Rogercl 0:095b19b8fb7e 52 } //end update_rtc()
Rogercl 0:095b19b8fb7e 53
Rogercl 0:095b19b8fb7e 54 void time_init()
Rogercl 0:095b19b8fb7e 55 {
Rogercl 0:095b19b8fb7e 56 // user selectable, any time < 512 seconds is OK
Rogercl 0:095b19b8fb7e 57 #define PERIODIC_UPDATE 1
Rogercl 0:095b19b8fb7e 58 Ticker rtc_ticker;
Rogercl 0:095b19b8fb7e 59 rtc_ticker.attach(&update_rtc, PERIODIC_UPDATE); // update the time regularly
Rogercl 0:095b19b8fb7e 60
Rogercl 0:095b19b8fb7e 61 time_t initial_time = example_time();
Rogercl 0:095b19b8fb7e 62 rtc.set_time(initial_time);
Rogercl 0:095b19b8fb7e 63
Rogercl 0:095b19b8fb7e 64 } //end time_init()
Rogercl 0:095b19b8fb7e 65
Rogercl 0:095b19b8fb7e 66 void print_time()
Rogercl 0:095b19b8fb7e 67 {
Rogercl 0:095b19b8fb7e 68 // called when a button is pushed, this prints the current time to the USB-connected console
Rogercl 0:095b19b8fb7e 69
Rogercl 0:095b19b8fb7e 70 time_t rawtime=rtc.time();
Rogercl 0:095b19b8fb7e 71
Rogercl 0:095b19b8fb7e 72 // massage the time into a human-friendly format for printing
Rogercl 0:095b19b8fb7e 73 struct tm * timeinfo;
Rogercl 0:095b19b8fb7e 74 timeinfo = localtime(&rawtime);
Rogercl 0:095b19b8fb7e 75 char date[24];
Rogercl 0:095b19b8fb7e 76 strftime(date,sizeof(date),"%H:%M:%S em %d/%m/%G",timeinfo);
Rogercl 0:095b19b8fb7e 77 Open.printf("Horario e data atual: %s.\r\n",date);
Rogercl 0:095b19b8fb7e 78
Rogercl 0:095b19b8fb7e 79 }// end print_time()
Rogercl 0:095b19b8fb7e 80
Rogercl 0:095b19b8fb7e 81 void ask_time(char date[100])
Rogercl 0:095b19b8fb7e 82 {
Rogercl 0:095b19b8fb7e 83 time_t rawtime=rtc.time();
Rogercl 0:095b19b8fb7e 84
Rogercl 0:095b19b8fb7e 85 // massage the time into a human-friendly format for printing
Rogercl 0:095b19b8fb7e 86 struct tm * timeinfo;
Rogercl 0:095b19b8fb7e 87 timeinfo = localtime(&rawtime);
Rogercl 0:095b19b8fb7e 88 char buff1[100];
Rogercl 0:095b19b8fb7e 89 strftime(buff1,sizeof(buff1),"%H-%M-%S",timeinfo);
Rogercl 0:095b19b8fb7e 90 sprintf(date,"%s,",buff1);
Rogercl 0:095b19b8fb7e 91
Rogercl 0:095b19b8fb7e 92 } //end ask_time()
Rogercl 0:095b19b8fb7e 93
Rogercl 0:095b19b8fb7e 94 void ask_day(char daya[2])
Rogercl 0:095b19b8fb7e 95 {
Rogercl 0:095b19b8fb7e 96 time_t rawtime=rtc.time();
Rogercl 0:095b19b8fb7e 97
Rogercl 0:095b19b8fb7e 98 // maessage the time into a human-friendly format for printing
Rogercl 0:095b19b8fb7e 99 struct tm * timeinfo;
Rogercl 0:095b19b8fb7e 100 timeinfo = localtime(&rawtime);
Rogercl 0:095b19b8fb7e 101 strftime(daya,sizeof(daya),"%d",timeinfo);
Rogercl 0:095b19b8fb7e 102
Rogercl 0:095b19b8fb7e 103 } //end ask_day()
Rogercl 0:095b19b8fb7e 104
Rogercl 0:095b19b8fb7e 105
Rogercl 0:095b19b8fb7e 106 #endif