move standard commands (codes) to a header file
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 24 Dec 2017 00:17:12 +0100
changeset 282b2f8a17d63a
parent 27 835bd4559e5c
child 29 10d6964e7b4a
move standard commands (codes) to a header file
c++/rgb-assembler/commands.h
c++/rgb-assembler/nbproject/configurations.xml
c++/rgb-assembler/rgb-assembler.cpp
c++/rgb-assembler/types.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/c++/rgb-assembler/commands.h	Sun Dec 24 00:17:12 2017 +0100
     1.3 @@ -0,0 +1,59 @@
     1.4 +#pragma once
     1.5 +
     1.6 +// Standard commands
     1.7 +
     1.8 +/**
     1.9 + * Skip to the given address.
    1.10 + * parameter: address_t
    1.11 + */
    1.12 +const command_t CMD_GOTO = 0x70;
    1.13 +
    1.14 +/**
    1.15 + * Compare values on two addresses and go to one of given three addresses.
    1.16 + * parameter: address_t a
    1.17 + * parameter: address_t b
    1.18 + * parameter: address_t GOTO target when a == b
    1.19 + * parameter: address_t GOTO target when a > b
    1.20 + * parameter: address_t GOTO target when a < b
    1.21 + */
    1.22 +const command_t CMD_GOTO_COMPARE = 0x80;
    1.23 +
    1.24 +/**
    1.25 + * Wait given time in ms.
    1.26 + * parameter: sleep_t
    1.27 + */
    1.28 +const command_t CMD_SLEEP = 0xFF;
    1.29 +
    1.30 +/**
    1.31 + * Set RGB LED color.
    1.32 + * parameter: led_t LED number
    1.33 + * parameter: color_t red
    1.34 + * parameter: color_t green
    1.35 + * parameter: color_t blue
    1.36 + */
    1.37 +const command_t CMD_COLOR = 0xAA;
    1.38 +
    1.39 +/**
    1.40 + * Stop program.
    1.41 + */
    1.42 +const command_t CMD_END = 0xED;
    1.43 +
    1.44 +/**
    1.45 + * Increase value at given address
    1.46 + * parameter: address_t
    1.47 + */
    1.48 +const command_t CMD_INCREMENT = 0x11;
    1.49 +
    1.50 +/**
    1.51 + * Decrease value at given address
    1.52 + * parameter: address_t
    1.53 + */
    1.54 +const command_t CMD_DECREMENT = 0x12;
    1.55 +
    1.56 +/**
    1.57 + * Placeholder for unsupported command.
    1.58 + * Just for testing.
    1.59 + */
    1.60 +const command_t CMD_INVALID = 0x1;
    1.61 +
    1.62 +// TODO: more commands, better numbers
    1.63 \ No newline at end of file
     2.1 --- a/c++/rgb-assembler/nbproject/configurations.xml	Sun Dec 24 00:12:58 2017 +0100
     2.2 +++ b/c++/rgb-assembler/nbproject/configurations.xml	Sun Dec 24 00:17:12 2017 +0100
     2.3 @@ -11,6 +11,7 @@
     2.4        <itemPath>commands/GotoCompare.h</itemPath>
     2.5        <itemPath>commands/IncrementDecrement.h</itemPath>
     2.6        <itemPath>commands/Sleep.h</itemPath>
     2.7 +      <itemPath>commands.h</itemPath>
     2.8        <itemPath>memory.h</itemPath>
     2.9        <itemPath>types.h</itemPath>
    2.10      </logicalFolder>
    2.11 @@ -51,6 +52,8 @@
    2.12        </compileType>
    2.13        <item path="Command.h" ex="false" tool="3" flavor2="0">
    2.14        </item>
    2.15 +      <item path="commands.h" ex="false" tool="3" flavor2="0">
    2.16 +      </item>
    2.17        <item path="commands/Color.h" ex="false" tool="3" flavor2="0">
    2.18        </item>
    2.19        <item path="commands/End.h" ex="false" tool="3" flavor2="0">
    2.20 @@ -93,6 +96,8 @@
    2.21        </compileType>
    2.22        <item path="Command.h" ex="false" tool="3" flavor2="0">
    2.23        </item>
    2.24 +      <item path="commands.h" ex="false" tool="3" flavor2="0">
    2.25 +      </item>
    2.26        <item path="commands/Color.h" ex="false" tool="3" flavor2="0">
    2.27        </item>
    2.28        <item path="commands/End.h" ex="false" tool="3" flavor2="0">
     3.1 --- a/c++/rgb-assembler/rgb-assembler.cpp	Sun Dec 24 00:12:58 2017 +0100
     3.2 +++ b/c++/rgb-assembler/rgb-assembler.cpp	Sun Dec 24 00:17:12 2017 +0100
     3.3 @@ -8,6 +8,7 @@
     3.4  #include "types.h"
     3.5  #include "memory.h"
     3.6  #include "Command.h"
     3.7 +#include "commands.h"
     3.8  #include "commands/Goto.h"
     3.9  #include "commands/GotoCompare.h"
    3.10  #include "commands/Sleep.h"
    3.11 @@ -17,64 +18,6 @@
    3.12  
    3.13  using namespace std;
    3.14  
    3.15 -// TODO: strong typedefs http://www.boost.org/doc/libs/1_61_0/libs/serialization/doc/strong_typedef.html ?
    3.16 -
    3.17 -/**
    3.18 - * Skip to the given address.
    3.19 - * parameter: address_t
    3.20 - */
    3.21 -const command_t CMD_GOTO = 0x70;
    3.22 -
    3.23 -/**
    3.24 - * Compare values on two addresses and go to one of given three addresses.
    3.25 - * parameter: address_t a
    3.26 - * parameter: address_t b
    3.27 - * parameter: address_t GOTO target when a == b
    3.28 - * parameter: address_t GOTO target when a > b
    3.29 - * parameter: address_t GOTO target when a < b
    3.30 - */
    3.31 -const command_t CMD_GOTO_COMPARE = 0x80;
    3.32 -
    3.33 -/**
    3.34 - * Wait given time in ms.
    3.35 - * parameter: sleep_t
    3.36 - */
    3.37 -const command_t CMD_SLEEP = 0xFF;
    3.38 -
    3.39 -/**
    3.40 - * Set RGB LED color.
    3.41 - * parameter: led_t LED number
    3.42 - * parameter: color_t red
    3.43 - * parameter: color_t green
    3.44 - * parameter: color_t blue
    3.45 - */
    3.46 -const command_t CMD_COLOR = 0xAA;
    3.47 -
    3.48 -/**
    3.49 - * Stop program.
    3.50 - */
    3.51 -const command_t CMD_END = 0xED;
    3.52 -
    3.53 -/**
    3.54 - * Increase value at given address
    3.55 - * parameter: address_t
    3.56 - */
    3.57 -const command_t CMD_INCREMENT = 0x11;
    3.58 -
    3.59 -/**
    3.60 - * Decrease value at given address
    3.61 - * parameter: address_t
    3.62 - */
    3.63 -const command_t CMD_DECREMENT = 0x12;
    3.64 -
    3.65 -/**
    3.66 - * Placeholder for unsupported command.
    3.67 - * Just for testing.
    3.68 - */
    3.69 -const command_t CMD_INVALID = 0x1;
    3.70 -
    3.71 -// TODO: more commands, better numbers
    3.72 -
    3.73  int main(int argc, char* argv[]) {
    3.74  
    3.75  	setlocale(LC_ALL, "");
     4.1 --- a/c++/rgb-assembler/types.h	Sun Dec 24 00:12:58 2017 +0100
     4.2 +++ b/c++/rgb-assembler/types.h	Sun Dec 24 00:17:12 2017 +0100
     4.3 @@ -8,3 +8,5 @@
     4.4  typedef uint8_t sleep_t;
     4.5  typedef uint8_t color_t;
     4.6  typedef uint8_t led_t;
     4.7 +
     4.8 +// TODO: strong typedefs http://www.boost.org/doc/libs/1_61_0/libs/serialization/doc/strong_typedef.html ?