Shellminator V3.0.1
Simple Terminal
|
We’re slowly getting to the examples where we’ll start using the terminal for cooler and cooler tasks. But before that, we need to understand how the terminal emulator works on our computer. The terminal emulator processes simple text commands that contain a few special characters. These special characters tell the terminal emulator what specific operation it needs to perform. The terminal emulator works best when it has to process large amounts of data at once because it can interpret the data all together. If, for example, it receives one command character by character instead of all at once, it’s not the end of the world. The only thing you might notice is that the screen might flicker since the rendering happens character by character, not in blocks.
In the demo below, the speed improvement might not be super noticeable since it's running on a fast computer. You'll really see the difference when typing quickly on a slower microcontroller.
This issue can be solved using buffering. You can think of it like having a relatively large buffer where Shellminator starts building the package that it would normally send to the terminal interface character by character. The data accumulates in this buffer until:
By default, buffering is turned off to save memory for the system. For example, on an Arduino Uno R3, it's not even recommended to enable it. However, if you have a microcontroller with 5-10kByte of free memory, you can comfortably set up a buffer for better terminal performance. We recommend that the buffer be at least 100 bytes in size, but of course, the larger it is, the better. However, it's rare for a buffer larger than 10kByte to result in significant improvements, so it's a good idea to experiment and find the ideal size for your specific environment.
It might seem a bit tricky at first, but we’ve put a lot of work into making this process as simple as possible for you. First, you'll need the buffer itself:
Next, we calculate the buffer size (this step is optional, but trust me, it’s easier this way):
Finally, in the initialization section, we enable buffering:
This should make everything much smoother and easier to manage!