diff --git a/libraries/AtomicWeight/.github/FUNDING.yml b/libraries/AtomicWeight/.github/FUNDING.yml index 90d9ab4c..2859c159 100644 --- a/libraries/AtomicWeight/.github/FUNDING.yml +++ b/libraries/AtomicWeight/.github/FUNDING.yml @@ -1,4 +1,5 @@ # These are supported funding model platforms -github: RobTillaart +github: RobTillaart +custom: "https://www.paypal.me/robtillaart" diff --git a/libraries/AtomicWeight/.github/workflows/arduino-lint.yml b/libraries/AtomicWeight/.github/workflows/arduino-lint.yml index 8a26f14a..a7490f1d 100644 --- a/libraries/AtomicWeight/.github/workflows/arduino-lint.yml +++ b/libraries/AtomicWeight/.github/workflows/arduino-lint.yml @@ -1,12 +1,12 @@ - name: Arduino-lint on: [push, pull_request] jobs: lint: runs-on: ubuntu-latest + timeout-minutes: 5 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: arduino/arduino-lint-action@v1 with: library-manager: update diff --git a/libraries/AtomicWeight/.github/workflows/arduino_test_runner.yml b/libraries/AtomicWeight/.github/workflows/arduino_test_runner.yml index fadfa904..dbd0ce79 100644 --- a/libraries/AtomicWeight/.github/workflows/arduino_test_runner.yml +++ b/libraries/AtomicWeight/.github/workflows/arduino_test_runner.yml @@ -1,4 +1,3 @@ ---- name: Arduino CI on: [push, pull_request] @@ -6,9 +5,10 @@ on: [push, pull_request] jobs: runTest: runs-on: ubuntu-latest + timeout-minutes: 20 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: 2.6 diff --git a/libraries/AtomicWeight/.github/workflows/jsoncheck.yml b/libraries/AtomicWeight/.github/workflows/jsoncheck.yml index 37a11298..fd05f5f8 100644 --- a/libraries/AtomicWeight/.github/workflows/jsoncheck.yml +++ b/libraries/AtomicWeight/.github/workflows/jsoncheck.yml @@ -9,10 +9,11 @@ on: jobs: test: runs-on: ubuntu-latest + timeout-minutes: 5 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: json-syntax-check - uses: limitusus/json-syntax-check@v1 + uses: limitusus/json-syntax-check@v2 with: pattern: "\\.json$" diff --git a/libraries/AtomicWeight/AtomicWeight.cpp b/libraries/AtomicWeight/AtomicWeight.cpp index 742648d1..06715cfd 100644 --- a/libraries/AtomicWeight/AtomicWeight.cpp +++ b/libraries/AtomicWeight/AtomicWeight.cpp @@ -2,7 +2,7 @@ // FILE: AtomicWeight.cpp // AUTHOR: Rob Tillaart // DATE: 2022-03-09 -// VERSION: 0.2.1 +// VERSION: 0.2.2 // PURPOSE: Arduino library for atomic weights // URL: https://github.com/RobTillaart/AtomicWeight @@ -28,11 +28,11 @@ uint8_t PTOE::size() } -char * PTOE::name(const uint8_t el) +char * PTOE::name(const uint8_t element) { // catch out of range. - if (el > _size) return NULL; - return elements[el].name; + if (element > _size) return NULL; + return elements[element].name; } @@ -40,34 +40,34 @@ uint8_t PTOE::find(const char * abbrev) { // case insensitive? // caching? - // param check? - // uint8_t len = strlen(abbrev); - // if ((len == 1) || (len == 2)) + // parameter check? + // uint8_t length = strlen(abbrev); + // if ((length == 1) || (length == 2) || (length == 3)) // { for (uint8_t i = 0; i < _size; i++) { if (strcmp(elements[i].name, abbrev) == 0) return i; } // } - return 255; + return 255; // out of range. } -uint8_t PTOE::electrons(const uint8_t el) +uint8_t PTOE::electrons(const uint8_t element) { - return el; + return element; } -uint8_t PTOE::neutrons(const uint8_t el) +uint8_t PTOE::neutrons(const uint8_t element) { - return round(weight(el)) - el; + return round(weight(element)) - element; } -uint8_t PTOE::protons(const uint8_t el) +uint8_t PTOE::protons(const uint8_t element) { - return el; + return element; } @@ -75,10 +75,10 @@ uint8_t PTOE::protons(const uint8_t el) // // WEIGHT // -float PTOE::weight(const uint8_t el) +float PTOE::weight(const uint8_t element) { - if (el > _size) return 0; // catch out of range. - return elements[el].weight * ATOMIC_WEIGHT_FACTOR; + if (element > _size) return 0; // catch out of range. + return elements[element].weight * ATOMIC_WEIGHT_FACTOR; } @@ -147,7 +147,10 @@ uint8_t PTOE::splitElements(const char * formula) // GET ELEMENT := [ Upper | Upper,lower ] elem[0] = 0; elem[1] = 0; - if (! isupper(*p)) return 0; // fail + if (! isupper(*p)) + { + return 0; // fail + } elem[0] = *p; p++; if (islower(*p)) @@ -156,8 +159,8 @@ uint8_t PTOE::splitElements(const char * formula) p++; } // FIND INDEX OF ELEMENT - int z = find(elem); - if (z == 255) + int index = find(elem); + if (index == 255) { return 0; // fail } @@ -166,14 +169,14 @@ uint8_t PTOE::splitElements(const char * formula) bool found = false; for (int i = 0; i < count; i++) { - if (_splitList[i] == z) + if (_splitList[i] == index) { found = true; } } if ((found == false) && (count < ATOMIC_WEIGHT_MAX_SPLIT_LIST)) { - _splitList[count] = z; + _splitList[count] = index; count++; } } @@ -193,10 +196,13 @@ uint8_t PTOE::splitElements(const char * formula) } -uint8_t PTOE::element(uint8_t el) +uint8_t PTOE::element(uint8_t element) { - if (el >= _found) return 255; - return _splitList[el]; + if (element >= _found) + { + return 255; // out of range + } + return _splitList[element]; } @@ -204,19 +210,19 @@ uint8_t PTOE::element(uint8_t el) // // COUNT // -uint32_t PTOE::count(const char * formula, const char * el) +uint32_t PTOE::count(const char * formula, const char * element) { p = (char *)formula; - return _count('\0', el); + return _count('\0', element); } -float PTOE::atomPercentage(const char * formula, const char * el) +float PTOE::atomPercentage(const char * formula, const char * element) { float total = count(formula); if (total == 0) return 0; p = (char *)formula; - return 100.0 * _count('\0', el) / total; + return 100.0 * _count('\0', element) / total; } @@ -234,14 +240,14 @@ float PTOE::weightFactor() // // PRIVATE // -float PTOE::_weight(const char sep, const char * abbrev) +float PTOE::_weight(const char separator, const char * abbrev) { float sum = 0; float w = 0; char elem[3] = { 0, 0, 0 }; uint32_t count = 0; - while (*p != sep) + while (*p != separator) { w = 0; // HANDLE GROUP (...) @@ -266,9 +272,9 @@ float PTOE::_weight(const char sep, const char * abbrev) // can be optimized? if ((abbrev == NULL) || (strcmp(elem, abbrev) == 0)) { - int z = find(elem); - if (z == 255) return 0; // fail - w = weight(z); + int index = find(elem); + if (index == 255) return 0; // fail + w = weight(index); } } @@ -291,14 +297,14 @@ float PTOE::_weight(const char sep, const char * abbrev) } -uint32_t PTOE::_count(const char sep, const char * abbrev) +uint32_t PTOE::_count(const char separator, const char * abbrev) { uint32_t sum = 0; char elem[3] = { 0, 0, 0 }; uint32_t count = 0; int w = 0; - while (*p != sep) + while (*p != separator) { // HANDLE GROUP (...) if (*p == '(') @@ -323,8 +329,8 @@ uint32_t PTOE::_count(const char sep, const char * abbrev) // can be optimized if ((abbrev == NULL) || (strcmp(elem, abbrev) == 0)) { - int z = find(elem); - if (z == 255) return 0; // fail + int index = find(elem); + if (index == 255) return 0; // fail w = 1; } } diff --git a/libraries/AtomicWeight/AtomicWeight.h b/libraries/AtomicWeight/AtomicWeight.h index 218faeef..46b0e58a 100644 --- a/libraries/AtomicWeight/AtomicWeight.h +++ b/libraries/AtomicWeight/AtomicWeight.h @@ -3,7 +3,7 @@ // FILE: AtomicWeight.h // AUTHOR: Rob Tillaart // DATE: 2022-03-09 -// VERSION: 0.2.1 +// VERSION: 0.2.2 // PURPOSE: Arduino library for atomic weights // URL: https://github.com/RobTillaart/AtomicWeight @@ -11,7 +11,7 @@ #include "Arduino.h" -#define ATOMIC_WEIGHT_LIB_VERSION (F("0.2.1")) +#define ATOMIC_WEIGHT_LIB_VERSION (F("0.2.2")) #ifndef ATOMIC_WEIGHT_MAX_SPLIT_LIST @@ -41,18 +41,18 @@ public: // BASIC - char * name(const uint8_t el); + char * name(const uint8_t element); uint8_t find(const char * abbrev); - uint8_t electrons(const uint8_t el); - uint8_t neutrons(const uint8_t el); - uint8_t protons(const uint8_t el); + uint8_t electrons(const uint8_t element); + uint8_t neutrons(const uint8_t element); + uint8_t protons(const uint8_t element); // WEIGHT of one atom - float weight(const uint8_t el); - // if (el != NULL) weights one element in a formula, e.g el == "H" - // if (el == NULL) weights the whole formula + float weight(const uint8_t element); + // if (element != NULL) weights one element in a formula, e.g element == "H" + // if (element == NULL) weights the whole formula float weight(const char * formula, const char * abbrev = NULL); // mass percentage of one element in a formula. float massPercentage(const char * formula, const char * abbrev); @@ -65,15 +65,15 @@ public: // SPLIT FORMULA IN ELEMENTS uint8_t splitElements(const char * formula); - uint8_t element(uint8_t el); + uint8_t element(uint8_t element); // COUNT - // if (el != NULL) count atoms of one element in a formula, e.g el == "H" - // if (el == NULL) count all atoms in the whole formula - uint32_t count(const char * formula, const char * el = NULL); + // if (element != NULL) count atoms of one element in a formula, e.g element == "H" + // if (element == NULL) count all atoms in the whole formula + uint32_t count(const char * formula, const char * element = NULL); // atom percentage of one element in a formula. - float atomPercentage(const char * formula, const char * el); + float atomPercentage(const char * formula, const char * element); // DEBUG @@ -83,9 +83,9 @@ public: private: uint8_t _size; - // if (el == NULL) ==> whole weight otherwise only of element. - float _weight(char sep, const char * abbrev); - uint32_t _count(const char sep, const char * abbrev); + // if (element == NULL) ==> whole weight otherwise only of element. + float _weight(char separator, const char * abbrev); + uint32_t _count(const char separator, const char * abbrev); char *p; // for _weight() and _count() // for splitElements diff --git a/libraries/AtomicWeight/CHANGELOG.md b/libraries/AtomicWeight/CHANGELOG.md index ac4197d3..7cfa4148 100644 --- a/libraries/AtomicWeight/CHANGELOG.md +++ b/libraries/AtomicWeight/CHANGELOG.md @@ -6,10 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.2.2] - 2024-04-07 +- update GitHub actions +- refactor internal names for readability +- minor edits + ## [0.2.1] - 2023-10-17 - update readme.md - ## [0.2.0] - 2023-04-15 - use new weight factor 201.3868 to reduce maximum relative error - create **elements_uint16.h** file. diff --git a/libraries/AtomicWeight/LICENSE b/libraries/AtomicWeight/LICENSE index 7ff52579..3f2859b6 100644 --- a/libraries/AtomicWeight/LICENSE +++ b/libraries/AtomicWeight/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022-2023 Rob Tillaart +Copyright (c) 2022-2024 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/AtomicWeight/README.md b/libraries/AtomicWeight/README.md index 50635f8f..e779e6fa 100644 --- a/libraries/AtomicWeight/README.md +++ b/libraries/AtomicWeight/README.md @@ -262,6 +262,8 @@ minimize the memory used for the elements mass lookup table. - improve documentation - reorganize. +- float => double +- EV is at the end of range float... #### Should @@ -271,7 +273,7 @@ minimize the memory used for the elements mass lookup table. - **uint32_t neutrons(formula)** uses protons() - **uint32_t electrons(formula)** uses protons() - add weight of electron as constant. for completeness. -- functions around **AVOGADRO**, **DALTON** etc +- functions around **AVOGADRO**, **DALTON** etc. - **float weightEV(formula)** - **float dalton2EV(float Dalton)** to express mass in eV. - **float dalton2Joule(float Dalton)** @@ -285,16 +287,18 @@ minimize the memory used for the elements mass lookup table. - look for optimizations - 3x almost same parser - PROGMEM ? -- state table - - liquid, gas, solid, unknown (2 bits per element) = ~30 bytes - - room temperature + sea level pressure - - separate file like elements_name.h - performance **find()** - alphabetical array? tree? - ==> more memory... - support \[] square brackets too. - (NH4)2\[Pt(SCN)6] + + - add a derived class PERIODIC_TABLE? +- state table + - liquid, gas, solid, unknown (2 bits per element) = ~30 bytes + - room temperature + sea level pressure + - separate file like elements_name.h #### Wont (unless) diff --git a/libraries/AtomicWeight/examples/atomic_count_atomPercentage/atomic_count_atomPercentage.ino b/libraries/AtomicWeight/examples/atomic_count_atomPercentage/atomic_count_atomPercentage.ino index 282e2c8d..ce8f8f51 100644 --- a/libraries/AtomicWeight/examples/atomic_count_atomPercentage/atomic_count_atomPercentage.ino +++ b/libraries/AtomicWeight/examples/atomic_count_atomPercentage/atomic_count_atomPercentage.ino @@ -14,9 +14,9 @@ char formula0[24] = "C6H6O6"; char formula1[24] = "((COH)3)2"; char formula2[24] = "H2SO4"; char formula3[24] = "CuO2"; -// char formula4[24] = "(COH)3(COH)2COH"; -// char formula4[24] = "(CH)6O6"; -char formula4[24] = "xH2"; // fails => 0; +char formula4[24] = "(COH)3(COH)2COH"; +char formula5[24] = "(CH)6O6"; +char formula6[24] = "xH2"; // fails => 0; @@ -85,6 +85,14 @@ void setup() Serial.print(" \t H \t"); Serial.println(ptoe.atomPercentage(formula4, "H")); + Serial.print(formula5); + Serial.print(" \t H \t"); + Serial.println(ptoe.atomPercentage(formula5, "O")); + + Serial.print(formula6); + Serial.print(" \t H \t"); + Serial.println(ptoe.atomPercentage(formula6, "H")); + } diff --git a/libraries/AtomicWeight/examples/atomic_count_split/atomic_count_split.ino b/libraries/AtomicWeight/examples/atomic_count_split/atomic_count_split.ino index c096cc91..2a0b3382 100644 --- a/libraries/AtomicWeight/examples/atomic_count_split/atomic_count_split.ino +++ b/libraries/AtomicWeight/examples/atomic_count_split/atomic_count_split.ino @@ -14,7 +14,7 @@ PTOE ptoe; char formula0[24] = "C6H6O6"; // Benzenehexol char formula1[24] = "Al2Si2O5(OH)4"; // kaolin -char formula2[24] = "H2SO4"; // sulpheric acid +char formula2[24] = "H2SO4"; // sulphuric acid char formula3[24] = "CuO2"; // CopperOxide char formula4[24] = "(COH)3(COH)2COH"; // fake // char formula4[24] = "(CH)6O6"; // fake diff --git a/libraries/AtomicWeight/examples/atomic_weight_formula/atomic_weight_formula.ino b/libraries/AtomicWeight/examples/atomic_weight_formula/atomic_weight_formula.ino index 89a88813..503f2ccc 100644 --- a/libraries/AtomicWeight/examples/atomic_weight_formula/atomic_weight_formula.ino +++ b/libraries/AtomicWeight/examples/atomic_weight_formula/atomic_weight_formula.ino @@ -14,9 +14,9 @@ char formula0[24] = "C6H6O6"; char formula1[24] = "((COH)3)2"; char formula2[24] = "H2SO4"; char formula3[24] = "CuO2"; -// char formula4[24] = "(COH)3(COH)2COH"; -// char formula4[24] = "(CH)6O6"; -char formula4[24] = "xH2"; // fails => 0; +char formula4[24] = "(COH)3(COH)2COH"; +char formula5[24] = "(CH)6O6"; +char formula6[24] = "xH2"; // fails => 0; void setup() @@ -62,15 +62,23 @@ void setup() Serial.print(formula4); Serial.print(" \t"); Serial.println(ptoe.weight(formula4)); - + + Serial.print(formula5); + Serial.print(" \t"); + Serial.println(ptoe.weight(formula5)); + + Serial.print(formula6); + Serial.print(" \t"); + Serial.println(ptoe.weight(formula6)); + Serial.print("()"); Serial.print(" \t"); Serial.println(ptoe.weight("()")); - + Serial.print("(H2O)"); Serial.print(" \t"); Serial.println(ptoe.weight("(H2O)")); - + Serial.print("(H2O)255"); Serial.print(" \t"); Serial.println(ptoe.weight("(H2O)255")); diff --git a/libraries/AtomicWeight/examples/atomic_weight_massPercentage/atomic_weight_massPercentage.ino b/libraries/AtomicWeight/examples/atomic_weight_massPercentage/atomic_weight_massPercentage.ino index f38bfa1a..7db6daf8 100644 --- a/libraries/AtomicWeight/examples/atomic_weight_massPercentage/atomic_weight_massPercentage.ino +++ b/libraries/AtomicWeight/examples/atomic_weight_massPercentage/atomic_weight_massPercentage.ino @@ -14,9 +14,9 @@ char formula0[24] = "C6H6O6"; char formula1[24] = "((COH)3)2"; char formula2[24] = "H2SO4"; char formula3[24] = "CuO2"; -// char formula4[24] = "(COH)3(COH)2COH"; -// char formula4[24] = "(CH)6O6"; -char formula4[24] = "xH2"; // fails => 0; +char formula4[24] = "(COH)3(COH)2COH"; +char formula5[24] = "(CH)6O6"; +char formula6[24] = "xH2"; // fails => 0; @@ -69,6 +69,14 @@ void setup() Serial.print(" \t H \t"); Serial.println(ptoe.massPercentage(formula4, "H")); + Serial.print(formula5); + Serial.print(" \t H \t"); + Serial.println(ptoe.massPercentage(formula5, "H")); + + Serial.print(formula6); + Serial.print(" \t H \t"); + Serial.println(ptoe.massPercentage(formula6, "H")); + } diff --git a/libraries/AtomicWeight/examples/atomic_weight_massPercentage/output_0.2.2.txt b/libraries/AtomicWeight/examples/atomic_weight_massPercentage/output_0.2.2.txt new file mode 100644 index 00000000..88bab914 --- /dev/null +++ b/libraries/AtomicWeight/examples/atomic_weight_massPercentage/output_0.2.2.txt @@ -0,0 +1,16 @@ +ATOMIC_WEIGHT_LIB_VERSION: 0.2.2 + +form. elem. perc. + +C C 100.00 +C6 C 100.00 +He6 C 0.00 +NaCl Na 39.34 +NaCl Cl 60.66 +C6H6O6 H 3.47 +((COH)3)2 H 3.47 +H2SO4 H 2.06 +CuO2 H 0.00 +(COH)3(COH)2COH H 3.47 +(CH)6O6 H 3.47 +xH2 H 0.00 diff --git a/libraries/AtomicWeight/examples/atomic_weight_print/.arduino-ci.yml b/libraries/AtomicWeight/examples/atomic_weight_print/.arduino-ci.yml index 25b1f13a..80069fcd 100644 --- a/libraries/AtomicWeight/examples/atomic_weight_print/.arduino-ci.yml +++ b/libraries/AtomicWeight/examples/atomic_weight_print/.arduino-ci.yml @@ -14,9 +14,9 @@ packages: url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json compile: - # Choosing to run compilation tests on 2 different Arduino platforms + # Choosing to run compilation tests on 2 different Arduino platforms platforms: - # - uno + # - uno # memory usage is HIGH for this lib # - due # - zero # - leonardo diff --git a/libraries/AtomicWeight/examples/generate_uint16_table/generate_uint16_table.ino b/libraries/AtomicWeight/examples/generate_uint16_table/generate_uint16_table.ino index 0e82cd53..dccd4f97 100644 --- a/libraries/AtomicWeight/examples/generate_uint16_table/generate_uint16_table.ino +++ b/libraries/AtomicWeight/examples/generate_uint16_table/generate_uint16_table.ino @@ -14,7 +14,7 @@ // 0.1.x 222.909 based op mapping max range 65535 == weight(118) // 0.2.x 201.3868 searched for minimal relative error. -// const float WEIGHT_FACTOR = 222.909; +// const float WEIGHT_FACTOR = 222.909; const float WEIGHT_FACTOR = 201.3868; diff --git a/libraries/AtomicWeight/library.json b/libraries/AtomicWeight/library.json index ca6fb49a..25de37de 100644 --- a/libraries/AtomicWeight/library.json +++ b/libraries/AtomicWeight/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/AtomicWeight.git" }, - "version": "0.2.1", + "version": "0.2.2", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/libraries/AtomicWeight/library.properties b/libraries/AtomicWeight/library.properties index 8f468c7f..f83a0570 100644 --- a/libraries/AtomicWeight/library.properties +++ b/libraries/AtomicWeight/library.properties @@ -1,5 +1,5 @@ name=AtomicWeight -version=0.2.1 +version=0.2.2 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for atomic weights, calculate massPercentage of elements in a formula.