Order Of Code


Moroccon S. Karpet, 1890
This page contains mainly notes of how to add new subprogram on Arduino Mega at General Learning Machine. Also the general appearance of "Operation system" of GLM is discussed briefly.

User Interface

User interface on GLM mainly consist matrix keypad, rotary encoder and lcd-screen . Function of each button depends of what subprogram is chosen. Mostly those chancing button functions on keypad are shown on lcd with keybad "image".
All subrograms use mainly same set of graphical elements for consistency and reusable code.

Operation codes

Implementing operation codes on GLM is attempt to have same user logic on source code, GUI and orders given outside.
Keypad is from some old cordles phone (chosen only because it is little enough), and button zero has also text "OPER". So it ispired function what I call "operation code".
On starting screen keypad buttons are used as fast access to some subprograms, but there are not enough buttons to all subprograms.This is firs reason for operation codes. If button zero is pressed on starting screen, user can insert operation code, which is some sort of shortening and uses alphabets marked on keypad. For example 8467 is "THOR" and so on.
Secondly, idea is to use operation codes as fast settings. Then 2633 may mean "AM33", like AM receiver memorychannel 33.
Third reason, operation codes can be given outside of GUI. So program itself can declare operation code and start some function with given settings. Or operation codes can be given from outside Mega, from Raspi or perhaps with DTMF-tones from handheld radio.

Picture: Gui2() is for larger drawings, either image or text. Here used for voltage plotter, which is like slow oscilloscope. Only lowest row of buttons are "visible". Thats why "0" is always "stop"-button.


Modularisation work

GLM started at some kind of simple receiver project. Orginally idea was just build something well, not general framework for building everything well.
Code on Arduino mega was simple menu-driven receiver. When new menus were added and added, code itself became horrible. Also my own knowledge about coding get a bit better and I rewrite everything not only better but also to support easy modifications of system, this means mainly adding new subprograms on code.
There are reusable User Interface elements and for example some data at eeprom which is shared across different subprograms. Like there is one subrogram whis is meant to be used to text insert, this text is saved to eeprom and can be used for example for THOR-beacon.

Picture:Gui() is for "normal" user interface with visible buttonfunctions.

IDE considerations

I recently have tried many IDEs for better handling of code, witch is about 2000 lines long now. I mainly wanted ability to fold ("collapse") code, of course.
I have tried Eclipse with Arduino plugin, Uecide, Codeblocks, Gedit, Geany, VIM, Emacs and some others...and after all ended to use Arduino IDE , just learned to use tabs. ..

Subprogram form:

Functions with own GUI are called subprograms here. Other functions on source code are called utility functions.
New subprogram should be written on own tab.
Name of tab is corresponding operation code, if used.
"Real" information is stored to global variables (frequency, volume, time, operation code, etc). These global variables are on beginning of main tab. Other variables are not to be shared between subprograms. (So if variable is shared between subprograms, it must be moved to main tab.)

Subprogram consist of blocks: (Should these blocks be separate functions? This sounds good! But function calling time?)

-Static gui
-loop (while key != '0') which consists:
-Logic (which may be functions gathered from other subprograms and utility functions).
-If there are reusable parts, they should be separate functions on one tab.
-Dynamic GUI (refreshed parts of lcd) should then be separate function, in order to use only logic if needed?

example: tab named "oneFunction"

void oneFunctionStaticGui(){
....GUI(); etc

void oneFunctionloop(){
....(while key != '0'){

void oneFunctionLogic(){
....Some logic....

Utility functions

Separate tabs for grouped utility functions:
-Graphical GUI functions

"Physical devices" should have own tab:

(Yes, I havent yet decided everything about this subject....these are just preliminary thoughts. )

// subprogramExample()   *****************************************
void subprogramExample(){
  //Static Gui
  buttonLabel('1', "St+ "); //for example...
  while (key != '0'){
    key = keypad.getKey();
    //Also chancing stuff on Gui comes from here
    // if other subprogram is called from here,
    // operCode can be used to get back directly
  operCode = 0;
  key = NO_KEY;
// subprogramExample() ends **************************************