![]() |
Forum Index : Microcontroller and PC projects : Serial log viewer for F4 and other micromites
Author | Message | ||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3309 |
Here is a doodle--the F4 takes serial output from a CMM2 @19200 (or other micromite, or PC or other serial outputter) and displays it on the LCD. In this case, it is an IPS 800x480 LCD. You can scroll back and forth on the display: <Home> starts the display at the first line; <End> ends it at the last line; <PgDn> moves down a screen's worth of lines; <PgUp> moves up; <UpArrow> moves up a line; <DownArrow> moves down. The default is to use font 2, which provides 24 lines by 66 characters on the IPS display; <LeftArrow> switches to Font 1, 36 lines by 100 characters; <RightArrow> switches back to Font 2. It does, sort of, what TeraTerm can do, but without necessarily having a PC attached. It works with local keyboard as well. In this configuration, I am using not only the IPS LCD adaptor but also the F4 2x20 hat PCB with PS/2 keyboard connector. ![]() Wherever you have located the view, if a new line comes in, that and the preceding lines display. If a line is added when the previous last line is already displayed, I first blitted from the second line through the last to the first line and then added the new line, but it appears to be faster to clear and TEXT write all the lines. I'm sure it is possible to overrun this--perhaps not even hard. ' F4Term.bas open "com1:19200,10000" as #1 dim integer i,j,k,l,m,n,x,y nlines=1, maxLn=300, maxShow, cursorPos dim string a$,b$,c$,s$,ln$, lines$(maxLn) length 100 dim integer maxLineLen=100, line1=1, showEnd=1, iStart=1 font 2 ' 24 lines by 66 characters ' FONT 1 ' 36 lines by 100 char maxShow=fix(mm.vres/mm.fontheight) do if loc(#1)>0 then a$=getCh$() else a$=_inkey$() if a$>"~" then ' special characters only: End, Home, PgUp, PgDn else a$="" ' ignore all normal characters (<128) from keyboard endif endif if asc(a$)=27 then ' escape sequence doEsc elseif asc(a$)=13 then ' carriage return (endShow) if nlines<=maxShow then ' screen not yet filled else ' if showEnd=nlines then ' we are showing the last line ' blit 0,mm.fontheight,0,0,mm.hres,mm.vres-mm.fontheight ' y=mm.vres-mm.fontheight ' box 0,y,mm.hres,mm.fontheight,,rgb(black),rgb(black) ' endif y=0: iStart=max(1,nlines-maxShow+1): showLines: showEnd=nlines endif if showEnd=nlines then ' we are showing the last line, so add one s$=str$(nlines)+" "+lines$(nlines) text 0,y,s$ y=y+mm.fontheight iStart=max(1,nlines-maxShow+1) endif if nlines<=maxln then nlines=nlines+1: showEnd=nlines endif elseif asc(a$)=128 then ' Up Arrow iStart=max(1,iStart-1): showLines elseif asc(a$)=129 then ' Down Arrow iStart=min(nlines-maxShow+1,iStart+1): showLines elseif asc(a$)=130 then ' Left Arrow (Font 1 36 lines by 100 ch) font 1: maxShow=fix(mm.vres/mm.fontheight): iStart=1: showLines elseif asc(a$)=131 then ' Right Arrow (Font 2 24 lines by 66 ch) font 2: maxShow=fix(mm.vres/mm.fontheight): iStart=1: showLines elseif asc(a$)=11 or asc(a$)=137 then ' Page up iStart=min(iStart+maxShow,nlines-maxShow+1): showLines elseif asc(a$)=12 or asc(a$)=136 then ' Page down iStart=max(1,iStart-maxShow): showLines elseif asc(a$)=134 then: iStart=1: showLines: ' Home elseif asc(a$)=135 then ' End iStart=max(1,nlines-maxShow+1): showLines elseif a$>=" " and a$<="~" then ' printable if len(lines$(nlines))< maxLineLen then lines$(nlines)=lines$(nlines)+a$ endif endif loop sub doEsc ' handle: 2J-cls 1F,2F-font H-home #;A-up #;B--down a$=getCh$() if a$="[" then ' second char of escape sequence a$=getCh$() select case a$ case "H": goHome case "2" ' could be cls or font a$=getCh$() if a$="J" then cls: nlines=1: for i=1 to maxLn: lines$(i)="": next i: y=0 elseif a$="F" then font 2:maxShow=fix(mm.vres/mm.fontheight) endif case "1" ' font a$=getCh$() if a$="F" then: font 1: maxShow=fix(mm.vres/mm.fontheight): endif end select endif end sub sub showLines showEnd=min(nlines,iStart+maxShow) cls: y=0: for i=iStart to showEnd s$=str$(i)+" "+lines$(i) text 0,y,s$ y=y+mm.fontheight next i line1=1 end sub function getCh$() do: loop while loc(#1)=0 getCh$=input$(1, #1) end Function Function _inkey$() local ky$ ky$=inkey$ if asc(ky$)=27 then ' escape sequence ky$=inkey$: ky$=inkey$: ky$=ucase$(ky$) ' ?ky$; If ky$="A" Then: ky$=chr$(128) ' up arrow ElseIf ky$="B" Then: ky$=chr$(129) ' down arrow ElseIf ky$="C" Then: ky$=chr$(131) ' right arrow ElseIf ky$="D" Then: ky$=chr$(130) ' left arrow ElseIf ky$="1" Then: ky$=chr$(134) ' home ElseIf ky$="4" Then: ky$=chr$(135) ' end ElseIf ky$="5" Then: ky$=chr$(136) ' pgup ElseIf ky$="6" Then: ky$=chr$(137) ' pgdn ' Function keys are ??? EndIf endif _inkey$=ky$ end function There actually is voice over in this youtube video, but not until about a minute in. F4 on Fruit of the Shed ~ Edited 2021-05-14 10:11 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |