Subsections of
About me
WHO am I?
I’m just another… One of those who loves different technical gadgets.
Who am I? For you, I’m another dude on the Internet who loves to write, program and solder different things. I do not set a goal to convey something to someone through the network. Whom need to find everything himself. The Internet offers great opportunities not only to waste time on social networks, but also to improve yourself.
Not so long ago, I became more interested in programming and Linux operating systems, and microcontrollers. Everything I love I will post here. Everything that helped me at least once I will write here on these pages.
These are my notes in the margins.
That’s all I can think of right now. I hope to add something to this later. 😅
Are you curious about me? Use the links below to visit my profiles.
GNU/Linux
LINUX NOTES SECTION
Subsections of GNU/Linux
Bash yaml parser
yb - a bash yaml parser
yb
provides a pure Bash solution to YAML parsing.
Usage
yb [-h|-a|-c|-q|-r|-A-C-d-F-K-l-L-R-n-T] [-f <file>|-o <object>] [-k <key>] [-v <value>|-O <object value>]
Examples
./yb -f file.yaml -k "key.childkey"
From the repository, you can do a quick try like so:
./yb -f tests/user.yaml -k "yb"
Create keys:
./yb -af tests/user.yaml -k "new.key"
add an inline-value:
./yb -af tests/user.yaml -k "new.key" -v "one, two"
change it:
./yb -cf tests/user.yaml -k "new.key" -v "three"
add list-values:
./yb -af tests/user.yaml -k "new.- list" -v "- one - two"
add an ASCII within a pipe-key:
./yb -af tests/user.yaml -k "new.ascii|" -v "|> ___ _ |> \ \// |> \ / |> / / |> /_/"
manipulate the YAML as a bash variable:
# using the '-R' raw option is advised to retrieve the content without color codes
my_YAML=$(./yb -f tests/user.yaml -k "new")
my_YAML=$(./yb -ao "${my_YAML}" -k "in_memory" -v "true")
add it to a file:
./yb -af tests/user.yaml -k "new.copy" -o "${my_YAML}"
Remove one value:
./yb -rf tests/user.yaml -k "new.- list" -v "- one"
or remove everything:
./yb -rf tests/user.yaml -k "new"
Options
yb
options are divided under 3 types:
action
: action options are ran against the file and are not compatible with each others. They are compatible withinput
, but notformat
.input
: input options are user settable options, and are compatible with each others. They are compatible with bothaction
andformat
.format
: format options print the output in various ways. They are compatible with each others, with theinput
type , but not theaction
one.
Option | Name | Type | Description | Example | Notes |
---|---|---|---|---|---|
-a | add | action | Adds key(s), value(s) or both. | yb -f "file.yaml" -a -k "key" -v "value" | |
-c | change | action | Changes value(s). | yb -f "file.yaml" -c -k "key" -v "new_value" | |
-q | query | action | Prints true or false if key(s), value(s) or both are present or not. | yb -f "file.yaml" -q -k "key" | Using single quotes is advised to retrieve a pipe value -v 'pipe value' . |
-r | remove | action | Removes key(s), value(s) or both. | yb -f "file.yaml" -r -k "key" -v "value" | Using single quotes is advised to remove a pipe value -v 'pipe value' . |
-f | file | input | YAML file path. | yb -f "file.yaml" | A file can be presented without the -f option, as the $1 option. -f and -c are not compatible with each others. |
-o | object | input | YAML object. | yb -o "${YAML_object}" | YAML object can be used with all actions. -f and -o are compatible together, only when adding an object to a file. |
-O | object value | input | YAML object value. | yb -f "file.yaml" -O "${YAML_object}" | YAML object can be used with the -a action. |
-k | key | input | Key(s) selection path. | yb -f "file.yaml" -k "key" | Support keys in this format :key , key.childkey , - list-key , pipe-key| . Multiple key(s) can be provided with a . as the separator. |
-v | value | input | Value(s) to be added, removed, queried or changed. | yb -f "file.yaml" -k "key" -v "value" | Support values in this format : value , - list-value , |> pipe-value . |
-A | array | format | Prints the output as a bash array. | yb -f "file.yaml" -A -k "key" | Will provide a different formatting if used with -F or -d . |
-C | colors | format | Force colors in a non-terminal output. | yb -Cf "file.yaml" -A -k "key" | |
-d | depth | format | Provides the output with the original depth. | yb -f "file.yaml" -d -k "key.childkey" -v "new_value" | |
-F | format | format | Prints a formatted output to represent the arborescence inline. | yb -f "file.yaml" -F -k "key" | Will provide a different formatting if used with -A or -d . |
-K | keys-only | format | Prints only keys. | yb -Kf "file.yaml" -k "key" | |
-l | line | format | Prints { {line } } on each lines. | yb -f "file.yaml" -l -k "key" | |
-L | level | format | Prints { {<level number> } } on each lines. | yb -f "file.yaml" -L -k "key" | |
-R | raw | format | Prints the ouptut without added colors, comments and empty lines. | yb -f "file.yaml" -R -k "key" | |
-n | number | format | Prints { {<line number> } } on each lines. | yb -f "file.yaml" -n -k "key" | |
-T | type | format | Prints a value type. | yb -f "file.yaml" -T -k "key" | Supports null , boolean , integer , floating number , string . |
-s | spaces | Deprecated | Spaces number selection. |
YAML support
yb
provides the basic YAML support for editing and reading a YAML file. As by version 0.9, yb
doesn’t support advanced features such as group based search, anchors, aliases, and overrides.
Thank you
All of you, YAML’ers !
Made in Bash.
Library
Subsections of Library
WD.Easy
WD.Easy
This library is intended to control watchdog modes of operation, so far only series microcontrollers AVR
.
Features
I did not write it in the style of a singleton class (the watchdog is one). No matter how many objects are created, they will all work with the same register. I set myself the task to make the library as easy as possible and can be used for any Arduino and not only.
The main requirement is that the TIMER SHOULD START COUNTING EVEN BEFORE THE FUNCTION setup
STARTS , and even better before the start of main
.
It seems to have worked
Methods are available in the timer
Method | DESCRIPTION | result |
---|---|---|
setTimeOut(uint8_t) | Sets the timer trigger interval | void |
setMode(uint8_t) | Sets the action when the timer is triggered | void |
setTask(ptr*) | Set the interrupt handler function | void |
getTimeOut() | Get the frequency of activations | uint8_t |
getMode() | Get the timer mode | uint8_t |
isEnable() | Is the timer active? | bool |
reset() | Start a new countdown | void |
Intervals
The table shows the parameters accepted by the method setTimeOut(uint8_t)
and returns getTimeOut()
.
define | time s | |
---|---|---|
WD_15MS | 0.015 | |
WD_30MS | 0.030 | |
WD_60MS | 0.060 | |
WD_120MS | 0.120 | |
WD_250MS | 0.250 | |
WD_500MS | 0.500 | |
WD_1S | 1 | |
WD_2S | 2 | |
WD_4S | 4 | |
WD_8S | 8 |
Note The time is approximate and not suitable for measuring exact intervals, since the watchdog timer is clocked by an internal low-latency oscillator that “floats” when the supply voltage and temperature change
Actions
define | DESCRIPTION |
---|---|
DISABLED | The timer is stopped |
INTERRUPT | When triggered, the interrupt handler will be called |
SYSTEMRESET | When triggered, the microcontroller will be rebooted |
INTERUPTANDRESET | When triggered, the interrupt handler will be called after the same intervals, the controller will be rebooted |
Обробник переривань
By default, no interrupt handler is specified (nullptr
).
Examples
Example one
void WD_tick() {
Serial.print("WD_tick()");
Serial.println(millis());
}
WatchDogEasy WD(WatchDogEasy::WD_1S, WatchDogEasy::INTERRUPT, WD_tick);
void setup() { Serial.begin(115200); }
void loop() {}
Here we trigger the timer to fire every second, when it fires, an interrupt will be generated, which will be handled by the WD_tick()
function.
In this example, the timer starts counting even before the setup()
function starts. This is convenient if there is a risk of the controller freezing during initiation.
Example two
void WD_tick() {
Serial.print("WD_tick()");
Serial.println(millis());
}
WatchDogEasy WD;
void setup() {
Serial.begin(115200);
WD.setTimeOut(WatchDogEasy::WD_1S);
WD.setMode(WatchDogEasy::INTERRUPT);
WD.setTask(WD_tick);
}
void loop() {}
Everything is the same here, but the timer starts counting after the last setter.
All setters reset the timer to a new count. Getters do not (Be careful). During the execution of the getter, the time may coincide and the action programmed in the timer may be executed.
Example three
WatchDogEasy WD(WatchDogEasy::WD_1S, WatchDogEasy::SYSTEMRESET, nullptr);
int main(){
for(;;){
}
}
Here, the timer is initialized before entering main()
. In my opinion, it’s super convenient
“System Requirements”
The timer will work on any Arduino and AVR series microcontrollers
An additional 2 bytes in the RAM will take up space in the flash 198 bytes
The most important thing
Installation
- You can download a zip archive WD.Easy v1.0 And extract the contents to the desired directory
- The library is available for installation through the Arduino IDE library manager.
- You can download a zip archive WD.Easy prerelise. This is a test branch with the most recent code, not debugged. It is set as the first item of this list
Need to connect
#include <WD.Easy.hpp>
and do not forget to set the timer so that it does not reset the program