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