.. include:: Homework: PWM Controller (2026-03-16) ===================================== Getting ------- * Update your fork (see :ref:`fh-ss-2024-update-fork`) * Massage ``googletest`` submodule. This has to be done only once. .. code-block:: console $ git submodule init $ git submodule update Exercise (Test Driven Development - TDD) ---------------------------------------- * New exercise: ``/exercises/pwm/_codebergaccountname_/`` * **DO NOT MODIFY** anything but ``pwm.{h,cpp}`` * Test driven development .. code-block:: console $ pwd /home/jfasch/My-Builds/FH-STECE2024-x86_64/exercises/pwm/_codebergaccountname_ $ ./pwm-suite._codebergaccountname_ Running main() from /home/jfasch/My-Projects/FH-STECE2024/googletest/googletest/src/gtest_main.cc [==========] Running 9 tests from 1 test suite. [----------] Global test environment set-up. [----------] 9 tests from pwm_test [ RUN ] pwm_test.init_ok /home/jfasch/My-Projects/FH-STECE2024/exercises/pwm/_codebergaccountname_/test_pwm.cpp:52: Failure Value of: ok Actual: false Expected: true [ FAILED ] pwm_test.init_ok (0 ms) [ RUN ] pwm_test.init_nok [ OK ] pwm_test.init_nok (0 ms) [ RUN ] pwm_test.set_period_ok /home/jfasch/My-Projects/FH-STECE2024/exercises/pwm/_codebergaccountname_/test_pwm.cpp:67: Failure Value of: ok Actual: false Expected: true [ FAILED ] pwm_test.set_period_ok (0 ms) [ RUN ] pwm_test.set_period__no_read_permissions_on_file /home/jfasch/My-Projects/FH-STECE2024/exercises/pwm/_codebergaccountname_/test_pwm.cpp:88: Failure Value of: ok Actual: false Expected: true [ FAILED ] pwm_test.set_period__no_read_permissions_on_file (0 ms) [ RUN ] pwm_test.get_period_ok /home/jfasch/My-Projects/FH-STECE2024/exercises/pwm/_codebergaccountname_/test_pwm.cpp:108: Failure Value of: ok Actual: false Expected: true [ FAILED ] pwm_test.get_period_ok (0 ms) [ RUN ] pwm_test.set_duty_cycle_ok /home/jfasch/My-Projects/FH-STECE2024/exercises/pwm/_codebergaccountname_/test_pwm.cpp:124: Failure Value of: ok Actual: false Expected: true [ FAILED ] pwm_test.set_duty_cycle_ok (0 ms) [ RUN ] pwm_test.get_duty_cycle_ok /home/jfasch/My-Projects/FH-STECE2024/exercises/pwm/_codebergaccountname_/test_pwm.cpp:137: Failure Value of: ok Actual: false Expected: true [ FAILED ] pwm_test.get_duty_cycle_ok (0 ms) [ RUN ] pwm_test.activate_deactivate_ok /home/jfasch/My-Projects/FH-STECE2024/exercises/pwm/_codebergaccountname_/test_pwm.cpp:153: Failure Value of: ok Actual: false Expected: true [ FAILED ] pwm_test.activate_deactivate_ok (0 ms) [ RUN ] pwm_test.is_active_ok /home/jfasch/My-Projects/FH-STECE2024/exercises/pwm/_codebergaccountname_/test_pwm.cpp:172: Failure Value of: ok Actual: false Expected: true [ FAILED ] pwm_test.is_active_ok (0 ms) [----------] 9 tests from pwm_test (2 ms total) [----------] Global test environment tear-down [==========] 9 tests from 1 test suite ran. (2 ms total) [ PASSED ] 1 test. [ FAILED ] 8 tests, listed below: [ FAILED ] pwm_test.init_ok [ FAILED ] pwm_test.set_period_ok [ FAILED ] pwm_test.set_period__no_read_permissions_on_file [ FAILED ] pwm_test.get_period_ok [ FAILED ] pwm_test.set_duty_cycle_ok [ FAILED ] pwm_test.get_duty_cycle_ok [ FAILED ] pwm_test.activate_deactivate_ok [ FAILED ] pwm_test.is_active_ok 8 FAILED TESTS * Running single tests and not all at once (handy for occasional ``strace`` debugging sessions) .. code-block:: console $ strace ./pwm-suite.jfasch --gtest_filter=pwm_test.set_period__no_read_permissions_on_file Additional Information: PWM On Linux ------------------------------------ * See how a PWM controller is handled on Linux: :ref:`linux_hw_pwm__sysfs` Additional Information: C++ --------------------------- ``bool`` ........ * ``bool`` is a dedicated type, don't have to misfit ``int`` ``std::string`` ............... .. topic:: See also From :doc:`/trainings/material/soup/cxx/cxx03/900-standard-library-miscellanea/string/topic`: * :ref:`cxx-string--operators` * :ref:`cxx-string--c-compat` * :ref:`cxx-string--conversion-to-int` * :ref:`cxx-string--conversion-from-int` * C++ strings (:doc:`/trainings/material/soup/cxx/cxx03/900-standard-library-miscellanea/string/topic`) are convenient * Operators (see :ref:`cxx-string--operators`) * |longrightarrow| Concatentation, assignment (see :ref:`cxx-string--conversion-to-int` and :ref:`cxx-string--conversion-from-int`) * Drawback: system calls like :doc:`open ` are defined in C |longrightarrow| needs explicit conversion back and forth (see :ref:`cxx-string--c-compat`) ``std::filesystem::path`` ......................... .. topic:: See also From :doc:`/trainings/material/soup/cxx/cxx11/filesystem/topic` * :ref:`cxx-filesystem--concat-compare` * PWM in ``sysfs`` uses paths heavily * |longrightarrow| ``std::filesystem::path`` * Conversion to C string: ``path.c_str()``, just like ``std::string``