Re: [Lazarus] Example of full screen console program anywhere?
How about using the Crt unit? It implements a Turbo Pascal-compatible API under all supported targets and should work fine with terminals. Example: http://pastebin.com/gzhsrv6x On Thu, Apr 28, 2016 at 9:27 PM, Bo Berglundwrote: > On Thu, 28 Apr 2016 15:23:01 +0200, Bo Berglund > wrote: > > I went ahead and created a new Console Application in Lazarus where I > use the same object for controlling the GPIO pins as I did in the GUI > program. > > The Console program just initializes the control object then enters > into a repeat loop reading a key from the user and then interpreting > the key in a case construct for valid commands. > It exits if the q key is pressed. > > When I run this in Lazarus all operates according to plan but as soon > as I try to run it outside of the GUI, for example in a terminal in > Raspbian or in a PuTTY terminal connected by SSH to the RPi literally > nothing works of the stuff that should happen in the repeat loop! > > What I get is the greeting message and then when I press the keys that > should produce the action nothing at all happens including pressing q, > which is the exit code out of the loop and should terminate the > program. > > For some reason it was possible to close it using Ctrl-C, though. > > In Lazarus I use the debug window "Terminal Output" and here > everything planned works fine! > > What a mystery! This is the first time I have encountered such a > difference! > > After some further debugging I found that the keypresses are not even > handled in the repeat loop. It uses this type of construct: > > //Display main screen > Writeln('Controls are:'); > Writeln('p = Toggle 12V SS Power ON/OFF'); > Writeln('w = Toggle WiFi Power feed ON/OFF'); > Writeln('l = Toggle Alarm Lamp ON/OFF'); > Writeln('s = Start SS by sending a 1s pulse'); > Writeln('q = Quit the program and reset the control lines'); > Writeln('Press any key!'); > > //Check input and act on commands > repeat > Read(cKey); > case cKey of > 'p': //SS Power toggle command > ... > until cKey = 'q'; > end; > > I added debug printing to the case sections to see what was sent in > and the answer was NOTHING! > It seems like Read() does not return anything for a simple key press > unlike what happens in the Lazarus debug window. So the program > probably just hangs on the Read(cKey) command, but in Lazarus it does > not so it is impossible to debug... > > Then I tested to use the Enter key and surprise! Now the relays > operate... > > But this should happen exactly when the key is pressed not when Enter > is also pressed later. I use Read() instead of Readln() just in order > to get one single key to process... > > What could be done to fix this? > > > > >-- > >Bo Berglund > >Developer in Sweden > > > -- > Bo Berglund > Developer in Sweden > > > -- > ___ > Lazarus mailing list > Lazarus@lists.lazarus.freepascal.org > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus > -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Example of full screen console program anywhere?
On Thu, 28 Apr 2016 15:23:01 +0200, Bo Berglundwrote: I went ahead and created a new Console Application in Lazarus where I use the same object for controlling the GPIO pins as I did in the GUI program. The Console program just initializes the control object then enters into a repeat loop reading a key from the user and then interpreting the key in a case construct for valid commands. It exits if the q key is pressed. When I run this in Lazarus all operates according to plan but as soon as I try to run it outside of the GUI, for example in a terminal in Raspbian or in a PuTTY terminal connected by SSH to the RPi literally nothing works of the stuff that should happen in the repeat loop! What I get is the greeting message and then when I press the keys that should produce the action nothing at all happens including pressing q, which is the exit code out of the loop and should terminate the program. For some reason it was possible to close it using Ctrl-C, though. In Lazarus I use the debug window "Terminal Output" and here everything planned works fine! What a mystery! This is the first time I have encountered such a difference! After some further debugging I found that the keypresses are not even handled in the repeat loop. It uses this type of construct: //Display main screen Writeln('Controls are:'); Writeln('p = Toggle 12V SS Power ON/OFF'); Writeln('w = Toggle WiFi Power feed ON/OFF'); Writeln('l = Toggle Alarm Lamp ON/OFF'); Writeln('s = Start SS by sending a 1s pulse'); Writeln('q = Quit the program and reset the control lines'); Writeln('Press any key!'); //Check input and act on commands repeat Read(cKey); case cKey of 'p': //SS Power toggle command ... until cKey = 'q'; end; I added debug printing to the case sections to see what was sent in and the answer was NOTHING! It seems like Read() does not return anything for a simple key press unlike what happens in the Lazarus debug window. So the program probably just hangs on the Read(cKey) command, but in Lazarus it does not so it is impossible to debug... Then I tested to use the Enter key and surprise! Now the relays operate... But this should happen exactly when the key is pressed not when Enter is also pressed later. I use Read() instead of Readln() just in order to get one single key to process... What could be done to fix this? > >-- >Bo Berglund >Developer in Sweden -- Bo Berglund Developer in Sweden -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Example of full screen console program anywhere?
On Mon, Apr 25, 2016 at 04:59:25PM +0200, Bo Berglund wrote: > writing is positioned on the screen in order to put output data in > certain places and commands can be entered without moving the > displayed screen. Besides the already mentioned textmode IDE, there is also fpctris, samegame and lister in the FPC examples. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Example of full screen console program anywhere?
On 04/28/2016 08:23 AM, Bo Berglund wrote: So I want to make a console type program instead which continuously displays the state of the GPIO outputs (like I have GUI shapes which change color) and then reacts to key presses where single letters mean different things causing an action on the outputs. I *want* to do the same thing to remote control a RPi to control power on devices! I'm thinking of using a FPC Free Vision app, controlled by encrypted UDP packets (completely stealth), with the RPi code eventually written with www.ultibo.org -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Example of full screen console program anywhere?
On 2016-04-28 14:23, Bo Berglund wrote: > What I do not want is a program that scrolls up on the screen as keys > are entered etc. I want the screen to stay put and only the status > fields change when I do the commands. Free Vision can do just that for you. Obviously you can search the Internet for DOS type menu interfaces [loads of such examples are still around], but that would require low level console codes and interpretation. Free Vision does it already for you - and the end-result should look much prettier. I suggest you grab a copy of a Turbo Pascal manual (they are freely available on the Internet now - Borland released them) or search for some Turbo Vision example programs/code. Or even look at the FPC Text IDE as a working example (but that's a rather complex example to study). I did a quick search, here is a simple Turbo Vision tutorial. It will apply exactly as is to Free Vision as well. http://www.baskent.edu.tr/~tkaracay/etudio/ders/prg/pascal/PasHTM3/pas/pasl3007.html Regards, Graeme -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Example of full screen console program anywhere?
On Mon, 25 Apr 2016 16:59:25 +0200, Bo Berglundwrote: >I need to create a console program, but one that works similar to the >nano editor, the gpsd position/satellite view or raspi-config on a >Raspberry Pi. >I.e. the program manages the full terminal screen and displays its >data in certain areas on screen and reads keystrokes as commands for >controlling the program. >I once did such programs on Windows using BASIC, but that was before >Windows appeared and I have all but forgotten how it was actually >accomplished >So I am looking for some examples to start off where the cursor for >writing is positioned on the screen in order to put output data in >certain places and commands can be entered without moving the >displayed screen. > >Is there such an example for FPC/Lazarus available somewhere? >Target is Raspbian on a Raspberry Pi3 and I cannot use any GUI system >for this because it must be accessed remotely via SSH (PuTTY) over a >slow link that does not work decently with the graphical interface. > Just to clarify: I want to be able to run an FPC program in the console of an SSH terminal like PuTTY connected to the remote system (a Raspberry Pi3 sitting across the world from me). This program should have 4-5 commands via key entries where it activates certain combinations of GPIO output pins to control relays, which in turn power on certain devices connected to the RPi controller. I have a GUI program created with Lazarus 1.6 and FPC 3.0.0 where I have located almost all of the actual processing in separate classes. I *can* run the GUI program on the remote Pi via VPN and then TightVNC but it is a PITB because of the sluggish response due to the slow connection to there from here. So I want to make a console type program instead which continuously displays the state of the GPIO outputs (like I have GUI shapes which change color) and then reacts to key presses where single letters mean different things causing an action on the outputs. What I do not want is a program that scrolls up on the screen as keys are entered etc. I want the screen to stay put and only the status fields change when I do the commands. Your two responses have been a bit over the top of my head in this context. I should have formulated my request a bit clearer of course. For example comparing to the nano editor was a bit over the top. :( -- Bo Berglund Developer in Sweden -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Example of full screen console program anywhere?
On 04/25/2016 10:31 AM, Sven Barth wrote: Am 25.04.2016 16:59 schrieb "Bo Berglund": I need to create a console program, but one that works similar to the nano editor, the gpsd position/satellite view or raspi-config on a Raspberry Pi. I.e. the program manages the full terminal screen and displays its data in certain areas on screen and reads keystrokes as commands for controlling the program. I once did such programs on Windows using BASIC, but that was before Windows appeared and I have all but forgotten how it was actually accomplished So I am looking for some examples to start off where the cursor for writing is positioned on the screen in order to put output data in certain places and commands can be entered without moving the displayed screen. Is there such an example for FPC/Lazarus available somewhere? Target is Raspbian on a Raspberry Pi3 and I cannot use any GUI system for this because it must be accessed remotely via SSH (PuTTY) over a slow link that does not work decently with the graphical interface. One example would be the Free Pascal's text mode IDE that you can find in the compiler's sources in ide/. It uses the Free Vision component system that's an open source clone of Turbo Pascal's Turbo Vision (FV is also part of FPC). About two years ago (on 26 May 2014) I put together a mini FPC distribution that compiled the FP IDE: http://turbocontrol.com/gnuroot.htm -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Example of full screen console program anywhere?
Am 25.04.2016 16:59 schrieb "Bo Berglund": > > I need to create a console program, but one that works similar to the > nano editor, the gpsd position/satellite view or raspi-config on a > Raspberry Pi. > I.e. the program manages the full terminal screen and displays its > data in certain areas on screen and reads keystrokes as commands for > controlling the program. > I once did such programs on Windows using BASIC, but that was before > Windows appeared and I have all but forgotten how it was actually > accomplished > So I am looking for some examples to start off where the cursor for > writing is positioned on the screen in order to put output data in > certain places and commands can be entered without moving the > displayed screen. > > Is there such an example for FPC/Lazarus available somewhere? > Target is Raspbian on a Raspberry Pi3 and I cannot use any GUI system > for this because it must be accessed remotely via SSH (PuTTY) over a > slow link that does not work decently with the graphical interface. One example would be the Free Pascal's text mode IDE that you can find in the compiler's sources in ide/. It uses the Free Vision component system that's an open source clone of Turbo Pascal's Turbo Vision (FV is also part of FPC). Regards, Sven -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
[Lazarus] Example of full screen console program anywhere?
I need to create a console program, but one that works similar to the nano editor, the gpsd position/satellite view or raspi-config on a Raspberry Pi. I.e. the program manages the full terminal screen and displays its data in certain areas on screen and reads keystrokes as commands for controlling the program. I once did such programs on Windows using BASIC, but that was before Windows appeared and I have all but forgotten how it was actually accomplished So I am looking for some examples to start off where the cursor for writing is positioned on the screen in order to put output data in certain places and commands can be entered without moving the displayed screen. Is there such an example for FPC/Lazarus available somewhere? Target is Raspbian on a Raspberry Pi3 and I cannot use any GUI system for this because it must be accessed remotely via SSH (PuTTY) over a slow link that does not work decently with the graphical interface. -- Bo Berglund Developer in Sweden -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus