diff --git a/libraries/AngleConvertor/.github/workflows/arduino-lint.yml b/libraries/AngleConvertor/.github/workflows/arduino-lint.yml index b2ca058c..8a26f14a 100644 --- a/libraries/AngleConvertor/.github/workflows/arduino-lint.yml +++ b/libraries/AngleConvertor/.github/workflows/arduino-lint.yml @@ -6,7 +6,7 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: arduino/arduino-lint-action@v1 with: library-manager: update diff --git a/libraries/AngleConvertor/.github/workflows/arduino_test_runner.yml b/libraries/AngleConvertor/.github/workflows/arduino_test_runner.yml index 096b975b..fadfa904 100644 --- a/libraries/AngleConvertor/.github/workflows/arduino_test_runner.yml +++ b/libraries/AngleConvertor/.github/workflows/arduino_test_runner.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: ruby/setup-ruby@v1 with: ruby-version: 2.6 diff --git a/libraries/AngleConvertor/.github/workflows/jsoncheck.yml b/libraries/AngleConvertor/.github/workflows/jsoncheck.yml index 04603d08..37a11298 100644 --- a/libraries/AngleConvertor/.github/workflows/jsoncheck.yml +++ b/libraries/AngleConvertor/.github/workflows/jsoncheck.yml @@ -10,7 +10,7 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: json-syntax-check uses: limitusus/json-syntax-check@v1 with: diff --git a/libraries/AngleConvertor/AngleConvertor.h b/libraries/AngleConvertor/AngleConvertor.h index be9e7df8..0866ae50 100644 --- a/libraries/AngleConvertor/AngleConvertor.h +++ b/libraries/AngleConvertor/AngleConvertor.h @@ -2,7 +2,7 @@ // // FILE: AngleConvertor.h // AUTHOR: Rob Tillaart -// VERSION: 0.1.0 +// VERSION: 0.1.1 // DATE: 2022-12-01 // PURPOSE: angle conversion class // URL: https://github.com/RobTillaart/AngleConvertor @@ -11,7 +11,7 @@ #include "Arduino.h" -#define ANGLECONVERTOR_LIB_VERSION (F("0.1.0")) +#define ANGLECONVERTOR_LIB_VERSION (F("0.1.1")) ///////////////////////////////////////////////////////////// @@ -34,7 +34,7 @@ public: void setHexacontade(float value = 0) { _v = value * (M_PI / 30.0); }; void setHourAngle(float value = 0) { _v = value * (M_PI / 12.0); }; void setMilliTurn(float value = 0) { _v = value * (M_PI / 500.0); }; - + void setMinuteTime(float value = 0) { _v = value * (M_PI / 720.0); }; void setOctant(float value = 0) { _v = value * (M_PI / 4.0); }; void setPechus(float value = 0) { _v = value * (M_PI / 90.0); }; // assumes 2° @@ -58,7 +58,7 @@ public: float getHexacontade() { return _v * (30.0 / M_PI); }; float getHourAngle() { return _v * (12.0 / M_PI); }; float getMilliTurn() { return _v * (500.0 / M_PI); }; - + float getMinuteTime() { return _v * (720.0 / M_PI); }; float getOctant() { return _v * (4.0 / M_PI); }; float getPechus() { return _v * (90.0 / M_PI); }; // assumes 2° @@ -71,8 +71,24 @@ public: float getTurn() { return _v * (0.5 / M_PI); }; + // WINDROSE + // + char * windrose() + { + return windrose(_v * (180.0 / M_PI)); + } + + char * windrose(float degrees) + { + uint8_t idx = (degrees + 11.25) * 0.044444444444444; // 1.0 / 22.5 + return _wr2[idx]; + } + private: - float _v; // internal use radians. + float _v; // internal use radians. + char _wr2[17][4] = { + "N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW", "N"}; + }; diff --git a/libraries/AngleConvertor/CHANGELOG.md b/libraries/AngleConvertor/CHANGELOG.md index fe196292..9146279e 100644 --- a/libraries/AngleConvertor/CHANGELOG.md +++ b/libraries/AngleConvertor/CHANGELOG.md @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.1.1] - 2023-01-23 +- update GitHub actions +- update license 2023 +- update readme +- add windrose() (2x) +- add example + + ## [0.1.0] - 2022-12-01 - initial version diff --git a/libraries/AngleConvertor/LICENSE b/libraries/AngleConvertor/LICENSE index cb502675..7ff52579 100644 --- a/libraries/AngleConvertor/LICENSE +++ b/libraries/AngleConvertor/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022-2022 Rob Tillaart +Copyright (c) 2022-2023 Rob Tillaart Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/libraries/AngleConvertor/README.md b/libraries/AngleConvertor/README.md index 994c902c..6d5f4cf2 100644 --- a/libraries/AngleConvertor/README.md +++ b/libraries/AngleConvertor/README.md @@ -43,7 +43,9 @@ AngleConvertor is an Arduino class to convert an angle from and to less known fo | Turn | 1 | -#### Related to +#### Related + +- https://github.com/RobTillaart/AngleConvertor - https://github.com/RobTillaart/AverageAngle - https://github.com/RobTillaart/Angle - https://github.com/RobTillaart/runningAngle @@ -51,12 +53,17 @@ AngleConvertor is an Arduino class to convert an angle from and to less known fo ## Interface +```cpp +#include "AngleConvertor.h" +``` + + #### Constructor - **AngleConvertor()** create an AngleConvertor, default value is zero. -#### setters +#### Setters - **void setDegrees(float value = 0)** - **void setRadians(float value = 0)** @@ -80,7 +87,7 @@ AngleConvertor is an Arduino class to convert an angle from and to less known fo - **void setTurn(float value = 0)** -#### getters +#### Getters - **float getDegrees()** - **float getRadians()** @@ -103,6 +110,18 @@ AngleConvertor is an Arduino class to convert an angle from and to less known fo - **float getSign()** - **float getTurn()** +#### WindRose + + +From: https://forum.arduino.cc/t/function-optimization-wind-direction-open-for-ideas/92493/10 + +Converts an angle in degrees to a char array like "WSW". +0 and 360 degrees is considered North. + +- **char \* windrose()** converter version. +- **char \* windrose(float degrees)** stand alone version. +degrees should be between 0 and 360, as function does no normalization. + ## Operation @@ -111,16 +130,17 @@ See examples. ## Future -#### must +#### Must + - improve documentation -#### should +#### Should -#### could +#### Could + - add dedicated functions == faster (on request only). - add more conversions - integrate with **Angle class** ? - printing can be a lot of work - diff --git a/libraries/AngleConvertor/examples/AngleConverter_windrose/AngleConverter_windrose.ino b/libraries/AngleConvertor/examples/AngleConverter_windrose/AngleConverter_windrose.ino new file mode 100644 index 00000000..692dcf28 --- /dev/null +++ b/libraries/AngleConvertor/examples/AngleConverter_windrose/AngleConverter_windrose.ino @@ -0,0 +1,55 @@ +// +// FILE: AngleConverter_windrose.ino +// AUTHOR: Rob Tillaart +// PURPOSE: demo sketch to test angleConvertor class +// DATE: 2022-12-01 +// URL: https://github.com/RobTillaart/AngleConvertor +// + + +#include "AngleConvertor.h" + +AngleConvertor conv; + +uint32_t start, stop; + + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + Serial.print("lib version: "); + Serial.println(ANGLECONVERTOR_LIB_VERSION); + Serial.println(); + + + for (int angle = 0; angle <= 360; angle += 5) + { + Serial.print(angle); + Serial.print("\t"); + Serial.print(conv.windrose(angle)); + Serial.println(); + } + Serial.println(); + delay(100); + + start = micros(); + conv.setDegrees(127.876); + char * p = conv.windrose(); + stop = micros(); + + Serial.print("WINDROSE TIME: \t"); + Serial.println(stop - start); + Serial.print("WINDROSE DIR: \t"); + Serial.println(p); + + Serial.println("\nDone..."); +} + + +void loop() +{ +} + + +// -- END OF FILE -- diff --git a/libraries/AngleConvertor/keywords.txt b/libraries/AngleConvertor/keywords.txt index 897c3dc0..015ef7f1 100644 --- a/libraries/AngleConvertor/keywords.txt +++ b/libraries/AngleConvertor/keywords.txt @@ -53,6 +53,10 @@ getSextant KEYWORD2 getSign KEYWORD2 getTurn KEYWORD2 +# Windrose + +windrose KEYWORD2 + # Constants (LITERAL1) ANGLECONVERTOR_LIB_VERSION LITERAL1 diff --git a/libraries/AngleConvertor/library.json b/libraries/AngleConvertor/library.json index 8c21b470..e4c0845b 100644 --- a/libraries/AngleConvertor/library.json +++ b/libraries/AngleConvertor/library.json @@ -1,6 +1,6 @@ { "name": "AngleConvertor", - "keywords": "Angle,convert,degrees,radians", + "keywords": "Angle,convert,degrees,radians,windrose", "description": "Library to convert between different less known angle formats.", "authors": [ @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/AngleConvertor.git" }, - "version": "0.1.0", + "version": "0.1.1", "license": "MIT", "frameworks": "arduino", "platforms": "*", diff --git a/libraries/AngleConvertor/library.properties b/libraries/AngleConvertor/library.properties index 0d6b494d..726f90fc 100644 --- a/libraries/AngleConvertor/library.properties +++ b/libraries/AngleConvertor/library.properties @@ -1,9 +1,9 @@ name=AngleConvertor -version=0.1.0 +version=0.1.1 author=Rob Tillaart maintainer=Rob Tillaart sentence=Library to convert between different less known angle formats. -paragraph= +paragraph=degrees,radians,gradians,windrose category=Data Processing url=https://github.com/RobTillaart/AngleConvertor architectures=* diff --git a/libraries/AngleConvertor/test/unit_test_001.cpp b/libraries/AngleConvertor/test/unit_test_001.cpp index 33fc177f..a7bc97a0 100644 --- a/libraries/AngleConvertor/test/unit_test_001.cpp +++ b/libraries/AngleConvertor/test/unit_test_001.cpp @@ -42,6 +42,7 @@ unittest_setup() fprintf(stderr, "ANGLECONVERTOR_LIB_VERSION: %s\n", (char *) ANGLECONVERTOR_LIB_VERSION); } + unittest_teardown() { } @@ -115,4 +116,6 @@ unittest(test_conversions) unittest_main() + // -- END OF FILE -- +