# HG changeset patch # User František Kučera # Date 1513955456 -3600 # Node ID 1ecfa42ca0d284096551a111ad573898e5198f42 # Parent 1d1cc6552542237b94fa9c2f0d0b2298d362cd58 local variables inside switch diff -r 1d1cc6552542 -r 1ecfa42ca0d2 c++/rgb-assembler/rgb-assembler.cpp --- a/c++/rgb-assembler/rgb-assembler.cpp Fri Dec 22 00:21:29 2017 +0100 +++ b/c++/rgb-assembler/rgb-assembler.cpp Fri Dec 22 16:10:56 2017 +0100 @@ -14,6 +14,8 @@ typedef uint8_t sleep_t; typedef uint8_t color_t; +// TODO: strong typedefs http://www.boost.org/doc/libs/1_61_0/libs/serialization/doc/strong_typedef.html ? + const address_t MEMORY_SIZE = 1024; const command_t CMD_GOTO = 0x70; @@ -76,34 +78,38 @@ command_t ch = read(memory, i); wprintf(L"%02X ", ch); - color_t r; - color_t g; - color_t b; - - sleep_t delay; - switch (ch) { case CMD_GOTO: + { i = read(memory, i); wprintf(L"GOTO %*d\n", 5, i); break; + } case CMD_SLEEP: - delay = read(memory, i); + { + sleep_t delay = read(memory, i); wprintf(L"SLEEP %*d ms\n", 4, delay); this_thread::sleep_for(chrono::milliseconds(delay)); break; + } case CMD_COLOR: - r = read(memory, i); - g = read(memory, i); - b = read(memory, i); + { + color_t r = read(memory, i); + color_t g = read(memory, i); + color_t b = read(memory, i); wprintf(L"COLOR %02X %02X %02X\n", r, g, b); break; + } case CMD_END: + { wprintf(L"END\n"); i = MEMORY_SIZE; break; + } default: + { wprintf(L"invalid command\n"); + } } }