Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: X_NUCLEO_IKS01A1 mbed-rtos mbed
Fork of HelloWorld_IKS01A1 by
userInteractions.cpp@29:f96590e6058d, 2016-05-09 (annotated)
- Committer:
- Jacinta
- Date:
- Mon May 09 01:42:41 2016 +0000
- Revision:
- 29:f96590e6058d
- Child:
- 31:eb7320bd1d37
Still can't figure the problem with "ticker.attach", however fixed some other errors that showed when I commented out ticker.attach. Apart from this, the remaining errors are related with "t", which is a variable of type thread being used for time...
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Jacinta | 29:f96590e6058d | 1 | #include "buffer.cpp" |
| Jacinta | 29:f96590e6058d | 2 | |
| Jacinta | 29:f96590e6058d | 3 | struct tm t; |
| Jacinta | 29:f96590e6058d | 4 | |
| Jacinta | 29:f96590e6058d | 5 | class UserMethods { |
| Jacinta | 29:f96590e6058d | 6 | Buffer buffer; |
| Jacinta | 29:f96590e6058d | 7 | |
| Jacinta | 29:f96590e6058d | 8 | public: |
| Jacinta | 29:f96590e6058d | 9 | |
| Jacinta | 29:f96590e6058d | 10 | int readAll() { |
| Jacinta | 29:f96590e6058d | 11 | //Check if there are samples |
| Jacinta | 29:f96590e6058d | 12 | int32_t Nsamples = samplesInBuffer->wait(); |
| Jacinta | 29:f96590e6058d | 13 | |
| Jacinta | 29:f96590e6058d | 14 | Buffer::log_data log; |
| Jacinta | 29:f96590e6058d | 15 | int count = buffer.newestIndex; |
| Jacinta | 29:f96590e6058d | 16 | int nOfRecords = 0; |
| Jacinta | 29:f96590e6058d | 17 | |
| Jacinta | 29:f96590e6058d | 18 | while(count >= buffer.oldestIndex){ |
| Jacinta | 29:f96590e6058d | 19 | log = buffer[count]; |
| Jacinta | 29:f96590e6058d | 20 | |
| Jacinta | 29:f96590e6058d | 21 | printf("Record %i \nDate: %s, Temp Celcius: %s, Temp Farenheit: %s, Humidity: %s, |
| Jacinta | 29:f96590e6058d | 22 | "Pressure: , Accelerometer: %s, Gyroscope: %s, Magnetometer: %s\n\n", log->id, |
| Jacinta | 29:f96590e6058d | 23 | log->date, log->tempCelcius, log->tempFarenheit, log->humidity, |
| Jacinta | 29:f96590e6058d | 24 | log->pressure, log->accelerometer, log->gyroscope, log->magnetometer); |
| Jacinta | 29:f96590e6058d | 25 | |
| Jacinta | 29:f96590e6058d | 26 | count--; |
| Jacinta | 29:f96590e6058d | 27 | nOfRecords++; |
| Jacinta | 29:f96590e6058d | 28 | } |
| Jacinta | 29:f96590e6058d | 29 | |
| Jacinta | 29:f96590e6058d | 30 | return nOfRecords; |
| Jacinta | 29:f96590e6058d | 31 | } |
| Jacinta | 29:f96590e6058d | 32 | |
| Jacinta | 29:f96590e6058d | 33 | int deleteAll() { |
| Jacinta | 29:f96590e6058d | 34 | int n = mail.count; |
| Jacinta | 29:f96590e6058d | 35 | mail.recv_thread(n); |
| Jacinta | 29:f96590e6058d | 36 | //int numRecords; |
| Jacinta | 29:f96590e6058d | 37 | return n; |
| Jacinta | 29:f96590e6058d | 38 | } |
| Jacinta | 29:f96590e6058d | 39 | |
| Jacinta | 29:f96590e6058d | 40 | int readN(int n) { |
| Jacinta | 29:f96590e6058d | 41 | //Check if there are samples |
| Jacinta | 29:f96590e6058d | 42 | int32_t Nsamples = samplesInBuffer->wait(); |
| Jacinta | 29:f96590e6058d | 43 | |
| Jacinta | 29:f96590e6058d | 44 | Buffer::log_data log; |
| Jacinta | 29:f96590e6058d | 45 | int count = buffer.newestIndex; |
| Jacinta | 29:f96590e6058d | 46 | int nOfRecords = 0; |
| Jacinta | 29:f96590e6058d | 47 | |
| Jacinta | 29:f96590e6058d | 48 | while(count >= n){ |
| Jacinta | 29:f96590e6058d | 49 | log = buffer[count]; |
| Jacinta | 29:f96590e6058d | 50 | |
| Jacinta | 29:f96590e6058d | 51 | printf("Record %i \nDate: %s, Temp Celcius: %s, Temp Farenheit: %s, Humidity: %s, |
| Jacinta | 29:f96590e6058d | 52 | "Pressure: , Accelerometer: %s, Gyroscope: %s, Magnetometer: %s\n\n", log->id, |
| Jacinta | 29:f96590e6058d | 53 | log->date, log->tempCelcius, log->tempFarenheit, log->humidity, |
| Jacinta | 29:f96590e6058d | 54 | log->pressure, log->accelerometer, log->gyroscope, log->magnetometer); |
| Jacinta | 29:f96590e6058d | 55 | |
| Jacinta | 29:f96590e6058d | 56 | count--; |
| Jacinta | 29:f96590e6058d | 57 | nOfRecords++; |
| Jacinta | 29:f96590e6058d | 58 | } |
| Jacinta | 29:f96590e6058d | 59 | |
| Jacinta | 29:f96590e6058d | 60 | return nOfRecords; |
| Jacinta | 29:f96590e6058d | 61 | } |
| Jacinta | 29:f96590e6058d | 62 | |
| Jacinta | 29:f96590e6058d | 63 | int deleteN(int n) { |
| Jacinta | 29:f96590e6058d | 64 | mail.recv_thread(n); |
| Jacinta | 29:f96590e6058d | 65 | //int numRecords; |
| Jacinta | 29:f96590e6058d | 66 | return n; |
| Jacinta | 29:f96590e6058d | 67 | } |
| Jacinta | 29:f96590e6058d | 68 | |
| Jacinta | 29:f96590e6058d | 69 | bool setDate() { |
| Jacinta | 29:f96590e6058d | 70 | bool success; |
| Jacinta | 29:f96590e6058d | 71 | printf("Enter current date : \n"); |
| Jacinta | 29:f96590e6058d | 72 | printf( "YYYY MM DD [enter] \n"); |
| Jacinta | 29:f96590e6058d | 73 | scanf ("%d %d %d", &t.tm_year, &t.tm_mon, &t.tm_mday); |
| Jacinta | 29:f96590e6058d | 74 | |
| Jacinta | 29:f96590e6058d | 75 | // adjust for tm structure required values |
| Jacinta | 29:f96590e6058d | 76 | t.tm_year = t.tm_year - 1900; |
| Jacinta | 29:f96590e6058d | 77 | t.tm_mon = t.tm_mon - 1; |
| Jacinta | 29:f96590e6058d | 78 | // set the time |
| Jacinta | 29:f96590e6058d | 79 | set_time(mktime(&t)); |
| Jacinta | 29:f96590e6058d | 80 | success= true; |
| Jacinta | 29:f96590e6058d | 81 | |
| Jacinta | 29:f96590e6058d | 82 | return success; |
| Jacinta | 29:f96590e6058d | 83 | } |
| Jacinta | 29:f96590e6058d | 84 | |
| Jacinta | 29:f96590e6058d | 85 | bool setTime () { |
| Jacinta | 29:f96590e6058d | 86 | bool success = false; |
| Jacinta | 29:f96590e6058d | 87 | |
| Jacinta | 29:f96590e6058d | 88 | // get the current time from the terminal |
| Jacinta | 29:f96590e6058d | 89 | printf("Enter current time:\n"); |
| Jacinta | 29:f96590e6058d | 90 | printf("HH MM SS[enter]\n"); |
| Jacinta | 29:f96590e6058d | 91 | scanf("%d %d %d", &t.tm_hour, &t.tm_min, &t.tm_sec); |
| Jacinta | 29:f96590e6058d | 92 | |
| Jacinta | 29:f96590e6058d | 93 | printf("TIME UPDATED TO %d:%d:%d\n", t.tm_hour, t.tm_min, t.tm_sec); |
| Jacinta | 29:f96590e6058d | 94 | |
| Jacinta | 29:f96590e6058d | 95 | // set the time |
| Jacinta | 29:f96590e6058d | 96 | set_time(mktime(&t)); |
| Jacinta | 29:f96590e6058d | 97 | success = true; |
| Jacinta | 29:f96590e6058d | 98 | |
| Jacinta | 29:f96590e6058d | 99 | return success; |
| Jacinta | 29:f96590e6058d | 100 | } |
| Jacinta | 29:f96590e6058d | 101 | |
| Jacinta | 29:f96590e6058d | 102 | void setT(int timePeriod) { |
| Jacinta | 29:f96590e6058d | 103 | scanf("Enter sampling period: %d\n", &timePeriod); |
| Jacinta | 29:f96590e6058d | 104 | } |
| Jacinta | 29:f96590e6058d | 105 | /* |
| Jacinta | 29:f96590e6058d | 106 | void state(char x){ |
| Jacinta | 29:f96590e6058d | 107 | printf("Sampling is %s\n", x); |
| Jacinta | 29:f96590e6058d | 108 | printf("Enter state:\n"); |
| Jacinta | 29:f96590e6058d | 109 | scanf("%s", x); |
| Jacinta | 29:f96590e6058d | 110 | }*/ |
| Jacinta | 29:f96590e6058d | 111 | |
| Jacinta | 29:f96590e6058d | 112 | bool logTime (int time, bool state) { |
| Jacinta | 29:f96590e6058d | 113 | return state; |
| Jacinta | 29:f96590e6058d | 114 | } |
| Jacinta | 29:f96590e6058d | 115 | |
| Jacinta | 29:f96590e6058d | 116 | bool debugMessages (bool state) { |
| Jacinta | 29:f96590e6058d | 117 | return state; |
| Jacinta | 29:f96590e6058d | 118 | } |
| Jacinta | 29:f96590e6058d | 119 | |
| Jacinta | 29:f96590e6058d | 120 | bool logging(bool state) { |
| Jacinta | 29:f96590e6058d | 121 | return state; |
| Jacinta | 29:f96590e6058d | 122 | } |
| Jacinta | 29:f96590e6058d | 123 | |
| Jacinta | 29:f96590e6058d | 124 | }; |

