Project
Dependencies: Hotboards_keypad TextLCD eeprom
Revision 0:194ff03a2e6a, committed 2018-10-23
- Comitter:
- shivanandgowdakr
- Date:
- Tue Oct 23 08:12:53 2018 +0000
- Child:
- 1:1894419d5def
- Commit message:
- HI
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.gitignore Tue Oct 23 08:12:53 2018 +0000 @@ -0,0 +1,4 @@ +.build +.mbed +projectfiles +*.py*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Hotboards_keypad.lib Tue Oct 23 08:12:53 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/Exultsoft1/code/Hotboards_keypad/#90db1fc5aa6f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LCDDisplay.cpp Tue Oct 23 08:12:53 2018 +0000
@@ -0,0 +1,51 @@
+#include "mbed.h"
+#include "TextLCD.h"
+#include <string>
+#include "Time.h"
+
+#define LCD_RS PC_2
+#define LCD_EN PC_3
+#define LCD_D4 PA_13
+#define LCD_D5 PA_14
+#define LCD_D6 PA_15
+#define LCD_D7 PB_7
+
+
+
+TextLCD lcd {LCD_RS,LCD_EN,LCD_D4,LCD_D5,LCD_D6,LCD_D7,TextLCD::LCD16x2};
+
+
+void Display_LCD(int col,int row,char *str)
+{
+
+lcd.locate(col,row);
+lcd.printf("%s",str);
+
+}
+void Clear_LCD(void)
+{
+ lcd.cls();
+}
+
+void Display_time(void)
+{
+ // Disable Interrupts
+ while(1)
+ {
+// do something that can't be interrupted
+ // Thread::signal_wait(0x1);
+ time_t curr_time;
+ tm * curr_tm;
+ char date_string[10];
+ char time_string[10];
+ time(&curr_time);
+ curr_tm = localtime(&curr_time);
+ strftime(date_string, 10, "%d%b%y", curr_tm);
+ strftime(time_string, 10, " %T", curr_tm);
+ lcd.locate(0,1);
+ lcd.printf("%s",date_string);
+ lcd.printf("%s",time_string);
+ wait(1);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LCDDisplay.h Tue Oct 23 08:12:53 2018 +0000 @@ -0,0 +1,10 @@ +#include <string> +#ifndef MBED_LCDDISPLAY_H +#define MBED_LCDDISPLAY_H + + +void Display_LCD(int,int,string); +void Display_LCD(int col,int row,char *str); +void Clear_LCD(void); +void Display_time(void); +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Tue Oct 23 08:12:53 2018 +0000 @@ -0,0 +1,57 @@ +# Getting started with Blinky on mbed OS + +This guide reviews the steps required to get Blinky working on an mbed OS platform. + +Please install [mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli). + +## Import the example application + +From the command-line, import the example: + +``` +mbed import mbed-os-example-blinky +cd mbed-os-example-blinky +``` + +### Now compile + +Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5: + +``` +mbed compile -m K64F -t ARM +``` + +Your PC may take a few minutes to compile your code. At the end, you see the following result: + +``` +[snip] ++----------------------------+-------+-------+------+ +| Module | .text | .data | .bss | ++----------------------------+-------+-------+------+ +| Misc | 13939 | 24 | 1372 | +| core/hal | 16993 | 96 | 296 | +| core/rtos | 7384 | 92 | 4204 | +| features/FEATURE_IPV4 | 80 | 0 | 176 | +| frameworks/greentea-client | 1830 | 60 | 44 | +| frameworks/utest | 2392 | 512 | 292 | +| Subtotals | 42618 | 784 | 6384 | ++----------------------------+-------+-------+------+ +Allocated Heap: unknown +Allocated Stack: unknown +Total Static RAM memory (data + bss): 7168 bytes +Total RAM memory (data + bss + heap + stack): 7168 bytes +Total Flash memory (text + data + misc): 43402 bytes +Image: .\.build\K64F\ARM\mbed-os-example-blinky.bin +``` + +### Program your board + +1. Connect your mbed device to the computer over USB. +1. Copy the binary file to the mbed device. +1. Press the reset button to start the program. + +The LED on your platform turns on and off. + +## Troubleshooting + +If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Tue Oct 23 08:12:53 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/davervw/code/TextLCD/#c5318c74f1a9
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Time.cpp Tue Oct 23 08:12:53 2018 +0000
@@ -0,0 +1,184 @@
+#include "mbed.h"
+#include "Time.h"
+#include "LCDDisplay.h"
+#include <string>
+
+int Date_Time_Setting(struct tm curt,char *str)
+{
+ int len=0;
+ len= strlen(str);
+ // printf("len = %d",len);
+ if(len < 14)
+ return 0;
+
+ curt.tm_mday = ( str[0]-0x30)*10+(str[1]-0x30);
+ curt.tm_mon = ( str[2]-0x30)*10+(str[3]-0x30) -1;
+ curt.tm_year = (( str[4]-0x30)*1000 + (str[5]-0x30)*100 + (str[6]-0x30)*10 + (str[7]-0x30)) -1900 ;
+
+ curt.tm_hour=(str[8]-0x30)*10+(str[9]-0x30);
+ curt.tm_min=(str[10]-0x30)*10+(str[11]-0x30);
+ curt.tm_sec=(str[12]-0x30)*10+(str[13]-0x30);
+
+ time_t epoch = mktime(&curt);
+ if (epoch == (time_t) -1) {
+ error("Error in clock setting\n");
+ // Stop here
+ }
+ set_time(epoch);
+ return 1;
+}
+
+
+int iSetTerminalTime(char *tstring)
+{
+ int ret=0;
+ struct tm curt;
+
+ ret = Date_Time_Setting(curt,tstring);
+
+ if(ret == 1) {
+ wait(1);
+
+ Display_LCD(0,0," DATE-TIME ");
+ Display_LCD(0,1," SET SUCCESS ");
+ printf("Date Time Set succesfully\r\n");
+
+ } else {
+ Display_LCD(0,0," DATE-TIME ");
+ Display_LCD(0,1," SET FAILURE ");
+ printf("Date Time Set Failure \r\n");
+
+ }
+ wait(1);
+// Clear_LCD();
+
+ return ret;
+}
+
+
+int chk_time (char *str)
+{
+ int HH,MM,SS;
+ HH=(str[0]-0x30)*10+(str[1]-0x30);
+ MM=(str[2]-0x30)*10+(str[3]-0x30);
+ SS=(str[4]-0x30)*10+(str[5]-0x30);
+ if ( HH < 0 || HH > 23 || MM < 0 || MM > 59 || SS < 0 || SS > 59 )
+ return -1;
+ return 1;
+}
+
+int chk_date (char *str)
+{
+ int epos_date=0,epos_month=0,epos_year=0;
+ epos_date = ( str[0]-0x30)*10+(str[1]-0x30);
+ epos_month = ( str[2]-0x30)*10+(str[3]-0x30);
+ epos_year = ( str[4]-0x30)*1000+ (str[5]-0x30)*100 + (str[6]-0x30)*10 + (str[7]-0x30);
+
+
+ if ( epos_month < 1 || epos_date < 1 || epos_date > 31 || epos_month > 12 || epos_year < 2008 ) return ERROR ;
+
+ else if(epos_month == 1 || epos_month == 3 || epos_month == 5 || epos_month == 7 || epos_month == 8 || epos_month ==10 ||epos_month == 12) {
+
+ if (epos_date > 31)
+ return -1;
+ }
+
+ else if (epos_month == 4 || epos_month == 6 || epos_month == 9 || epos_month == 11) {
+
+ if (epos_date > 30)
+ return -1;
+ }
+
+ else if (epos_month == 2 )
+
+ {
+ if ( !(epos_year%400) || (epos_year%100 != 0 && epos_year%4==0 ) ) {
+ if (epos_date > 29 ) return -1;
+ }
+
+ else if( epos_date > 28 ) return -1;
+ }
+ return 1;
+}
+
+void Get_Date_Time(char *date_string,char *time_string, char *DTSTRING)
+{
+ time_t curr_time;
+ tm * curr_tm;
+ time(&curr_time);
+ curr_tm = localtime(&curr_time);
+ strftime(date_string,10,"%Y%m%d",curr_tm);
+ strftime(time_string,10,"%H%M%S",curr_tm);
+ strftime(DTSTRING,20,"%Y%m%d%H%M%S",curr_tm);
+}
+
+void Get_Date_Time(char *date_string,char *time_string)
+{
+ time_t curr_time;
+ tm * curr_tm;
+ time(&curr_time);
+ curr_tm = localtime(&curr_time);
+ strftime(date_string,10,"%Y%m%d",curr_tm);
+ strftime(time_string,10,"%H%M%S",curr_tm);
+
+}
+
+
+void Get_Date_Time( char *DTSTRING)
+{
+ time_t curr_time;
+ tm * curr_tm;
+ time(&curr_time);
+ curr_tm = localtime(&curr_time);
+ strftime(DTSTRING,20,"%Y%m%d%H%M%S",curr_tm);
+}
+
+void Get_Date_Time_Trns( char *DTSTRING)
+{
+ time_t curr_time;
+ tm * curr_tm;
+ time(&curr_time);
+ curr_tm = localtime(&curr_time);
+ strftime(DTSTRING,20,"%d%m%Y%H%M%S",curr_tm);
+}
+
+
+
+int is_12_O_Clock_Night(void)
+{
+ char dat[9]={'\0'};
+char tim[9]={'\0'};
+int HH,MM;
+ Get_Date_Time(dat,tim);
+ HH=(tim[0]-0x30)*10+(tim[1]-0x30);
+ MM=(tim[2]-0x30)*10+(tim[3]-0x30);
+
+ if((HH==0) &&(MM <59))
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+
+int is_6_O_Clock(void)
+{
+char dat[9]={'\0'};
+char tim[9]={'\0'};
+int HH,MM;
+ Get_Date_Time(dat,tim);
+ HH=(tim[0]-0x30)*10+(tim[1]-0x30);
+ MM=(tim[2]-0x30)*10+(tim[3]-0x30);
+
+ if((HH==6) &&(MM <30))
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Time.h Tue Oct 23 08:12:53 2018 +0000 @@ -0,0 +1,18 @@ + +#ifndef MBED_TIME_H +#define MBED_TIME_H +#include "mbed.h" + + +int Date_Time_Setting(struct tm curt,char *str); +int iSetTerminalTime(char *tstring); +int chk_time (char *str); +int chk_date (char *str); +void Get_Date_Time(char *date_string,char *time_string, char *DTSTRING); +void Get_Date_Time( char *DTSTRING); +void Get_Date_Time_Trns( char *DTSTRING); +int is_12_O_Clock_Night(void); +int is_6_O_Clock(void); +void Get_Date_Time(char *date_string,char *time_string); + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/eeprom.lib Tue Oct 23 08:12:53 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/Exultsoft1/code/eeprom/#78ca3fcb8db1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/i2ceeprom.cpp Tue Oct 23 08:12:53 2018 +0000
@@ -0,0 +1,138 @@
+
+
+// Example
+
+#include <string>
+#include "mbed.h"
+#include "eeprom.h"
+
+#define EEPROM_ADDR 0x02 // I2C EEPROM address is 0x00
+
+#define SDA D14 // I2C SDA pin
+#define SCL D15 // I2C SCL pin
+
+#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
+#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
+
+extern float G_time;
+extern float Y_time;
+extern float R_time;
+
+
+int32_t eeprom_size,max_size;
+typedef struct _MyData {
+ int16_t sdata;
+ int32_t idata;
+ float fdata;
+ } MyData;
+
+static void myerror(std::string msg)
+{
+ printf("Error %s\n",msg.c_str());
+ exit(1);
+}
+
+void StoreCurrentMode(int32_t idata)
+{
+ EEPROM ep(SDA,SCL,EEPROM_ADDR,EEPROM::T24C128); // 24C64 eeprom with sda = p9 and scl = p10
+ eeprom_size = ep.getSize();
+ max_size = MIN(eeprom_size,256);
+ ep.write((uint32_t)(eeprom_size - 200),(int32_t)idata); // long write at address eeprom_size - 12
+ if(ep.getError() != 0)
+ myerror(ep.getErrorMessage());
+// printf("\n");
+ ep.read((eeprom_size - 12),(int32_t&)idata);
+ // printf("TransDC Read %d\r\n",idata);
+}
+
+
+
+int32_t readCurrentMode()
+{
+ int32_t idata;
+ EEPROM ep(SDA,SCL,EEPROM_ADDR,EEPROM::T24C128); // 24C64 eeprom with sda = p9 and scl = p10
+ eeprom_size = ep.getSize();
+ max_size = MIN(eeprom_size,256);
+ ep.read((eeprom_size - 200),(int32_t&)idata);
+
+ if(ep.getError() != 0)
+ myerror(ep.getErrorMessage());
+// printf("\n");
+ // printf("Trans Down Count Read %d\r\n",idata);
+ return idata;
+}
+
+bool WriteCorresspondingTimes(uint32_t currentMode, float gTime,float yTime,float rTime)
+{
+ EEPROM ep(SDA,SCL,EEPROM_ADDR,EEPROM::T24C128); // 24C64 eeprom with sda = p9 and scl = p10
+ eeprom_size = ep.getSize();
+ max_size = MIN(eeprom_size,256);
+
+ uint32_t addr = eeprom_size - (currentMode*12);
+ ep.write(addr,(float)gTime); // float write at address eeprom_size - 8
+ if(ep.getError() != 0)
+ myerror(ep.getErrorMessage());
+
+ // Test read short, long, float
+ printf("\nGreen Time : (%f) :\n",gTime);
+
+
+ addr = eeprom_size - ((currentMode*12)-4);
+ ep.write(addr,(float)yTime); // float write at address eeprom_size - 8
+ if(ep.getError() != 0)
+ myerror(ep.getErrorMessage());
+
+ // Test read short, long, float
+ printf("\nYellow Time : (%f) :\n",yTime);
+
+ addr = eeprom_size - ((currentMode*12)-8);
+ ep.write(addr,(float)rTime); // float write at address eeprom_size - 8
+ if(ep.getError() != 0)
+ myerror(ep.getErrorMessage());
+
+ // Test read short, long, float
+ printf("\nRed Time : (%f) :\n",rTime);
+
+
+}
+
+
+bool ReadCorresspondingTimes(uint32_t currentMode, float *gTime,float *yTime,float *rTime)
+{
+ float fdata=0.0;
+ EEPROM ep(SDA,SCL,EEPROM_ADDR,EEPROM::T24C128); // 24C64 eeprom with sda = p9 and scl = p10
+ eeprom_size = ep.getSize();
+ max_size = MIN(eeprom_size,256);
+ ep.read((eeprom_size - (currentMode*12)),(float&)fdata);
+
+ if(ep.getError() != 0)
+ myerror(ep.getErrorMessage());
+// printf("\n");
+ // printf("Trans Down Count Read %d\r\n",idata);
+ *gTime=fdata;
+ fdata=0.0;
+ ep.read((eeprom_size - (currentMode*12)-4),(float&)fdata);
+
+ if(ep.getError() != 0)
+ myerror(ep.getErrorMessage());
+// printf("\n");
+ // printf("Trans Down Count Read %d\r\n",idata);
+ *yTime=fdata;
+ fdata=0.0;
+ ep.read((eeprom_size - (currentMode*12)-8),(float&)fdata);
+
+ if(ep.getError() != 0)
+ myerror(ep.getErrorMessage());
+// printf("\n");
+ // printf("Trans Down Count Read %d\r\n",idata);
+ *rTime=fdata;
+}
+
+
+
+void Last_Saved_Mode()
+{
+ //float Gtime=0,Ytime=0, Rtime=0;
+ int32_t CurrentMode= readCurrentMode();
+ bool flag= ReadCorresspondingTimes( CurrentMode, &G_time,&Y_time, &R_time);
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/i2ceeprom.h Tue Oct 23 08:12:53 2018 +0000 @@ -0,0 +1,12 @@ +#ifndef I2CEEPROM_H +#define I2CEEPROM_H +#include "mbed.h" + +static void myerror(std::string msg); +void StoreCurrentMode(int32_t idata); +int32_t readCurrentMode(); +bool WriteCorresspondingTimes(uint32_t currentMode, float gTime,float yTime,float rTime); +bool ReadCorresspondingTimes(uint32_t currentMode, float *gTime,float *yTime,float *rTime); +void Last_Saved_Mode(); + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Oct 23 08:12:53 2018 +0000
@@ -0,0 +1,862 @@
+
+
+#include "mbed.h"
+#include "LCDDisplay.h"
+#include "i2ceeprom.h"
+#include "Hotboards_keypad.h"
+#include "Hotboards_keypad.h"
+
+// Defines the keys array with it's respective number of rows & cols,
+// and with the value of each key
+char keys[ 4 ][ 4 ] =
+{
+ { '1' , '2' , '3' , 'A' },
+ { '4' , '5' , '6' , 'B' },
+ { '7' , '8' , '9' , 'C' },
+ { '*' , '0' , '#' , 'D' }
+};
+
+// Defines the pins connected to the rows
+DigitalInOut rowPins[ 4 ] = {D4,D5,D6,D7 };
+// Defines the pins connected to the cols
+DigitalInOut colPins[ 4 ] = { D8,D9,D10,D11};
+ //connect to the column pinouts of the keypad
+
+Keypad keypad( makeKeymap( keys ), rowPins, colPins,4,4);
+
+DigitalIn Mode1(PC_8);
+DigitalIn Mode2(PC_6);
+DigitalIn Mode3(PC_5);
+//DigitalIn Mode4(PC_5);
+//DigitalIn Mode5(PC_8);
+//DigitalIn Mode6(PC_6);
+
+bool PasswordStatus=false;
+int mode=0;
+DigitalIn Start(PA_12);
+DigitalIn Stop(PA_11);
+DigitalIn Reset(PB_12);
+
+
+DigitalOut GreenLight(PB_1);
+DigitalOut YellowLight(PB_15);
+DigitalOut RedLight(PB_14);
+DigitalOut SpareLight(PB_13);
+DigitalOut Buzzer(PC_13);
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+
+
+
+uint32_t Current_Mode=0;
+
+float G_time=0;
+float Y_time=0;
+float R_time=0;
+
+uint8_t StartButtonPressed=0;
+uint8_t StopButtonPressed=0;
+uint8_t ReStartButtonPressed=0;
+Timer timer;
+Timer timerred;
+//Thread EveryOneSec;
+
+void keypadEvent(KeypadEvent key);
+bool ReadEachLightTime(int mode,char *mmss);
+bool ReadAllTimesofEachMode(int MODE,char *Greentime,char *Yellowtime,char *Redtime);
+void ExtractTimesinSecs(char *greentime,char *yellowtime,char *redtime,float *grntim,float *yeltim,float *redtim);
+void SaveTimes(int Mode,float GreenTime,float YellowTime,float RedTime);
+void CalculateTimeElapsed(float TimeElapsed, char *TimeStr);
+bool PasswordAcceptance();
+int ModeSelectTochange();
+void fn(char rkey);
+int main()
+{
+ bool start=false;
+ Mode1.mode(PullUp);
+ Mode2.mode(PullUp);
+ Mode3.mode(PullUp);
+// Mode4.mode(PullUp);
+// Mode5.mode(PullUp);
+// Mode6.mode(PullUp);
+ bool lcdflag=true;
+ Start.mode(PullUp);
+ Stop.mode(PullUp);
+ Reset.mode(PullUp);
+
+ float timeElapsed=0;
+ char buff[6]= {'\0'};
+ char Buffer[17]= {'\0'};
+ Clear_LCD();
+ Display_LCD(0,0," Initialising ");
+ SpareLight=1;
+ GreenLight=1;
+ YellowLight=1;
+ RedLight=1;
+ wait(1);
+ Clear_LCD();
+ //Current_Mode=1;
+ Display_LCD(0,0,"Select Mode Or");
+ Display_LCD(0,1,"Press Start ");
+ G_time=20;
+ Y_time=5;
+ R_time=10;
+ char key;
+ while(1) {
+
+
+ key=keypad.getKey();
+ if(key)
+ {
+ if(key=='*')
+ {
+ PasswordStatus=PasswordAcceptance();
+ }
+ if(PasswordStatus==true)
+ {
+ PasswordStatus=false;
+ mode= ModeSelectTochange();
+ if(mode>=1 && mode <=6)
+ {
+ fn((char)(mode+0x30));
+ mode=0;
+ }
+ else
+ {
+ Display_LCD(0,0," Invalid Mode ");
+ Display_LCD(0,1,"Mode b/w 1-6 ");
+ wait(2);
+
+ Clear_LCD();
+ Display_LCD(0,0,"Select Mode Or");
+ Display_LCD(0,1,"Press Start ");
+
+ }
+ }
+
+ else if(key=='A')
+ {
+ printf("Started \r\n");
+ StartButtonPressed=1;
+ StopButtonPressed=0;
+ ReStartButtonPressed=0;
+ printf("Started ************ %d \r\n",StartButtonPressed);
+ printf("Started ############## %d \r\n",StopButtonPressed);
+ printf("Started 88888888888888%d \r\n",ReStartButtonPressed);
+ timer.start();
+
+ }
+
+ else if(key=='B')
+ {
+ StartButtonPressed=0;
+ StopButtonPressed=1;
+ ReStartButtonPressed=0;
+
+ printf("Stopped \r\n");
+ wait(0.2);
+ }
+ else if(key=='C')
+ {
+ StartButtonPressed=0;
+ StopButtonPressed=0;
+ ReStartButtonPressed=1;
+ timer.stop();
+ printf("Reset \r\n");
+ wait(0.2);
+ }
+
+ else if(key=='D')
+ {
+ Clear_LCD();
+ Display_LCD(0,0,"Choose Mode");
+ wait(0.5);
+ char tempkey=keypad.waitForKey();
+ if(tempkey>=0x31 && tempkey<=0x36)
+ {
+ char Buff[20]={'\0'};
+ sprintf(Buff,"Current Mode %c",tempkey);
+ Display_LCD(0,1,Buff);
+ Current_Mode=(int)(tempkey-0x30);
+ wait(1);
+ Clear_LCD();
+
+ }
+ else
+ {
+ Display_LCD(0,0,"Invld Mod Entrd");
+ wait(1);
+ Clear_LCD();
+
+ }
+ }
+ else
+ {}
+
+ }
+
+
+// if(Mode1==0)
+ if(Current_Mode==1)
+ {
+ printf("Am here in Mode 1\r\n");
+ G_time=20;
+ Y_time=5;
+ R_time=10;
+
+// ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time);
+ printf("Current MOde 1 \r\n");
+// Display_LCD(0,1,"Mode: 1");
+ Y_time=Y_time+G_time;
+ R_time=R_time+Y_time;
+ wait(0.2);
+ }
+
+// if(Mode2==0)
+ if(Current_Mode==2)
+ {
+
+ G_time=2;
+ Y_time=5;
+ R_time=1;
+ Current_Mode=2;
+// ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time);
+ printf("Current MOde 2 \r\n");
+// Display_LCD(0,1,"Mode: 2");
+ Y_time=Y_time+G_time;
+ R_time=R_time+Y_time;
+ wait(0.1);
+ }
+
+// if(Mode3==0)
+ if(Current_Mode==3)
+ {
+
+ G_time=12;
+ Y_time=5;
+ R_time=10;
+ Current_Mode=3;
+// ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time);
+ printf("Current MOde 3 \r\n");
+// Display_LCD(0,1,"Mode: 3");
+ Y_time=Y_time+G_time;
+ R_time=R_time+Y_time;
+ wait(0.1);
+ }
+
+
+ // if(Mode4==0)
+ if(Current_Mode==4)
+ {
+
+ G_time=20;
+ Y_time=5;
+ R_time=10;
+ Current_Mode=4;
+// ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time);
+ printf("Current MOde 1 \r\n");
+ Display_LCD(0,1,"Mode: 4");
+ Y_time=Y_time+G_time;
+ R_time=R_time+Y_time;
+ wait(0.2);
+ }
+//
+ if(Current_Mode==5)
+ {
+
+ G_time=2;
+ Y_time=5;
+ R_time=1;
+ Current_Mode=5;
+ printf("Current MOde 2 \r\n");
+// ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time);
+ Display_LCD(0,1,"Mode: 5");
+ Y_time=Y_time+G_time;
+ R_time=R_time+Y_time;
+ wait(0.2);
+ }
+//
+// if(Mode6==0)
+if(Current_Mode==6)
+ {
+
+ G_time=12;
+ Y_time=5;
+ R_time=10;
+ Current_Mode=3;
+ printf("Current MOde 3 \r\n");
+// ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time);
+ Display_LCD(0,1,"Mode: 6");
+ Y_time=Y_time+G_time;
+ R_time=R_time+Y_time;
+ wait(0.2);
+ }
+
+
+ if(Start==0)
+ {
+ printf("Started \r\n");
+ StartButtonPressed=1;
+ StopButtonPressed=0;
+ ReStartButtonPressed=0;
+ printf("Started ************ %d \r\n",StartButtonPressed);
+ printf("Started ############## %d \r\n",StopButtonPressed);
+ printf("Started 88888888888888%d \r\n",ReStartButtonPressed);
+
+ timer.start();
+
+ }
+ if(Stop==0)
+ {
+ StartButtonPressed=0;
+ StopButtonPressed=1;
+ ReStartButtonPressed=0;
+
+ printf("Stopped \r\n");
+ wait(0.2);
+
+ }
+
+ if(Reset==0)
+ {
+ StartButtonPressed=0;
+ StopButtonPressed=0;
+ ReStartButtonPressed=1;
+ timer.stop();
+ printf("Reset \r\n");
+ wait(0.2);
+ }
+
+
+ if(StartButtonPressed==1 && StopButtonPressed==0 && ReStartButtonPressed==0 ) {
+ printf(" Read Time %f\r\n",timer.read()); //while
+ if(timer.read()<=G_time ) {
+
+ if(lcdflag==true)
+ {
+ Clear_LCD();
+ lcdflag=false;
+
+ }
+// timer.start();
+ printf(" Read Time %f\r\n",timer.read());
+ Display_LCD(0,0,"Green Light ");
+ GreenLight=0;
+ YellowLight=1;
+ RedLight=1;
+ wait(0.1);
+ } else if( timer.read()>G_time && timer.read()<=Y_time ) {
+ Display_LCD(0,0,"Yellow Light ");
+
+ GreenLight=1;
+ YellowLight=0;
+ RedLight=1;
+ wait(0.1);
+ printf(" Read Time %f\r\n",timer.read());
+ }
+
+ else if( timer.read()>Y_time && timer.read()<=R_time )
+ {
+ Display_LCD(0,0,"Red Light ");
+ GreenLight=1;
+ YellowLight=1;
+ RedLight=0;
+ timerred.start();
+ wait(0.1);
+
+ printf(" Read Time %f\r\n",timer.read());
+ }
+ //else if(timer.read()>R_time) {
+// Display_LCD(0,0,"Time Lmt Excded ");
+// GreenLight=1;
+// YellowLight=1;
+// RedLight=1;
+// wait(0.2);
+//
+//
+// }
+
+ }
+// timeElapsed=timer.read();
+// CalculateTimeElapsed(timeElapsed,buff);
+ if(StartButtonPressed==0 && StopButtonPressed==1 && ReStartButtonPressed==0 ) {
+ timeElapsed=timer.read();
+ timer.stop();
+
+ printf("Total Time = %f\r\n",timeElapsed);
+
+ CalculateTimeElapsed(timeElapsed,buff);
+
+ sprintf(Buffer,"Total Time %s",buff);
+
+ Display_LCD(0,0,Buffer);
+ memset(Buffer,'\0',17);
+ timeElapsed=timerred.read();
+ timerred.stop();
+ CalculateTimeElapsed(timeElapsed,buff);
+ memset(Buffer,'\0',17);
+ sprintf(Buffer,"Tim af Red %s",buff);
+ Display_LCD(0,1,Buffer);
+ memset(Buffer,'\0',17);
+
+ wait(0.1);
+
+ // /******************************************/
+// ReStartButtonPressed=1;
+// StartButtonPressed=0;
+// StopButtonPressed=0;
+// /******************************************/
+ }
+ if(StartButtonPressed==0 && StopButtonPressed==0 && ReStartButtonPressed==1 ) {
+
+
+ Display_LCD(0,0,"Done Resetting");
+ StartButtonPressed=0;
+ StopButtonPressed=0;
+ ReStartButtonPressed=0;
+ Clear_LCD();
+
+
+ }
+ if(StartButtonPressed==0 && StopButtonPressed==0 && ReStartButtonPressed==0 ) {
+ GreenLight=1;
+ YellowLight=1;
+ RedLight=1;
+ timer.reset();
+ timerred.reset();
+
+// printf(" Last Line\r\n");
+ Display_LCD(0,0,"Select Mode Or");
+ Display_LCD(0,1,"Press Start ");
+
+ lcdflag=true;
+ }
+
+ }
+}
+
+
+void ReadTimes()
+{
+ char rkey;
+ char Str[5]= {'\0'};
+ char Star[5]={'\0'};
+ char text[5]={'\0'};
+ char GreenTime[6]={'\0'};
+ char YellowTime[6]={'\0'};
+ char RedTime[6]={'\0'};
+ bool Staus=false;
+ rkey=keypad.waitForKey();
+
+ switch(rkey)
+ {
+
+ case '1':
+
+ {
+ Staus=ReadAllTimesofEachMode(1,GreenTime,YellowTime,RedTime);
+ if(Staus==true)
+ {
+
+ float GTIME=0,YTIME=0,RTIME=0;
+ ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME);
+ SaveTimes(1,GTIME,YTIME,RTIME);
+ }
+ Staus=false;
+ }
+ break;
+ case '2':
+ {
+ Staus=ReadAllTimesofEachMode(2,GreenTime,YellowTime,RedTime);
+ if(Staus==true)
+ {
+
+ float GTIME=0,YTIME=0,RTIME=0;
+ ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME);
+ SaveTimes(2,GTIME,YTIME,RTIME);
+ }
+ Staus=false;
+ }
+ break;
+ case '3':
+ {
+ Staus=ReadAllTimesofEachMode(3,GreenTime,YellowTime,RedTime);
+ if(Staus==true)
+ {
+
+ float GTIME=0,YTIME=0,RTIME=0;
+ ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME);
+ SaveTimes(3,GTIME,YTIME,RTIME);
+ }
+ Staus=false;
+ }
+
+ break;
+ case '4':
+ {
+ Staus=ReadAllTimesofEachMode(4,GreenTime,YellowTime,RedTime);
+ if(Staus==true)
+ {
+
+ float GTIME=0,YTIME=0,RTIME=0;
+ ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME);
+ SaveTimes(4,GTIME,YTIME,RTIME);
+ }
+ Staus=false;
+ }
+
+ break;
+ case '5':
+ {
+ Staus=ReadAllTimesofEachMode(5,GreenTime,YellowTime,RedTime);
+ if(Staus==true)
+ {
+
+ float GTIME=0,YTIME=0,RTIME=0;
+ ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME);
+ SaveTimes(5,GTIME,YTIME,RTIME);
+ }
+ Staus=false;
+ }
+
+ break;
+
+ case '6':
+ {
+ Staus=ReadAllTimesofEachMode(6,GreenTime,YellowTime,RedTime);
+ if(Staus==true)
+ {
+
+ float GTIME=0,YTIME=0,RTIME=0;
+ ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME);
+ SaveTimes(6,GTIME,YTIME,RTIME);
+ }
+ Staus=false;
+ }
+
+ break;
+ default:
+ {
+ printf("No Mode\r\n");
+ Clear_LCD();
+ Display_LCD(0,0," InValid Mode ");
+
+ }
+
+
+ }
+
+
+}
+
+bool ReadEachLightTime(int mode,char *mmss,char *lightTimeName)
+{
+ Clear_LCD();
+ char Buffer[17]= {'\0'};
+ char Buffer1[17]="Entr Time Mode:";
+ char Buffer2[17]="Tim MM:SS";
+
+ uint8_t index1=0;
+ char key='\0';
+ char str[6]= {'\0'};
+ Clear_LCD();
+ sprintf(Buffer,"%s%d",Buffer1,mode);
+ Display_LCD(0,0,Buffer);
+ memset(Buffer,'\0',16);
+ sprintf(Buffer,"%s %s",lightTimeName,Buffer2);
+ Display_LCD(0,1,Buffer);
+
+ wait(3);
+ Clear_LCD();
+ Display_LCD(0,0,"Press # Set ");
+ Display_LCD(0,1,"Prss * to Exit ");
+
+ key=keypad.waitForKey();
+ if(key=='#') {
+ Clear_LCD();
+ Display_LCD(0,0,"MM:SS ");
+
+ index1=0;
+ while(index1==0 ||(index1<=4 && key !='#' && key!='*')) {
+ key=keypad.waitForKey();
+ str[index1]=key;
+ if(index1==2) {
+ str[index1]=':';
+ index1++;
+ str[index1]=key;
+ }
+ index1++;
+ Display_LCD(0,0,"MM:SS ");
+ Display_LCD(0,1,"MM:SS ");
+ Display_LCD(0,1,str);
+ }
+ Clear_LCD();
+ Display_LCD(0,0,"Saving Mode ");
+ Display_LCD(0,1,str);
+ memcpy(mmss,str,5);
+ mmss[6]='\0';
+ wait(1);
+ Clear_LCD();
+
+ return true;
+ } else if(key=='*'){
+ Display_LCD(0,0,"Mode Not Set ");
+ Display_LCD(0,1,"Retains PrevMode");
+ return false;
+ }
+}
+
+
+bool ReadAllTimesofEachMode(int MODE,char *Greentime,char *Yellowtime,char *Redtime)
+{
+ bool Greenflag=false,Yellowflag=false,Redflag=false;
+ Greenflag=ReadEachLightTime(MODE,Greentime,"Green");
+
+ if(Greenflag==true) {
+
+ Yellowflag=ReadEachLightTime(MODE,Yellowtime,"Yellow");
+ if(Yellowflag==true) {
+
+ Redflag=ReadEachLightTime(MODE,Redtime,"Red");
+ if(Redflag==true) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+
+ } else
+ return false;
+}
+
+
+void ExtractTimesinSecs(char *greentime,char *yellowtime,char *redtime,float *grntim,float *yeltim,float *redtim)
+{
+ int mins,secs;
+ if( greentime[2]==':') {
+ mins=(( greentime[0]-0x30)*10)+(greentime[1]-0x30);
+ secs=((greentime[3]-0x30)*10)+(greentime[4]-0x30);
+ }
+ *grntim=mins*60+secs;
+ if( yellowtime[2]==':') {
+ mins=(( yellowtime[0]-0x30)*10)+(yellowtime[1]-0x30);
+ secs=((yellowtime[3]-0x30)*10)+(yellowtime[4]-0x30);
+ }
+ *yeltim=mins*60+secs;
+ if( redtime[2]==':') {
+ mins=(( redtime[0]-0x30)*10)+(redtime[1]-0x30);
+ secs=((redtime[3]-0x30)*10)+(redtime[4]-0x30);
+ }
+ *redtim=mins*60+secs;
+}
+
+void SaveTimes(int Mode,float GreenTime,float YellowTime,float RedTime)
+{
+ bool flag=false;
+ flag=WriteCorresspondingTimes(Mode, GreenTime,YellowTime,RedTime);
+ {
+ if(flag==true) {
+ Clear_LCD();
+ Display_LCD(0,0," Mode Save Success");
+ wait(1);
+ } else {
+ Clear_LCD();
+ Display_LCD(0,0," Mode Save Failure");
+ wait(1);
+ }
+ }
+}
+
+void CalculateTimeElapsed(float TimeElapsed, char *TimeStr)
+{
+ memset(TimeStr,'\0',sizeof TimeStr);
+ int mins=(int)TimeElapsed/60;
+ int secs=(int)TimeElapsed%60;
+ sprintf(TimeStr,"%2d:%02d",mins,secs);
+}
+
+
+ bool PasswordAcceptance()
+ {
+ Clear_LCD();
+ Display_LCD(0,0,"Enter Password ");
+ char PasswordStr[5]={'\0'};
+ char temp='\0';
+ temp=keypad.waitForKey();
+ PasswordStr[0]=temp;
+ Display_LCD(0,1,PasswordStr);
+ temp=keypad.waitForKey();
+ PasswordStr[1]=temp;
+ Display_LCD(0,1,PasswordStr);
+ temp=keypad.waitForKey();
+ PasswordStr[2]=temp;
+ Display_LCD(0,1,PasswordStr);
+ temp=keypad.waitForKey();
+ PasswordStr[3]=temp;
+ Display_LCD(0,1,PasswordStr);
+ printf("Password Str %s\r\n",PasswordStr);
+
+ if(PasswordStr[0]=='1' && PasswordStr[1] =='1' && PasswordStr[2]=='1' && PasswordStr[3]=='1')
+ {
+ Display_LCD(0,0,"Accepted ");
+ printf("Accepted\r\n");
+ return true;
+ }
+ return false;
+ }
+
+
+ int ModeSelectTochange()
+ {
+ Clear_LCD();
+ Display_LCD(0,0,"Select Mode 1-6 ");
+ char str[2]={'\0'};
+ char temp='\0';
+ temp=keypad.waitForKey();
+ if(temp>=0x31 && temp<=0x36)
+ {
+ Display_LCD(0,1,"Mode Is: ");
+ str[0]=temp;
+ Display_LCD(9,1,str);
+ wait(1);
+ return (temp-0x30);
+ }
+ Display_LCD(0,0,"Invalid Mode");
+ return -1;
+
+ }
+
+
+
+
+
+
+ void fn(char rkey)
+ {
+ char GreenTime[10]={'\0'},YellowTime[10]={'\0'},RedTime[10]={'\0'};
+ bool Staus=false;
+ switch(rkey)
+
+ {
+
+ case '1':
+
+ {
+ Staus=ReadAllTimesofEachMode(1,GreenTime,YellowTime,RedTime);
+ if(Staus==true)
+ {
+
+ float GTIME=0,YTIME=0,RTIME=0;
+ ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME);
+// SaveTimes(1,GTIME,YTIME,RTIME);
+ Display_LCD(0,0,"Done Saving ");
+ Display_LCD(0,1,"Mode Saved");
+ wait(1);
+ Clear_LCD();
+ }
+ Staus=false;
+ }
+ break;
+ case '2':
+ {
+ Staus=ReadAllTimesofEachMode(2,GreenTime,YellowTime,RedTime);
+ if(Staus==true)
+ {
+
+ float GTIME=0,YTIME=0,RTIME=0;
+ ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME);
+// SaveTimes(2,GTIME,YTIME,RTIME);
+ Display_LCD(0,0,"Done Saving ");
+ Display_LCD(0,1,"Mode Saved");
+ wait(1);
+ Clear_LCD();
+ }
+ Staus=false;
+ }
+ break;
+ case '3':
+ {
+ Staus=ReadAllTimesofEachMode(3,GreenTime,YellowTime,RedTime);
+ if(Staus==true)
+ {
+
+ float GTIME=0,YTIME=0,RTIME=0;
+ ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME);
+// SaveTimes(3,GTIME,YTIME,RTIME);
+ Display_LCD(0,0,"Done Saving ");
+ Display_LCD(0,1,"Mode Saved");
+ wait(1);
+ Clear_LCD();
+ }
+ Staus=false;
+ }
+
+ break;
+ case '4':
+ {
+ Staus=ReadAllTimesofEachMode(4,GreenTime,YellowTime,RedTime);
+ if(Staus==true)
+ {
+
+ float GTIME=0,YTIME=0,RTIME=0;
+ ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME);
+// SaveTimes(4,GTIME,YTIME,RTIME);
+ Display_LCD(0,0,"Done Saving ");
+ Display_LCD(0,1,"Mode Saved");
+ wait(1);
+ Clear_LCD();
+ }
+ Staus=false;
+ }
+
+ break;
+ case '5':
+ {
+ Staus=ReadAllTimesofEachMode(5,GreenTime,YellowTime,RedTime);
+ if(Staus==true)
+ {
+
+ float GTIME=0,YTIME=0,RTIME=0;
+ ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME);
+// SaveTimes(5,GTIME,YTIME,RTIME);
+ Display_LCD(0,0,"Done Saving ");
+ Display_LCD(0,1,"Mode Saved");
+ wait(1);
+ Clear_LCD();
+ }
+ Staus=false;
+ }
+
+ break;
+
+ case '6':
+ {
+ Staus=ReadAllTimesofEachMode(6,GreenTime,YellowTime,RedTime);
+ if(Staus==true)
+ {
+
+ float GTIME=0,YTIME=0,RTIME=0;
+ ExtractTimesinSecs(GreenTime,YellowTime,RedTime,>IME,&YTIME,&RTIME);
+// SaveTimes(6,GTIME,YTIME,RTIME);
+ Display_LCD(0,0,"Done Saving ");
+ Display_LCD(0,1,"Mode Saved");
+ wait(1);
+ Clear_LCD();
+ }
+ Staus=false;
+ }
+
+ break;
+ default:
+ Display_LCD(0,0,"No Mode saved");
+ Display_LCD(0,1,"Retns Prev Mode");
+ wait(1);
+ Clear_LCD();
+ printf("No Mode\r\n");
+
+ }
+
+ }
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Tue Oct 23 08:12:53 2018 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#2885c1b41e63158cb6faf5f107cd821ae06ef26c