-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainWindow.cs
131 lines (104 loc) · 3.43 KB
/
MainWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System;
using System.Diagnostics;
using Gtk;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
namespace goprogtk{
public partial class MainWindow: Gtk.Window
{
string lastfilename="nope";
bool recording = false;
System.Timers.Timer keepalive = new System.Timers.Timer(2500);
public MainWindow () : base (Gtk.WindowType.Toplevel)
{
Build ();
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
protected void recordClick (object sender, EventArgs e)
{
TaskFactory t = new TaskFactory ();
t.StartNew (() => {
label1.Text = "Förbereder Kameran...";
progressbar1.Fraction = 0;
GoPro.ExecuteURL("gpControl/command/mode?p=1");
label1.Text = "Tar bild...";
System.Threading.Thread.Sleep (100);
progressbar1.Fraction = 0.1;
GoPro.ExecuteURL("gpControl/command/shutter?p=1");
System.Threading.Thread.Sleep (300);
progressbar1.Fraction = 0.3;
System.Threading.Thread.Sleep (300);
progressbar1.Fraction = 0.6;
label1.Text = "Sparar bilden...";
System.Threading.Thread.Sleep (400);
progressbar1.Fraction = 0.8;
WebRequest req = HttpWebRequest.Create ("http://10.5.5.9:8080/gp/gpMediaList");
req.Method = "GET";
WebResponse filelist = req.GetResponse ();
System.IO.StreamReader sr = new System.IO.StreamReader (filelist.GetResponseStream ());
string fileliststring = sr.ReadToEnd ();
int lastimage = fileliststring.LastIndexOf ('J');
lastfilename = fileliststring.Substring (lastimage - 9, 12);
req.GetResponse ().Close ();
progressbar1.Fraction = 0.9;
label1.Text = "Laddar hem bilden...";
WebClient client = new WebClient ();
client.DownloadFile ("http://10.5.5.9:8080/videos/DCIM/100GOPRO/" + lastfilename, "lastimg.jpg");
int wwidth; int wheight;
this.GetSize (out wwidth,out wheight);
Gdk.Pixbuf pixbuff = new Gdk.Pixbuf ("lastimg.jpg",wwidth,wwidth*3/4);
image1.Pixbuf = pixbuff;
progressbar1.Fraction = 1;
label1.Text = lastfilename.ToString ();
});
}
protected void filethere(){
}
protected void stopstream(object sender, EventArgs e){
keepalive.Stop();
GoPro.ExecuteURL ("gpControl/execute?p1=gpStream&c1=stop");
}
protected void streamclick (object sender, EventArgs e)
{
label1.Text =("Sätter upp lajvström..");
GoPro.ExecuteURL ("gpControl/execute?p1=gpStream&c1=restart");
keepalive.Elapsed += Keepalive_Elapsed;
Process p = new Process ();
p.StartInfo.FileName = "ffplay";
p.StartInfo.Arguments= "-window_title \"Lajvström från Kamera!\" -fflags nobuffer udp://:8554";
p.Start ();
p.EnableRaisingEvents = true;
p.Exited+= stopstream;
keepalive.Start();
}
protected void stopthing(object sender, EventArgs e){
label1.Text = "Success!";
}
void Keepalive_Elapsed (object sender, System.Timers.ElapsedEventArgs e)
{
UdpClient udpClient = new UdpClient("10.5.5.9", 8554);
Byte[] sendBytes = System.Text.Encoding.ASCII.GetBytes("_GPHD_:0:0:2:0.000000\n");
udpClient.Send(sendBytes, sendBytes.Length);
}
protected void OnButton8Clicked (object sender, EventArgs e)
{
if (System.IO.File.Exists ("lastimg.jpg")) {
System.IO.File.Copy ("lastimg.jpg", lastfilename);
}
}
protected void OnButton1Clicked (object sender, EventArgs e)
{
Window settings = new goprogtk.SettingsWindow ();
settings.Show ();
}
protected void OnButton2Clicked (object sender, EventArgs e)
{
var state = GoPro.getState ();
}
}
}