0010 REM PReader for Newton Copyright(c) 2000 Eric M. Schneck, Inc. 0020 LET appSpec={goto:'endProgram,title:"Pocket Reader"} 0030 window app,appSpec,"APP" 0040 show app 0050 widgetdef Layout_0:={lbDestination:{widgetType:"labelPicke r"B ,order:0,checkCurrentItem:TRUE,indent:80,viewBounds:{left:2B ,top:288,right:153,bottom:308},labelCommands:["Notepad","ClB ipboard"],text:"Destination",viewValue:0,gosub:'SetDestinatB ion},btnLoad:{widgetType:"textButton",order:1,gosub:'Load,vB iewBounds:{left:4,top:4,right:47,bottom:19},viewFlags:514,tB ext:"Load",viewFont:{family:'espy,face:1,size:12},viewFormaB t:67109456},btnStop:{widgetType:"textButton",order:2,gosub:B 'StopLoading,viewBounds:{left:53,top:4,right:84,bottom:19},B viewFlags:514,text:"Stop!",viewFont:{family:'espy,face:1,siB ze:9},viewFormat:67109456},btnSave:{widgetType:"textButton"B ,order:3,gosub:'SaveText,viewBounds:{left:274,top:3,right:3B 16,bottom:18},viewFlags:514,text:"Save",viewFont:{family:'eB spy,face:1,size:12},viewFormat:67109456},lbSeparator:{widgeB tType:"labelPicker",order:4,checkCurrentItem:TRUE,indent:75B ,viewBounds:{left:142,top:289,right:263,bottom:313},labelCoB mmands:["blank","tab","LF","none"],text:"Separator",viewValB ue:0,gosub:'setSeparator},btnClear:{widgetType:"textButton"B ,order:5,gosub:'ClearText,viewounds:{top:5,bottom:20,left:5B ,right:84},viewFlags:514,text:"Clear",viewFont:{family:'espB y,face:1,size:9},viewFormat:67109456,viewBounds:{left:238,tB op:3,right:268,bottom:18}},txtText:{widgetType:"text",orderB :6,viewClass:81,viewBounds:{top:27,bottom:282,left:3,right:B 317},viewFlags:47616,viewFormat:12625,viewJustify:0,viewLinB eSpacing:16,text:"",viewFont:12289,tabs:[20,40,60,80,120,140,160 ,180]}} 0060 window wlist,Layout_0 0070 show wlist 0075 getroot().alphakeyboard:open() 0080 gosub Initialize // 0100 wait -1 // indefinitely 0500 Initialize: REM 0520 let seps=[" ","\t","\n",""] 0540 gosub GetSettings // 0560 let bWorking=nil 0620 if bConnect then gosub Load 0640 return 0660 GetSettings: REM 0680 let f:={name:"PR",destination:0, separator:0, ConnectOnOpe n:nil, ClearOnLoad:nil,text:nil} 0700 open chan,"PRSettings",name 0720 if fstat=0 then get chan,f 0740 if fstat=0 then close chan 0760 let eDestination=f.destination 0780 let eSeparator=f.separator 0800 let bConnect=f.ConnectOnOpen 0820 let l=Layout_0.lbSeparator.labelCommands[eSeparator] 0840 u.layout_0.lbSeparator:UpdateText(l) 0860 let bClear=f.ClearOnLoad 0880 let l=Layout_0.lbDestination.labelCommands[eDestination] 0900 u.Layout_0.lbDestination:UpdateText(l) 0920 rem if bConnect=TRUE then u.Layout_0.cbConnect:ToggleCheck () 0940 rem if bClear=TRUE then u.Layout_0.cbClear:ToggleCheck() 0960 SetValue(Layout_0.txtText,'text,f.text) 0980 let f=nil // clear saved text 1000 return 1020 SaveSettings: REM 1040 let l=layout_0.txtText.text 1060 let f:={name:"PR",destination:eDestination, separator:eSep arator, ConnectOnOpen:bConnect, ClearOnLoad:bClear,Text:l} 1080 create chan,"PRSettings",name 1100 if fstat=1 then 1120 delete "PRSettings" 1140 create chan,"PRSettings",name 1160 end if 1180 if fstat=1 then return 1200 put chan,f 1220 close chan 1240 let f=nil 1260 let l=nil 1280 return 1300 SetDestination: REM 1320 let eDestination=Layout_0.lbDestination.viewValue 1340 return 1360 SetConnect: REM 1380 rem let bConnect=Layout_0.cbConnect.viewValue 1400 return 1420 SetClear: REM 1440 rem let bClear=Layout_0.cbClear.viewValue 1460 return 1480 setSeparator: REM 1500 let eSeparator=Layout_0.lbSeparator.viewValue 1520 return 1540 ClearText: REM 1560 SetValue(Layout_0.txtText,'text,clone("")) 1580 return 1600 Erase: REM 1620 gosub Connect // 1640 let ep.buffer="" 1660 u.ep:Output(7,nil) // cmd_erase_all_data 1670 u.ep:flushOutput() 1680 gosub ReadEndpoint // 1700 gosub Disconnect // 1720 return 1740 Connect: REM 1770 let ep.buffer="" 1780 gosub CreateEndpoint // 1820 u.ep:Output(0,nil) // cmd_establish_connection 1830 u.ep:flushOutput() 1840 gosub ReadEndpoint // 1880 return 1900 Disconnect: REM 1920 u.ep:Output(1,nil) // cmd_release_connection 1930 u.ep:flushOutput() 1960 gosub DeleteEndpoint // 1970 return 1980 SaveNotepad: REM 2000 let l=Layout_0.txtText.text 2020 LET notes:=getroot().paperroll 2040 u.notes:makeTextNote(l, true) 2060 let l=nil 2080 return 2082 SaveClipBoard: REM 2084 LET clipBoardDataFrame={} 2086 LET clipBoardDataFrame.label=substr(Layout_0.txtText.text, 0,10) 2088 LET clipBoardDataFrame.types=[['text]] 2090 LET clipBoardDataFrame.bounds={} 2092 LET clipBoardDataFrame.data=[[{text:u.Layout_0.txtText.tex t}]] 2094 setClipBoard(ensureInternal(clipBoardDataFrame)) 2096 return 2100 SaveOutbox: REM 2120 LET transportSym:=getGroupTransport('mail) 2140 LET NSBSym:=getroot().|basic:nsbasic| 2160 LET item=getroot().(transportSym):newItem(NSBSym) 2180 LET item.toRef=[{name: "info",email:"xxxx@yyyyyyy.com"}] 2200 LET item.title="Scanned Information" 2220 LET item.text=u.Layout_0.txtText.text 2240 send('mail, item) 2260 return 2280 SaveText: REM 2300 if eDestination=0 then GOSUB SaveNotepad 2320 if eDestination=1 then GOSUB SaveClipboard 2340 if eDestination=2 then GOSUB SaveOutbox 2360 return 2380 Load: REM 2400 if bWorking then return 2420 let bWorking = true 2440 gosub Connect // 2445 u.ep:disconnect() 2450 gosub createendpoint // 2460 gosub ReadFirstLine // 2470 for i=1 to 10000 2480 if bWorking=nil then exit for 2520 gosub ReadLine // 2540 next i 2560 let bWorking=nil 2580 gosub Disconnect // 2595 if bClear=TRUE then gosub Erase 2600 return 2620 StopLoading: REM 2660 let bWorking=nil 2700 return 2720 ReadFirstLine: REM 2780 let ep.buffer="" 2800 u.ep:Output(4,nil) // // cmd_send_data 2820 u.ep:flushOutput() 2830 LET u.ep:Output(0, nil) // data rate=300 2835 u.ep:flushOutput() 2840 u.ep:Output(0, nil) // text 2870 u.ep:flushOutput() 2900 gosub GetData // 2920 return 2940 ReadLine: REM 2980 let ep.buffer="" 3000 u.ep:Output(5, nil) // cmd_send_next_data_block 3010 u.ep:flushOutput() 3040 gosub GetData // 3060 return 3080 GetData: REM 3140 gosub ReadEndpoint // 3150 if bWorking=nil then return 3160 let opc=ord(A$[0]) 3200 if opc<>209 then 3220 let bWorking=nil 3240 return 3260 end if 3280 gosub ReadEndpoint // 3290 let l="" 3300 let len=ord(A$[0]) 3340 for i = 1 to len 3360 gosub ReadEndpoint // 3370 if bWorking=nil then exit for 3380 let l = l & A$ 3400 gosub ReadEndpoint // skip fmt char 3420 if bWorking=nil then exit for 3440 next i 3460 gosub ReadEndpoint // skip checksum 3470 let sep$=seps[eSeparator] 3480 SetValue(Layout_0.txtText,'text,Layout_0.txtText.text&l&se p$) 3500 let l=nil 3520 return 3620 CreateEndpoint: REM 3630 function ExceptionHandler(error) begin end 3640 function inputScript(ep, data) begin ep.buffer:=strconcat( ep.buffer,data); end 3660 let kCMSAsyncSerial := "aser" 3680 let kCMOSerialIOParms:="siop" 3700 let kCMOInputFlowControlParms:="iflc" 3720 let kCMOOutputFlowControlParms:="oflc" 3750 let protoEndpoint:=@174 3760 let opSetRequired=512 3761 let opSetNegotiate=256 3762 let k300bps:=300 3764 let k1StopBits:=0 3766 let k8DataBits:=8 3768 let kEvenParity:=2 3780 let connectService:={label:kCMSAsyncSerial,type:'service,o pCode:opSetRequired} 3800 let serialParms:={label:kCMOSerialIOParms,type:'option,opC ode:opSetNegotiate, data:{ stopBits:k1StopBits,parity:kEvenPari ty,dataBits:k8DataBits,bps:k300bps}} 3820 let inFlowParms:={label: kCMOInputFlowControlParms, type: 'option, opCode:opSetNegotiate ,data:{useSoftFlowControl: nil,us eHardFlowControl: nil}} 3840 let outFlowParms:={label: kCMOOutputFlowControlParms,type: 'option, opCode: opSetNegotiate, data:{useSoftFlowControl: nil, useHardFlowControl: nil}} 3870 let initConfig=[connectService, serialParms, inFlowParms, outFlowParms] 3880 let ep:={ ExceptionHandler:u.ExceptionHandler,configOption s:initConfig,buffer:clone("")} 3890 let ep._proto=protoEndpoint 3920 u.ep:Instantiate(ep,nil) // initConfig) 3960 u.ep:Connect(nil,nil) 3980 let inputSpec:={inputForm:'string,byteCount:1,InputScript: u.inputScript} 4000 u.ep:SetInputSpec(inputSpec) 4020 return 4040 DeleteEndpoint: REM 4060 if ep<>nil then u.ep:Dispose() 4080 return 4100 ReadEndpoint: REM 4140 ShowBusyBox(true) 4160 if strlen(ep.buffer)=0 then wait 250 4170 if strlen(ep.buffer)=0 AND bWorking=TRUE then 4175 LET w2Spec={ViewBounds:SETBOUNDS(30,70,300,120)} 4180 window w2, w2Spec 4182 WPRINT w2,"\n No response from Pocket Reader.\n Please m ake sure it is connected and turned on" 4185 show w2 4187 wait 5000 4189 hide w2 4190 LET bWorking = nil 4200 end if 4260 if bWorking=TRUE then 4280 let A$=substr(ep.buffer,0,1) 4300 let ep.buffer:=substr(ep.buffer,1,nil) 4320 end if 4340 ShowBusyBox(nil) 4360 return 9000 endProgram: rem 9010 gosub DeleteEndpoint // 9020 gosub SaveSettings // 9030 hide 9040 bye