diff --git a/02 Lab 1 Test-Driven Development.md b/02 Lab 1 Test-Driven Development.md index 1c90b87..d13801c 100644 --- a/02 Lab 1 Test-Driven Development.md +++ b/02 Lab 1 Test-Driven Development.md @@ -1,7 +1,7 @@ # Test-Driven Development with Arduino -In this lab you will learn how to carry out the process of Test-Driven development (TDD) using the Arduino framework. We will be using the PlatformIO plugin for the Visual Studio Code IDE. +In this lab you will learn how to carry out the process of Test-Driven development (TDD) using the Arduino framework. We will be using the PlatformIO command-line tools. There is [detailed documentation](https://docs.platformio.org/en/latest/plus/unit-testing.html#remote) covering the implementation of the [Unity](http://www.throwtheswitch.org/unity/) tools. ## 1 Understanding the Code @@ -27,7 +27,13 @@ You should now use the IDE to open the `exercises/02_tdd/temp/` directory which ## 2 Running the Unit Tests -We will be executing our test suite from the terminal by invoking the `pio` command together with the `test` subcommand. Make sure you [create an account](https://docs.platformio.org/en/latest/userguide/account/cmd_register.html) and [log in](https://docs.platformio.org/en/latest/userguide/account/cmd_login.html) +We will be executing our test suite from the terminal by invoking the `pio` command together with the `test` subcommand. Make sure you [create an account](https://docs.platformio.org/en/latest/userguide/account/cmd_register.html) and [log in](https://docs.platformio.org/en/latest/userguide/account/cmd_login.html). + +You should also ensure the `gcc` toolchain is installed on your computer. Run the command `gcc`. If this is not found you will need to install, the instructions differ depending on your operating system: + +1. MacOS: `brew install gcc` +2. Ubuntu: `apt install gcc` +3. Windows 10: install [Cygwin](https://sourceware.org/cygwin/) and make sure you pick the gcc tools from the selection of software it can install. ```shell $ pio test -v -e native @@ -50,12 +56,6 @@ $ pio test -v -e native Notice that the test suite fails! -If you gen an error stating that gcc is not installed you will need to do this: - -1. MacOS: `brew install gcc` -2. Ubuntu: `apt install gcc` -3. Windows 10: install [Cygwin](https://sourceware.org/cygwin/) - ## 3 Test-Driven Development You are now going to modify the code to ensure that the test passes. The test adds a single value to the library. It then reads the average value which should match the value we passed (but it doesn't). We are going to apply TDD principles. @@ -77,6 +77,7 @@ The third and final step is to tidy up the code, making sure the tests still pas Now apply the TDD principles to fix the following issues, this will take 6 TDD iterations: 1. If I send 2 values to the library, the average should be calculated based on the 2 values. Try adding 42 and 24, it should return 33. + 1. If the result is wrong perhaps you needed to call the `avg_clear()` function at the start of each test. 2. If the average is a floating point number it should round up if the average is 0.5 or above: 1. If I pass values of 42 and 23 the average should be 33. 2. If I pass values of 42, 11, 17, the average should be 23. diff --git a/exercises/01_arduino/blink/.vscode/settings.json b/exercises/01_arduino/blink/.vscode/settings.json index 4160df4..b15d089 100644 --- a/exercises/01_arduino/blink/.vscode/settings.json +++ b/exercises/01_arduino/blink/.vscode/settings.json @@ -1,6 +1,6 @@ { "terminal.integrated.env.linux": { - "PATH": "/home/mtyers/.platformio/penv/bin:/home/mtyers/.platformio/penv:/home/mtyers/.nvm/versions/node/v10.8.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin", + "PATH": "/home/mtyers/.platformio/penv/bin:/home/mtyers/.platformio/penv:/home/mtyers/.platformio/penv/bin:/home/mtyers/.platformio/penv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin", "PLATFORMIO_CALLER": "vscode" } } \ No newline at end of file diff --git a/exercises/01_arduino/blink/include/readme.txt b/exercises/01_arduino/blink/include/readme.txt new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/exercises/01_arduino/blink/include/readme.txt @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/exercises/01_arduino/blink/lib/readme.txt b/exercises/01_arduino/blink/lib/readme.txt new file mode 100644 index 0000000..c3fd443 --- /dev/null +++ b/exercises/01_arduino/blink/lib/readme.txt @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- readme.txt --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/exercises/01_arduino/blink/src/main.cpp b/exercises/01_arduino/blink/src/main.cpp index a36d148..57403c8 100644 --- a/exercises/01_arduino/blink/src/main.cpp +++ b/exercises/01_arduino/blink/src/main.cpp @@ -1,24 +1,18 @@ - -#ifndef UNIT_TEST - #include -#include long randNumber; void setup() { Serial.begin(9600); - pinMode(LED_BUILTIN, OUTPUT); + pinMode(D4, OUTPUT); // NodeMCU: D4, Lolin32: LED_BUILTIN randomSeed(analogRead(0)); } void loop() { randNumber = random(10, 20); Serial.println(randNumber); - digitalWrite(LED_BUILTIN, HIGH); + digitalWrite(D4, HIGH); // remember to change this for Lolin32 delay(1000); - digitalWrite(LED_BUILTIN, LOW); + digitalWrite(D4, LOW); // remember to change this for Lolin32 delay(1000); } - -#endif diff --git a/exercises/01_arduino/screen/include/readme.txt b/exercises/01_arduino/screen/include/readme.txt new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/exercises/01_arduino/screen/include/readme.txt @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/exercises/01_arduino/screen/platformio.ini b/exercises/01_arduino/screen/platformio.ini index a85e456..ef7048d 100644 --- a/exercises/01_arduino/screen/platformio.ini +++ b/exercises/01_arduino/screen/platformio.ini @@ -13,8 +13,8 @@ platform = espressif32 board = lolin32 framework = arduino ; upload_port = /dev/ttyUSB0 -upload_speed = 14400 ; 9600 14400 19200 28800 38400 57600 115200 +upload_speed = 9600 ; 9600 14400 19200 28800 38400 57600 115200 +upload_protocol = esptool lib_deps = ESP8266_SSD1306 - Adafruit_Sensor