Ejemplo n.º 1
0
		public static void Main (string[] args)
		{
			ManualResetEvent terminateProgram = new ManualResetEvent (false);
			string fbToken = "CAACpSl1Qm3cBAHAMyZAY...";//This is not valied
			var fb = new FacebookClient(fbToken);
			Font f = Font.MediumFont;
			Point offset = new Point(0,25);
			Point p = new Point(10, Lcd.Height-75);
			Point boxSize = new Point(100, 24);
			Rectangle box = new Rectangle(p, p+boxSize);
			var colorSensor = new EV3ColorSensor (SensorPort.In1);
			ButtonEvents buts = new ButtonEvents ();
			LcdConsole.WriteLine("Use color on port1");
			LcdConsole.WriteLine("Enter post value");
			LcdConsole.WriteLine("Esc. terminate");
			buts.EscapePressed += () => { 
				terminateProgram.Set();
			};
			
			buts.EnterPressed += () => { 
				Color color = colorSensor.ReadColor();
				Lcd.Clear();
				Lcd.WriteTextBox(f, box + offset*0, "Color: " + color, true);
				Lcd.WriteTextBox(f, box + offset*1, "Send to Facebook" + color, true);
				Lcd.Update();
				colorSensor.ReadColor();
				var me = fb.Get("monobrick.dk") as JsonObject;
				var uid = me["id"];
		    	string url = string.Format("{0}/{1}", uid, "feed");
		    	var argList = new Dictionary<string, object>();
		    	argList["message"] = "A program running MonoBrick Firmware was aked to read the color sensor. Color read: " + colorSensor.ReadColor().ToString();
		    	fb.Post(url, argList);
			};
			terminateProgram.WaitOne (); 
		    		
		}
Ejemplo n.º 2
0
		public static void Main (string[] args)
		{
			const string to = "*****@*****.**";
			const string from = "*****@*****.**";
			const string password = "******";
			
			ManualResetEvent terminateProgram = new ManualResetEvent(false);
			var colorSensor = new EV3ColorSensor(SensorPort.In1);
			ButtonEvents buts = new ButtonEvents ();
			SmtpClient smptpClient = new SmtpClient("smtp.gmail.com", 587);
			smptpClient.EnableSsl = true;
			smptpClient.UseDefaultCredentials = false;
			smptpClient.Credentials = new NetworkCredential(from, password);
			smptpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
			ServicePointManager.ServerCertificateValidationCallback = 
                delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 
                    { return true; };
			MailMessage message = new MailMessage();
			message.To.Add(to);
			message.From = new MailAddress(from);
			message.Subject = "Color mail from my EV3";
			LcdConsole.Clear();
			LcdConsole.WriteLine("Use color on port1");
			LcdConsole.WriteLine("Enter send mail");
			LcdConsole.WriteLine("Esc. terminate");
			buts.EscapePressed += () => { 
				terminateProgram.Set();
			};
			buts.EnterPressed += () => { 
				LcdConsole.WriteLine("Sending email");
				try{
					message.Body = "EV3 read color: " + colorSensor.ReadColor();
					smptpClient.Send(message);
					LcdConsole.WriteLine("Done sending email");
				}
				catch(Exception e)
				{
					LcdConsole.WriteLine("Failed to send email");
					Console.WriteLine(e.StackTrace);
				}
			};
			terminateProgram.WaitOne();
			message = null;
		}