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: mbed 4DGL-uLCD-SE SDFileSystem
Revision 7:d85521f4f0c3, committed 2016-12-07
- Comitter:
- ashea6
- Date:
- Wed Dec 07 17:37:12 2016 +0000
- Parent:
- 6:ce8d4456e28b
- Commit message:
- done
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Dec 06 23:32:59 2016 +0000
+++ b/main.cpp Wed Dec 07 17:37:12 2016 +0000
@@ -3,18 +3,23 @@
#include <vector>
#include "utils.h"
#include "SDFileSystem.h"
-#include "uLCD_4DGL.h"
+//#include "uLCD_4DGL.h"
DigitalOut myled(LED1);
+DigitalOut myled2(LED2);
+DigitalOut myled3(LED3);
+DigitalOut myled4(LED4);
+
InterruptIn pb1(p21);
InterruptIn pb2(p22);
-uLCD_4DGL uLCD(p28,p27,p29);
+//uLCD_4DGL uLCD(p28,p27,p29);
SDFileSystem sd(p5, p6, p7, p8, "sd");
//PinDetect pb1(p21); // receive new schedule
-Serial pc(USBTX, USBRX); // tx, rx .... for testing purposes (remove later)
-//Serial blue(p13, p14, 9600);
+//Serial pc(USBTX, USBRX); // tx, rx .... for testing purposes (remove later)
+Serial pc(p28, p27);
+Serial mypc(USBTX, USBRX);
Serial easyVR(p13,p14);
void pb1_hit_interrupt (void);
void pb2_hit_interrupt (void);
@@ -81,7 +86,7 @@
wait(0.1);
}
- uLCD.printf("waiting to receive schedule\n");
+ //uLCD.printf("waiting to receive schedule\n");
receive_schedule();
int current_time = schedule_read();
//uLCD.printf("current time set to: %i", current_time);
@@ -90,34 +95,41 @@
// subtract 5*60*60 for eastern time
time_t clock;
time_t seconds = time(NULL);
- uLCD.printf("Time as a basic string = %s", ctime(&seconds));
+ //uLCD.printf("Time as a basic string = %s", ctime(&seconds));
//packdata(1);
wait(1);
int flag = 0;
-
+ myled2 = 1;
//Day currentDay = Wednesday;
- uLCD.printf("current day is %i\n",timeinfo->tm_wday);
+ //uLCD.printf("current day is %i\n",timeinfo->tm_wday);
int time_diff;
+ int dex = 0;
+ int stop_point = myschedule.getSize();
while(1) {
for (int i = 0; i < myschedule.getSize(); i++) {
timeinfo = localtime (&clock); // ct_time not set right now
time(&clock);
- pc.printf("Time as a basic string = %s\n\r", ctime(&clock));
+ //Why this was printing on receive data app:
+ mypc.printf("Time as a basic string = %s\n\r", ctime(&clock));
reminder tmpReminder = myschedule.getCurrentReminder();
// CHANGE TO POTENTAILLY NOT INCREMENTING CURRENT REMINDER?
flag = 0;
+ //mypc.printf("%s\n\r", tmpReminder.notification);
while (!flag) {
+
if (tmpReminder.reminder_days[timeinfo->tm_wday] != 1) {
- // pc.printf("%i\n\r", myschedule.reminder_list[i].reminder_days[currentDay]);
+ mypc.printf("what day is it: %i %i\n\r", timeinfo->tm_wday, tmpReminder.reminder_days[timeinfo->tm_wday]);
+ //pc.printf("%i\n\r", myschedule.reminder_list[i].reminder_days[currentDay]);
i++; // current reminder not set to go off today; go to next reminder
tmpReminder = myschedule.nextReminder();
}
// may need to check if the current reminder is not last one, otherwise out of bounds ERROR
else {
time_diff = estimate_time(tmpReminder);
+ mypc.printf("time diff %i\n\r", time_diff);
//uLCD.locate(0,0);
- uLCD.printf("time_diff is %i\n\r", time_diff);
+ //uLCD.printf("time_diff is %i\n\r", time_diff);
if (time_diff < 0) {
i++;
tmpReminder = myschedule.nextReminder();
@@ -127,40 +139,43 @@
}
//wait(1);
}
- uLCD.printf("%s\n", tmpReminder.notification);
+
if (tmpReminder.notification == "App") {
- uLCD.printf("checking app\n");
+ myled3 = 1;
+ //uLCD.printf("checking app\n");
//if (timeinfo->tm_min == tmpReminder.min && timeinfo->tm_hour == tmpReminder.hour - 1) {
//if (tmpReminder.hour - timeinfo->tm_hour <= 1) {
- if (time_diff == 60) {
+ if (time_diff <= 60) {
myled = true;
synthesis(tmpReminder);
- if (myschedule.getSize() == 1) {
+ //uLCD.printf("moving to next reminder\n");
+ myschedule.nextReminder();
+ //uLCD.printf("moved to next reminder\n");
+ flag = 0;
+ dex++;
+ if (dex == stop_point){
while (1) {}
}
- uLCD.printf("moving to next reminder\n");
- myschedule.nextReminder();
- uLCD.printf("moved to next reminder\n");
- flag = 0;
}
} else {
if (timeinfo->tm_min == tmpReminder.min && timeinfo->tm_hour == tmpReminder.hour) {
myled = true;
synthesis(tmpReminder);
- uLCD.printf("moving to next reminder\n");
- if (myschedule.getSize() == 1) {
+ //uLCD.printf("moving to next reminder\n");
+ myschedule.nextReminder();
+ //uLCD.printf("moved to next reminder\n");
+ flag = 0;
+ dex++;
+ if (dex == stop_point){
while (1) {}
}
- myschedule.nextReminder();
- uLCD.printf("moved to next reminder\n");
- flag = 0;
}
}
//if (myschedule.getSize() ==
// wait(1);
}
- uLCD.printf("All reminders done for the day\n");
+ //uLCD.printf("All reminders done for the day\n");
//while(1) {}
}
}
@@ -189,10 +204,10 @@
bool flag = false;
while(!flag) {
buff[i] = pc.getc();
- uLCD.printf("%c", buff[i]);
+ //uLCD.printf("%c", buff[i]);
//blue.putc(buff[i]);
flag = buff[i] == '^';
- if (flag) uLCD.printf("flag detected");
+ //if (flag) uLCD.printf("flag detected");
i++;
}
write_schedule_sd(buff, i);
@@ -223,8 +238,8 @@
// get time
fread(time_read,1,1,fp);
if (time_read[0] != '[') {
- uLCD.locate(0,0);
- uLCD.printf("[ not found, instead found %s\r\n",time_read[0]);
+ //uLCD.locate(0,0);
+ //uLCD.printf("[ not found, instead found %s\r\n",time_read[0]);
error("Time in incorrect format, expected [, got %s\n",time_read[0]);
}
while (time_read[0] != ']') {
@@ -245,8 +260,8 @@
//fgets(reminder_size, sizeof(reminder_size), fp);
fread(reminder_size,1,1,fp);
if (reminder_size[0] != '{') {
- uLCD.locate(0,0);
- uLCD.printf("{ not found, instead found %s\r\n",reminder_size[0]);
+ //uLCD.locate(0,0);
+ //uLCD.printf("{ not found, instead found %s\r\n",reminder_size[0]);
error("Schedule in incorrect format, expected {, got %s\n",reminder_size[0]);
}
while (header) {
@@ -256,12 +271,12 @@
if (test[0] == '|') header = 0;
else {
//uLCD.printf("%s %i",reminder_size[0], (int)reminder_size[0]);
- uLCD.printf("%c",test[0]);
+ //uLCD.printf("%c",test[0]);
//wait(4);
reminder_count = (reminder_count*10)+(test[0] - '0');
}
}
- uLCD.cls();
+ //uLCD.cls();
//uLCD.locate(0,0);
//uLCD.printf("parsing schedule reminder count is %i\r\n", reminder_count);
//wait(5);
@@ -272,32 +287,32 @@
for (int i = 0; i < reminder_count; i++) {
//fgets(buf, sizeof(buf), fp);
fread(buf,sizeof(buf),1,fp);
- uLCD.cls();
- uLCD.locate(0,0);
- uLCD.printf("buf is %s\r\n",buf);
+ //uLCD.cls();
+ //uLCD.locate(0,0);
+ //uLCD.printf("buf is %s\r\n",buf);
wait(.1);
char *pch;
pch = strtok (buf,"+");
tmp.notification = pch;
- uLCD.printf("%s\n", pch);
+ //uLCD.printf("%s\n", pch);
wait(.1);
pch = strtok (NULL,"+");
//uLCD.printf("%s\n", pch);
if (strlen(pch) == 1) tmp.hour = (int) (pch[0] - '0');
else tmp.hour = (int) ((pch[0] - '0') * 10 + (pch[1] - '0'));
//if (tmp.hour > 24
- uLCD.printf("%i\n", tmp.hour);
+ //uLCD.printf("%i\n", tmp.hour);
//wait(1);
pch = strtok (NULL,"+");
if (strlen(pch) == 1) tmp.min = (int) (pch[0] - '0');
else tmp.min = (int) ((pch[0] - '0') * 10 + (pch[1] - '0'));
- uLCD.printf("%i\n", tmp.min);
+ //uLCD.printf("%i\n", tmp.min);
wait(.1);
pch = strtok (NULL,"+");
for (int i = 0; i < 7; i++) {
tmp.reminder_days[i] = (int) pch[i] - '0';
//days = days/10;
- uLCD.printf("%i\n", tmp.reminder_days[i]);
+ //uLCD.printf("%i\n", tmp.reminder_days[i]);
//wait(.1);
}
@@ -306,8 +321,8 @@
wait(5);
}
fclose(fp);
- uLCD.cls();
- uLCD.printf("returned time here");
+ //uLCD.cls();
+ //uLCD.printf("returned time here");
return set_time;
}
@@ -319,14 +334,14 @@
void packdata(int send)
{
-
+ /*
dateTime testdt;
testdt.month = 1;
testdt.day = 2;
testdt.year = 2009;
myschedule.updateRecord(testdt, 1);
myschedule.updateRecord(testdt, 0);
-
+ */
int rem_num = 0; // number of reminders
char con[2];
string record_str = "";
@@ -334,9 +349,9 @@
int data_entries;
record tmpr;
dateTime tmpd;
- uLCD.printf("test start\r\n");
+ //uLCD.printf("test start\r\n");
for (int i = 0; i < myschedule.getSize(); i++) {
- uLCD.printf("schedule entries exist\r\n");
+ //uLCD.printf("schedule entries exist\r\n");
data_entries = myschedule.getNumRecords(i);
if (data_entries) { // more than 1 data entry
rem_num++;
@@ -347,19 +362,19 @@
tmpr = myschedule.getRecord(i);
for (int j = 0; j < data_entries; j++) {
tmpd = tmpr.date[j];
- char tmpmon[2], tmpday[2], tmpyear[2];
- sprintf(tmpmon, "%d", tmpd.month);
- sprintf(tmpday, "%d", tmpd.day);
- sprintf(tmpyear, "%d", tmpd.year);
+ char tmpmon[2], tmpday[2], tmpyear[4];
+ sprintf(tmpmon, "%i", tmpd.month);
+ sprintf(tmpday, "%i", tmpd.day);
+ sprintf(tmpyear, "%i", tmpd.year);
part = "[";
if (tmpd.month < 10) part += "0";
part += (string) tmpmon + "-";
if (tmpd.day < 10) part += "0";
part += (string)tmpday + "-" + (string)tmpyear + "]";
char tmpval[1];
- sprintf(tmpval, "%d", tmpr.data[j]);
+ sprintf(tmpval, "%i", tmpr.data[j]);
part += tmpval;
- uLCD.printf("%s\r\n", part.c_str());
+ //uLCD.printf("%s\r\n", part.c_str());
//part = "[" + tmpd.month + "-" + tmpd.day + "-" + tmpd.year + "]";
record_str += part;
}
@@ -368,8 +383,8 @@
char remnum[2];
sprintf(remnum, "%d", rem_num);
record_str = "{" + (string)remnum + record_str + "}";
- uLCD.printf("%s\r\n", record_str.c_str());
- uLCD.printf("starting data record write\r\n");
+ //uLCD.printf("%s\r\n", record_str.c_str());
+ //uLCD.printf("starting data record write\r\n");
// save data to buffer
@@ -392,7 +407,7 @@
void writetest()
{
- uLCD.printf("starting test\r\n");
+ //uLCD.printf("starting test\r\n");
char *buffer = "hello1";
mkdir("/sd/mydir", 0777);
FILE *fp = fopen("/sd/mydir/data.txt", "w");
@@ -401,7 +416,7 @@
}
fprintf(fp, buffer);
fclose(fp);
- uLCD.printf("first opened\r\n");
+ //uLCD.printf("first opened\r\n");
char *buffer2 = "good2";
FILE *fq = fopen("/sd/mydir/data.txt", "w");
if(fq == NULL) {
@@ -409,7 +424,7 @@
}
fprintf(fq, buffer2);
fclose(fq);
- uLCD.printf("second opened\r\n");
+ //uLCD.printf("second opened\r\n");
char open[10];
@@ -418,8 +433,8 @@
error("Could not open file to read\n");
}
fread(open,sizeof(open),8,fw);
- uLCD.printf("%s", open);
- uLCD.printf("should have printed\r\n");
+ //uLCD.printf("%s", open);
+ //uLCD.printf("should have printed\r\n");
}
@@ -445,7 +460,7 @@
void synthesis(reminder x)
{
- uLCD.printf("speaking syn\n");
+ //uLCD.printf("speaking syn\n");
if(x.notification == "App") {
speak(synWords[3]);
wait(0.001);
@@ -457,6 +472,7 @@
int repeat = 0;
int response = 0;
while (asking) {
+ mypc.printf("asking\r\n");
speak(synWords[2]);
wait(0.001);
//ask if they've taken their medication
@@ -468,7 +484,9 @@
easyVR.putc('B');
clock_t endwait;
endwait = clock() + 60 * CLOCKS_PER_SEC ;
- while (easyVR.readable()!=0 && clock() < endwait) {}
+ while (easyVR.readable()!=0 && clock() < endwait) {
+ mypc.printf("listening\r\n");
+ }
if (clock() < endwait) {
response = 1;
//asking = 0;
@@ -486,22 +504,22 @@
easyVR.putc(' ');
rchar = easyVR.getc();
//for a yes response
- if (rchar=='A' || rchar=='C' || rchar=='E' || rchar=='G' || rchar == 'I' || rchar == 'K') {
- uLCD.printf("yes");
+ if (rchar=='A' || rchar=='C' || rchar=='D' || rchar=='F' || rchar == 'J') {
+ //uLCD.printf("yes");
//yes++;
//response++;
result = 1;
- } else if (rchar == 'B' || rchar=='D' || rchar=='F' || rchar=='H' || rchar=='J' || rchar=='K') {
- uLCD.printf("no");
+ } else if (rchar == 'B' || rchar=='E' || rchar=='G' || rchar=='I' || rchar=='K') {
+ //uLCD.printf("no");
result = 0;
//no++;
//response++;
}
asking = 0;
- uLCD.printf("asking = 0\n");
+ //uLCD.printf("asking = 0\n");
} else if (rchar == 'e') {
- uLCD.printf("error");
+ //uLCD.printf("error");
result = -1;
repeat++;
if (repeat > 2) {
@@ -509,15 +527,19 @@
asking = 0;
// try again
}
- } else uLCD.printf("%c ",rchar);
+ } // else uLCD.printf("%c ",rchar);
}
}
- uLCD.printf("done\n");
+ //uLCD.printf("done\n");
dateTime dt_record;
- dt_record.month = timeinfo->tm_mday;
- dt_record.day = timeinfo->tm_mon+1; // days since january (0-11) so add 1
- dt_record.year = timeinfo->tm_year + 1990; // years since 1990
+ dt_record.month = timeinfo->tm_mon+1; // months since january (0-11) so add 1
+ dt_record.day = timeinfo->tm_mday;
+ dt_record.year = timeinfo->tm_year + 1900; // years since 1990
+ mypc.printf("month %i\r\n", dt_record.month);
+ mypc.printf("day %i\r\n", dt_record.day);
+ mypc.printf("year %i\r\n", dt_record.year);
+ mypc.printf("result %i\r\n", result);
myschedule.updateRecord(dt_record, result);
// do error checking for no response
//thank the user
@@ -531,14 +553,15 @@
void synTimes(reminder x)
{
- uLCD.printf("speaking time\n");
+ //uLCD.printf("speaking time\n");
// schedule.reminder_list....
// x is selected reminder
//two switch case statements: one for if the second number is a 5, one if it's a 0
int ampm = 0;
int hour = x.hour;
- if(x.hour > 12) {
- hour = x.hour % 12;
+ if(x.hour >= 12) {
+ if (x.hour != 12)
+ hour = x.hour % 12;
ampm = 24;
} else
ampm = 22;
@@ -606,7 +629,7 @@
}
}
speak(ampm);
- uLCD.printf("done speaking\n");
+ //uLCD.printf("done speaking\n");
}
/*
void pb1_hit_callback (void) {
@@ -616,14 +639,15 @@
void pb1_hit_interrupt (void)
{
- uLCD.printf("push button 1 pressed - send schedule\n");
+ //uLCD.printf("push button 1 pressed - send schedule\n");
//receive_schedule();
packdata(1);
}
+//what does this function do if it only wrote to the uLCD?
void pb2_hit_interrupt (void)
{
- uLCD.printf("push button 2 pressed - cognitive game\n");
+ //uLCD.printf("push button 2 pressed - cognitive game\n");
}
@@ -638,13 +662,13 @@
*/
int correct = 0;
int timesplayed;
- uLCD.printf("Speak: Your recall wordset will now play\n");
+ //uLCD.printf("Speak: Your recall wordset will now play\n");
// speak(recall game)
wait(3);
int wordset = rand() % 5; // pick random wordset between 1 and 5
- uLCD.printf("Playing wordset %i\n", wordset);
+ //uLCD.printf("Playing wordset %i\n", wordset);
switch(wordset) {
case 0: {
//speak(wordset1);
@@ -668,6 +692,6 @@
}
}
- uLCD.printf("Was _____ the first word in the set?\n");
- uLCD.printf("Was _____ the last word in the set?\n");
+ //uLCD.printf("Was _____ the first word in the set?\n");
+ //uLCD.printf("Was _____ the last word in the set?\n");
}
\ No newline at end of file