Skip to content

Commit

Permalink
feat: add configurable colors red and purple
Browse files Browse the repository at this point in the history
  • Loading branch information
xxthunder committed Nov 9, 2023
1 parent 0476a26 commit 95b2d6c
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 15 deletions.
11 changes: 0 additions & 11 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@
"test"
],
"python.testing.unittestEnabled": false,
"python.formatting.provider": "black",
"python.formatting.blackArgs": [
"--line-length",
"240"
],
"python.formatting.blackPath": "black",
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
"python.linting.flake8Args": [
"--ignore=W293"
],
"python.analysis.extraPaths": [
"test"
],
Expand Down
3 changes: 2 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@
"console_interface",
"keyboard_interface",
"light_controller",
"main",
"main_control_knob",
"power_signal_processing",
"rte",
"main"
"spled"
]
}
]
Expand Down
6 changes: 6 additions & 0 deletions src/light_controller/KConfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@ menu "Light Controller"

config COLOR_BLUE
bool "Blue"

config COLOR_RED
bool "Red"

config COLOR_PURPLE
bool "Purple"
endchoice
endmenu
7 changes: 6 additions & 1 deletion src/light_controller/src/light_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ static void turnLightOn(void) {
RGBColor color = OFF_COLOR;
#if CONFIG_COLOR_BLUE
color.blue = getBrightnessValue();
#else
#elif CONFIG_COLOR_GREEN
color.green = getBrightnessValue();
#elif CONFIG_COLOR_RED
color.red = getBrightnessValue();
#elif CONFIG_COLOR_PURPLE
color.red = getBrightnessValue() / 2;
color.blue = getBrightnessValue();
#endif
#if CONFIG_BLINKING_RATE_AUTO_ADJUSTABLE
blinkState = TRUE;
Expand Down
6 changes: 5 additions & 1 deletion src/light_controller/test/test_light_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ MATCHER_P(RGBColorEq, expected, "") {

#if CONFIG_COLOR_BLUE
const RGBColor onColor = { .red = 0, .green = 0, .blue = LED_BRIGHTNESS };
#else
#elif CONFIG_COLOR_GREEN
const RGBColor onColor = { .red = 0, .green = LED_BRIGHTNESS, .blue = 0 };
#elif CONFIG_COLOR_RED
const RGBColor onColor = { .red = LED_BRIGHTNESS, .green = 0, .blue = 0 };
#elif CONFIG_COLOR_PURPLE
const RGBColor onColor = { .red = LED_BRIGHTNESS / 2, .green = 0, .blue = LED_BRIGHTNESS };
#endif
const RGBColor offColor = { .red = 0, .green = 0, .blue = 0 };

Expand Down
33 changes: 33 additions & 0 deletions src/spled/doc/ai_example/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Examplary Usage of GitHub Copilot
=================================

Steps to add two additional colors to the Sleep Light for Customer B by using GitHub Copilot:

* Open guiconfig of variant CustB/Sleep to show the configuration of the light controller.
* Close it.
* Build the product and show that the LED is blue for the Sleep Light for Customer B.
* Open KConfig of light controller and add two additional colors to the list of colors by marking the whole file, hit Ctrl+I and ask:
::

"Please add two additional colors red and purple to the list of colors."

* Open guiconfig of variant CustB/Sleep again and configure purple as color.
* Open test_light_controller.cc and adapt the tests to support purple as configured color by marking the color config section and asking:
::

"We have 4 possible configuration values now for the selected code: blue, green, red and purple. Could you adapt this code part to reflect that?"

* Run the tests and see that they fail.
* Open light_controller.c and adapt the code to support purple as configured color by marking the function turnLightOn() and asking:
::

"We have 4 possible configuration values now for the selected code: blue, green, red and purple. Could you adapt this code part to reflect that?"

* Run the tests and see that they pass. Actually they might fail due to different definition of the colors in the test and the code.
* Adapt the test to use the same definition as the code by asking:
::

"In the productive code we used half the brightness value for red. I would like to use this color definition here, too."

* Build the product and show that the LED is purple for the Sleep Light for Customer B.
* Done.
2 changes: 2 additions & 0 deletions src/spled/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ SPLed Documentation
/doc/common/customer_requirements/index.rst
/doc/common/sw_architecture/index.rst
/doc/common/variants/index.rst
ai_example/index.rst

4 changes: 3 additions & 1 deletion variants/CustB/Sleep/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ CONFIG_BRIGHTNESS_ADJUSTMENT=y
# Light Controller
#
# CONFIG_COLOR_GREEN is not set
CONFIG_COLOR_BLUE=y
# CONFIG_COLOR_BLUE is not set
# CONFIG_COLOR_RED is not set
CONFIG_COLOR_PURPLE=y
# end of Light Controller
# end of Features

0 comments on commit 95b2d6c

Please sign in to comment.