History

Answering calls seems to work properly

Joel Armstrong committed 15 years ago

Commit 3dfdab61 parent 0fde8801 file · +34 −8Browse files

Unified · Split

appl/wm/dialer.b+34−8
@@ -41,7 +41,7 @@ audio_route := EARPIECE; · 40 unmodified lines
4141 task_cfg := array[] of {
4242 "frame .fl -width 40w -height 40w",
4343 "frame .b",
44− "label .l -text {Enter number to dial}",
44+ "label .number -text {Enter number to dial}",
4545 "button .b.back -text {<-} -command {send cmd back}",
4646 "frame .row1 -height 100",
4747 "button .b.1 -height 50 -text 1 -command {send cmd 1}",
@@ -66,10 +66,12 @@ task_cfg := array[] of { · 18 unmodified lines
6666 "button .b.dial -height 50 -text Dial -command {send cmd dial}",
6767 "button .b.hangup -height 50 -text {Hang up} -command {send cmd hangup}",
6868 "button .b.switchroute -height 50 -text {Speaker} -command {send cmd switch_route}",
69− "pack .l .b.back",
69+ "label .status -text {Status}",
70+ "pack .number .b.back",
7071 "pack .row1 .row2 .row3 .row4 -fill both -in .b",
7172 "pack .b.dial .b.hangup .b.switchroute -fill both -in .b",
7273 "pack .b -fill both",
74+ "pack .status -fill x",
7375 "pack .fl -fill both -expand 1",
7476 "pack propagate . 0",
7577 "update",
@@ -104,10 +106,10 @@ init(ctxt: ref Draw->Context, argv: list of string) · 28 unmodified lines
104106 tkclient->startinput(t, "kbd"::"ptr"::nil);
105107
106108 phonech := chan of string;
107− calllistch := chan of string;
108− spawn monitor(phonech);
109+ callsch := chan of string;
110+ spawn monitor_phone(phonech);
109111 spawn monitor_buttons();
110− spawn monitor_calls(calllistch);
112+ spawn monitor_calls(callsch);
111113
112114 if(len argv > 1) {
113115 # we were given a number as an argument, start dialing
@@ -172,6 +174,9 @@ init(ctxt: ref Draw->Context, argv: list of string) · 58 unmodified lines
172174 dial(labeltext);
173175 route(audio_route);
174176 get_call_list();
177+ "answer" =>
178+ answer();
179+ route(audio_route);
175180 "hangup" =>
176181 hangup_current();
177182 "switch_route" =>
@@ -185,7 +190,7 @@ init(ctxt: ref Draw->Context, argv: list of string) · 7 unmodified lines
185190 tk->cmd(t, ".b.switchroute configure -text Speaker");
186191 }
187192 }
188− tk->cmd(t, ".l configure -text {" + labeltext + "}");
193+ tk->cmd(t, ".number configure -text {" + labeltext + "}");
189194 tk->cmd(t, "update");
190195 phonemsg := <- phonech =>
191196 case phonemsg {
@@ -193,7 +198,15 @@ init(ctxt: ref Draw->Context, argv: list of string) · 1 unmodified line
193198 phone_state = RINGING;
194199 sys->print("ring!");
195200 }
196− tk->cmd(t, ".l configure -text {" + phonemsg +"}");
201+ tk->cmd(t, ".number configure -text {" + phonemsg +"}");
202+ tk->cmd(t, "update");
203+ nil = <- callsch =>
204+ tk->cmd(t, ".status configure -text {" + call.state + " (" + call.number + ")}");
205+ if(call.state == "incoming") {
206+ tk->cmd(t, ".b.dial configure -text Answer -command {send cmd answer}");
207+ } else {
208+ tk->cmd(t, ".b.dial configure -text Dial -command {send cmd dial}");
209+ }
197210 tk->cmd(t, "update");
198211 }
199212 }
@@ -257,6 +270,17 @@ dial(number : string) · 57 unmodified lines
257270 phone_state = ACTIVE;
258271 }
259272
273+answer()
274+{
275+ fd := sys->open("/phone/phone", sys->OWRITE);
276+ if(fd == nil) {
277+ sys->fprint(sys->fildes(2), "could not open phone: %r\n");
278+ return;
279+ }
280+ sys->fprint(fd, "answer");
281+ phone_state = ACTIVE;
282+}
283+
260284 # Read /dev/buttons to look for volume up/volume down events.
261285 monitor_buttons()
262286 {
@@ -286,7 +310,7 @@ monitor_buttons() · 23 unmodified lines
286310 }
287311
288312 # Open phone device to look for incoming events, e.g. the phone ringing.
289−monitor(phonech : chan of string)
313+monitor_phone(phonech : chan of string)
290314 {
291315 fd := sys->open("/phone/phone", sys->OREAD);
292316 if(fd == nil) {
@@ -314,6 +338,7 @@ monitor_calls(ch : chan of string) · 21 unmodified lines
314338 }
315339 n := sys->read(fd, buf, len buf);
316340 if(n == 0) {
341+ # we read 0 bytes, meaning no calls
317342 phone_state = IDLE;
318343 call.state = "inactive";
319344 call.number = "";
@@ -339,6 +364,7 @@ monitor_calls(ch : chan of string) · 19 unmodified lines
339364 call.number = number;
340365 }
341366 sys->print("state %s number %s\n", call.state, call.number);
367+ ch <-= "update";
342368 sys->sleep(1000);
343369 }
344370 }