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: SPI_TFT_ILI9341 TFT_fonts Adafruit_RTCLib RTC-DS1307 TSI
utility.cpp
00001 #include "utility.h" 00002 00003 00004 TimeClass::TimeClass (int h, int m, float s) 00005 : hour(h), minute(m), second(s) {} 00006 00007 void TimeClass::inc(TimeClass *prev, float i) { 00008 prev->second = this->second; 00009 prev->minute = this->minute; 00010 prev->hour = this->hour; 00011 this->second += i; 00012 if (this->second >= 60) { 00013 this->second = 0; 00014 this->minute += 1; 00015 } 00016 00017 if (this->minute == 60) { 00018 this->minute = 0; 00019 this->hour += 1; 00020 } 00021 00022 if (this->hour == 24) 00023 this->hour = 0; 00024 } 00025 00026 DateClass::DateClass(int d, int m, int y, int dow) 00027 : day(d), month(m), year(y), dow(dow) {} 00028 00029 WeatherClass::WeatherClass(weatherType t, int tmp, bool cel, char *p) 00030 : type(t), temp(tmp), isCelsius(cel), place(p) {} 00031 00032 StateClass::StateClass(TimeClass *t, TimeClass *p, WeatherClass *w, DateClass *d, TimeClass *a) 00033 : time(t), prevTime(p), weather(w), date(d), alarm(a), screenState(0), screenActive(true), duringAlarm(false) {} 00034 00035 00036 void playAlarmSound() 00037 { 00038 PwmOut speaker(ALARM_PIN); // alarm sound of regular beeps 00039 while (programState->duringAlarm) { 00040 speaker.period(1.0/150.0); // 150hz period 00041 speaker =0.0125; 00042 wait(0.5); 00043 speaker=0.0; // turn off audio 00044 wait(0.5); 00045 } 00046 } 00047 00048 AnalogIn ain(RANGE_AN); 00049 DigitalOut cs(RANGE_CS, 0); 00050 00051 bool getDistance() 00052 { 00053 float adc, volts, inches; 00054 cs = 1; 00055 wait_us(30); 00056 adc = ain.read(); // read analog as a float 00057 volts = adc * 4.5; // convert to volts 00058 inches = volts / 0.0095; 00059 cs = 0; 00060 return inches <= RANGE_THRESHOLD; 00061 } 00062 00063 //I2C master(RTC_SDA, RTC_SCL); 00064 Rtc_Ds1307 rtc(RTC_SDA, RTC_SCL); 00065 void read_rtc(StateClass *ps) 00066 { 00067 Rtc_Ds1307::Time_rtc data = {}; 00068 int s = 0, m = 0, h = 0, dow = 0, d = 0, mo = 0, y = 0; 00069 //rtc.gettime(&s, &m, &h, &dow, &d, &mo, &y); 00070 rtc.getTime(data); 00071 h = data.hour; 00072 m = data.min; 00073 s = data.sec; 00074 dow = data.wday - 1; 00075 d = data.date; 00076 mo = data.mon; 00077 y = data.year; 00078 LOG("%d:%d:%d", h, m, s); 00079 //if (!rtc.isRunning()) 00080 // return; 00081 ps->time->hour = h; 00082 ps->prevTime->hour = h; 00083 ps->time->minute = m; 00084 ps->prevTime->minute = m; 00085 ps->time->second = s; 00086 ps->prevTime->second = s; 00087 ps->date->year = y; 00088 ps->date->day = d; 00089 ps->date->month = mo; 00090 ps->date->dow = dow-1; 00091 } 00092 00093 void update_rtc(StateClass *ps) 00094 { 00095 //DateTime data(ps->date->year, ps->date->month, ps->date->day, ps->time->hour, ps->time->minute, ps->time->second); 00096 //rtc.adjust(data); 00097 }
Generated on Wed Jul 13 2022 17:42:29 by
