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
00001 #include "mailBox.cpp" 00002 #include "expansionBoard.cpp" 00003 00004 struct tm t; 00005 00006 class UserMethods { 00007 00008 public: 00009 00010 int readAll() { 00011 ExpansionBoard logs; 00012 int nOfRecords = logs.count; 00013 00014 while(nOfRecords > 0) { 00015 osEvent evt = mail_box.get(); 00016 00017 if (evt.status == osEventMail) { 00018 log_data* log = (log_data*)evt.value.p; 00019 printf("Record %d \nDate: %s, Temp Celcius: %f, Temp Farenheit: %f, Humidity: %f, " 00020 "Pressure: %f, Accelerometer: %d, Gyroscope: %d, Magnetometer: %d\n\n", log->id, 00021 log->date, log->tempCelsius, log->tempFarenheit, log->humidity, 00022 log->pressure, log->accelerometer, log->gyroscope, log->magnetometer); 00023 00024 nOfRecords--; 00025 } 00026 } 00027 00028 return logs.count; 00029 } 00030 00031 int deleteAll() { 00032 ExpansionBoard logs; 00033 int n = logs.count; 00034 00035 while(n > 0) { 00036 osEvent evt = mail_box.get(); 00037 if (evt.status == osEventMail) { 00038 log_data *log_d = (log_data*)evt.value.p; 00039 mail_box.free(log_d); 00040 } 00041 n--; 00042 } 00043 return logs.count; 00044 } 00045 00046 int readN(int n) { 00047 ExpansionBoard logs; 00048 int nOfRecords = 0; 00049 00050 if(logs.count < n) { 00051 nOfRecords = readAll(); 00052 } else { 00053 while(nOfRecords < n) { 00054 osEvent evt = mail_box.get(); 00055 00056 if (evt.status == osEventMail) { 00057 log_data* log = (log_data*)evt.value.p; 00058 printf("Record %d \nDate: %s, Temp Celcius: %f, Temp Farenheit: %f, Humidity: %f, " 00059 "Pressure: %f, Accelerometer: %d, Gyroscope: %d, Magnetometer: %d\n\n", log->id, 00060 log->date, log->tempCelsius, log->tempFarenheit, log->humidity, 00061 log->pressure, log->accelerometer, log->gyroscope, log->magnetometer); 00062 00063 nOfRecords--; 00064 } 00065 } 00066 } 00067 00068 return nOfRecords; 00069 } 00070 00071 int deleteN(int n) { 00072 ExpansionBoard logs; 00073 00074 if(logs.count < n){ 00075 n = deleteAll(); 00076 } else { 00077 while(n > 0) { 00078 osEvent evt = mail_box.get(); 00079 if (evt.status == osEventMail) { 00080 log_data *log_d = (log_data*)evt.value.p; 00081 mail_box.free(log_d); 00082 } 00083 n--; 00084 } 00085 } 00086 return n; 00087 } 00088 00089 bool setDate() { 00090 bool success; 00091 printf("Enter current date : \n"); 00092 printf( "YYYY MM DD [enter] \n"); 00093 scanf ("%d %d %d", &t.tm_year, &t.tm_mon, &t.tm_mday); 00094 00095 // adjust for tm structure required values 00096 t.tm_year = t.tm_year - 1900; 00097 t.tm_mon = t.tm_mon - 1; 00098 // set the time 00099 set_time(mktime(&t)); 00100 success= true; 00101 00102 return success; 00103 } 00104 00105 bool setTime () { 00106 bool success = false; 00107 00108 // get the current time from the terminal 00109 printf("Enter current time:\n"); 00110 printf("HH MM SS[enter]\n"); 00111 scanf("%d %d %d", &t.tm_hour, &t.tm_min, &t.tm_sec); 00112 00113 printf("TIME UPDATED TO %d:%d:%d\n", t.tm_hour, t.tm_min, t.tm_sec); 00114 00115 // set the time 00116 set_time(mktime(&t)); 00117 success = true; 00118 00119 return success; 00120 } 00121 00122 void setT(int timePeriod) { 00123 scanf("Enter sampling period: %d\n", &timePeriod); 00124 } 00125 /* 00126 void state(char x){ 00127 printf("Sampling is %s\n", x); 00128 printf("Enter state:\n"); 00129 scanf("%s", x); 00130 }*/ 00131 00132 bool logTime (int time, bool state) { 00133 return state; 00134 } 00135 00136 bool debugMessages (bool state) { 00137 return state; 00138 } 00139 00140 bool logging(bool state) { 00141 return state; 00142 } 00143 00144 };
Generated on Sun Jul 17 2022 00:26:54 by
1.7.2
