Pierre Bourdin 11 years ago
parent
commit
37ad4c7692
1 changed files with 55 additions and 15 deletions
  1. 55 15
      Minitel_SM.ino

+ 55 - 15
Minitel_SM.ino

@@ -1,9 +1,10 @@
 #include <SoftwareSerial.h>
 #include <Minitel.h>
 
-Minitel m(53,52);			//Dfinition pour le Serial du Minitel
+Minitel m(52,53);			//Definition pour le Serial du Minitel
 
 void saisieNum(char *num);
+void saisiePin(char *pin);
 void saisieTxt(char *txt);
 void send_AT_cmd(const char *at_cmd, char *at_rep);
 void send_sms();
@@ -11,17 +12,18 @@ void enter_pin();
 
 // CAYE PAS BIEN ET JMEN FOUT !
 char rep[50];
+char Operator[50];
+//char Signal[];
 
 
 void setup()
 {
-	/****Init Shield GPRS Hardware mode*****/
+	/****Init Shield GPRS Hardware0617827300 mode*****/
 	Serial.begin(19200);
 	Serial1.begin(19200);
 	/****Simulation ON/OFF*****/
 //	pinMode(8, OUTPUT);
 //	digitalWrite(8, HIGH);
-	char rep[30];
 	char mess_ok[50];
 	m.clearScreen();
 	m.textMode();
@@ -33,13 +35,11 @@ void setup()
 	send_AT_cmd("AT+CPIN?\r", rep);
 	Serial.println(rep);
 	if (strstr(rep, "READY") == NULL) {
-		m.blink();
 		m.text("[ ] Check for pin lock... ", 2, 3);
 		m.text("Enter PIN code : ", 2, 4);
 		enter_pin();
 
 	}
-	m.noBlink();
 	m.text("[*] PIN code is good ! ", 2, 3);
 
 	m.text("[ ]", 2, 5); 
@@ -48,17 +48,19 @@ void setup()
 	
 	send_AT_cmd("AT+COPS?\r", rep);
 	Serial.print(rep);
-	char *token;
-	token = strtok(rep, " ");
-	while (token == NULL) {
-		delay(100);
-	}
+	char *token, *endtoken;
+	token = strchr(rep, '\"');
+	token++;
+	endtoken = strchr(token, '\"');
+	*endtoken = '\0';
 	sprintf(mess_ok, "You are connected to %s", token);
-	
-	
+//	strcpy(mess_ok, "You are connected to ");
+//	strcat(mess_ok, token);
+	sprintf(Operator, "Operator : %s", token);
 	m.noBlink();
 	m.text("[*]", 2, 5);
 	m.text(mess_ok, 5, 5);
+	delay(2000);
 	send_AT_cmd("AT+CGREG?\r\r", rep);
 	Serial.print(rep);
 	
@@ -75,10 +77,13 @@ void loop()
 	m.textColor(WHITE);
 	m.bgColor(RED);
 	m.text("         Smartphone Minitel V1         ", 1, 1);
-	m.text("  Operator : XXXXXX", 1, 23);
+	m.text(Operator, 1, 23);
 	m.bgColor(BLACK);
 	m.text("1 - Send SMS", 4, 5 );
 	m.text("2 - Read SMS", 4, 6 );
+	m.text("5 - Adress Book", 4, 8 );
+	
+
 	
 	while(1) {
 		if(m.available()>0) {
@@ -105,12 +110,13 @@ void enter_pin()
 {
 	char pin[5];
 	char at_pin[12];
-	saisieNum(pin);
+	saisiePin(pin);
 	sprintf(at_pin, "AT+CPIN=%s\r", pin);
 	Serial.print(pin);
 	send_AT_cmd(at_pin, rep);
+	send_AT_cmd(at_pin, rep);
 	Serial.print(rep);
-	return;
+	return setup();
 	
 }
 
@@ -190,6 +196,7 @@ void saisieNum(char *num) {
 }
 
 
+
 void saisieTxt(char *txt) {
 	int strCount = 0;
 	m.text("Message : ", 1, 6);
@@ -222,6 +229,39 @@ void saisieTxt(char *txt) {
 	}	
 }
 
+
+
+void saisiePin(char *pin) {
+	int strCount = 0;
+	
+	while(1) {
+		if(m.available()>0) {
+			char key = NULL;
+			// Obligation de lire 2 buffer en cas de touche Menu
+			key = m.getKey();
+			if(key != NULL) {
+				if (m.isMenuKey() == true) { 
+					key = m.getKey();
+					if (key == '8') {
+						/**** AJOUTER LE CHAR FIN DE COM MANDE AT PUIS PASSER SAISIE MESSAGES ****/
+						pin[strCount]='\0';
+						return;
+					}
+				}
+				else {
+					m.textChar('*');		//print sur minitel
+//					Serial.print(key);		//print sur le prompt
+					pin[strCount] = key;
+					strCount++;
+					strCount%=19;
+
+				}
+			}
+		}
+	}
+}
+
+
 void send_AT_cmd(const char *at_cmd, char *at_rep)
 {
 	Serial1.print(at_cmd);