Unified · Split
| @@ -41,7 +41,7 @@ audio_route := EARPIECE; · 40 unmodified lines | ||
| 41 | 41 | task_cfg := array[] of { |
| 42 | 42 | "frame .fl -width 40w -height 40w", |
| 43 | 43 | "frame .b", |
| 44 | − "label .l -text {Enter number to dial}", | |
| 44 | + "label .number -text {Enter number to dial}", | |
| 45 | 45 | "button .b.back -text {<-} -command {send cmd back}", |
| 46 | 46 | "frame .row1 -height 100", |
| 47 | 47 | "button .b.1 -height 50 -text 1 -command {send cmd 1}", |
| @@ -66,10 +66,12 @@ task_cfg := array[] of { · 18 unmodified lines | ||
| 66 | 66 | "button .b.dial -height 50 -text Dial -command {send cmd dial}", |
| 67 | 67 | "button .b.hangup -height 50 -text {Hang up} -command {send cmd hangup}", |
| 68 | 68 | "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", | |
| 70 | 71 | "pack .row1 .row2 .row3 .row4 -fill both -in .b", |
| 71 | 72 | "pack .b.dial .b.hangup .b.switchroute -fill both -in .b", |
| 72 | 73 | "pack .b -fill both", |
| 74 | + "pack .status -fill x", | |
| 73 | 75 | "pack .fl -fill both -expand 1", |
| 74 | 76 | "pack propagate . 0", |
| 75 | 77 | "update", |
| @@ -104,10 +106,10 @@ init(ctxt: ref Draw->Context, argv: list of string) · 28 unmodified lines | ||
| 104 | 106 | tkclient->startinput(t, "kbd"::"ptr"::nil); |
| 105 | 107 | |
| 106 | 108 | phonech := chan of string; |
| 107 | − calllistch := chan of string; | |
| 108 | − spawn monitor(phonech); | |
| 109 | + callsch := chan of string; | |
| 110 | + spawn monitor_phone(phonech); | |
| 109 | 111 | spawn monitor_buttons(); |
| 110 | − spawn monitor_calls(calllistch); | |
| 112 | + spawn monitor_calls(callsch); | |
| 111 | 113 | |
| 112 | 114 | if(len argv > 1) { |
| 113 | 115 | # 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 | ||
| 172 | 174 | dial(labeltext); |
| 173 | 175 | route(audio_route); |
| 174 | 176 | get_call_list(); |
| 177 | + "answer" => | |
| 178 | + answer(); | |
| 179 | + route(audio_route); | |
| 175 | 180 | "hangup" => |
| 176 | 181 | hangup_current(); |
| 177 | 182 | "switch_route" => |
| @@ -185,7 +190,7 @@ init(ctxt: ref Draw->Context, argv: list of string) · 7 unmodified lines | ||
| 185 | 190 | tk->cmd(t, ".b.switchroute configure -text Speaker"); |
| 186 | 191 | } |
| 187 | 192 | } |
| 188 | − tk->cmd(t, ".l configure -text {" + labeltext + "}"); | |
| 193 | + tk->cmd(t, ".number configure -text {" + labeltext + "}"); | |
| 189 | 194 | tk->cmd(t, "update"); |
| 190 | 195 | phonemsg := <- phonech => |
| 191 | 196 | case phonemsg { |
| @@ -193,7 +198,15 @@ init(ctxt: ref Draw->Context, argv: list of string) · 1 unmodified line | ||
| 193 | 198 | phone_state = RINGING; |
| 194 | 199 | sys->print("ring!"); |
| 195 | 200 | } |
| 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 | + } | |
| 197 | 210 | tk->cmd(t, "update"); |
| 198 | 211 | } |
| 199 | 212 | } |
| @@ -257,6 +270,17 @@ dial(number : string) · 57 unmodified lines | ||
| 257 | 270 | phone_state = ACTIVE; |
| 258 | 271 | } |
| 259 | 272 | |
| 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 | + | |
| 260 | 284 | # Read /dev/buttons to look for volume up/volume down events. |
| 261 | 285 | monitor_buttons() |
| 262 | 286 | { |
| @@ -286,7 +310,7 @@ monitor_buttons() · 23 unmodified lines | ||
| 286 | 310 | } |
| 287 | 311 | |
| 288 | 312 | # 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) | |
| 290 | 314 | { |
| 291 | 315 | fd := sys->open("/phone/phone", sys->OREAD); |
| 292 | 316 | if(fd == nil) { |
| @@ -314,6 +338,7 @@ monitor_calls(ch : chan of string) · 21 unmodified lines | ||
| 314 | 338 | } |
| 315 | 339 | n := sys->read(fd, buf, len buf); |
| 316 | 340 | if(n == 0) { |
| 341 | + # we read 0 bytes, meaning no calls | |
| 317 | 342 | phone_state = IDLE; |
| 318 | 343 | call.state = "inactive"; |
| 319 | 344 | call.number = ""; |
| @@ -339,6 +364,7 @@ monitor_calls(ch : chan of string) · 19 unmodified lines | ||
| 339 | 364 | call.number = number; |
| 340 | 365 | } |
| 341 | 366 | sys->print("state %s number %s\n", call.state, call.number); |
| 367 | + ch <-= "update"; | |
| 342 | 368 | sys->sleep(1000); |
| 343 | 369 | } |
| 344 | 370 | } |