Skip to content

Commit 4ff96f0

Browse files
committed
0.3.0 weight
1 parent cd94d58 commit 4ff96f0

File tree

10 files changed

+129
-37
lines changed

10 files changed

+129
-37
lines changed

libraries/weight/CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1-
# Change Log tinySHT2x
1+
# Change Log Weight
22

33
All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.3.0] - 2023-08-29
10+
- rename class **weightConvertor** to **weightConverter**
11+
- add **adders** to the weightConverter to add different units of weight.
12+
- update readme.md
13+
- update keywords.txt
14+
- minor edits
15+
16+
----
17+
918
## [0.2.0] - 2022-12-05
1019
- add weightConverter class
1120
- update readme.md
1221
- update unit test
1322

23+
----
1424

1525
## [0.1.4] - 2022-11-26
1626
- Add RP2040 support to build-CI.

libraries/weight/README.md

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
[![Arduino CI](https://github.com/RobTillaart/weight/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
33
[![Arduino-lint](https://github.com/RobTillaart/weight/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/weight/actions/workflows/arduino-lint.yml)
44
[![JSON check](https://github.com/RobTillaart/weight/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/weight/actions/workflows/jsoncheck.yml)
5+
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/weight.svg)](https://github.com/RobTillaart/weight/issues)
6+
57
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/weight/blob/master/LICENSE)
68
[![GitHub release](https://img.shields.io/github/release/RobTillaart/weight.svg?maxAge=3600)](https://github.com/RobTillaart/weight/releases)
9+
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/weight.svg)](https://registry.platformio.org/libraries/robtillaart/weight)
710

811

912
# Weight
1013

11-
Library of weight conversion functions.
14+
Arduino library to convert weight units.
1215

1316

1417
## Description
@@ -18,6 +21,13 @@ Weight.h is a library containing weight conversion functions.
1821
Open for additions, including obscure weight metrics or
1922
weight related math functions and constants.
2023

24+
#### Related
25+
26+
- https://github.com/RobTillaart/AtomicWeight
27+
- https://github.com/RobTillaart/VolumeConverter
28+
- https://github.com/RobTillaart/HX711
29+
- https://github.com/RobTillaart/HX711_MP
30+
2131

2232
## Interface
2333

@@ -68,7 +78,10 @@ New conversions are possible by providing a setXYZ and getXYZ() function.
6878
These two should convert to and from grams respectively.
6979
Additions are welcome, please open an issue.
7080

71-
Internal representation is the gram as it the standard.
81+
Internal representation is the gram as it the ISO standard.
82+
83+
Since version 0.3.0 the converter can also add different units.
84+
7285

7386
## Interface
7487

@@ -77,7 +90,7 @@ Internal representation is the gram as it the standard.
7790

7891
- **weightConverter()**
7992

80-
#### setters
93+
#### Setters
8194

8295
- **void setKilogram(float value = 0)**
8396
- **void setGram(float value = 0)**
@@ -98,8 +111,28 @@ Internal representation is the gram as it the standard.
98111
- **void setGrain(float value = 0)**
99112
- **void setCarat(float value = 0)**
100113

101-
102-
#### getters
114+
#### Adders
115+
116+
- **void addKilogram(float value = 0)**
117+
- **void addGram(float value = 0)**
118+
- **void addLBS(float value = 0)**
119+
- **void addStone(float value = 0)**
120+
- **void addOunce(float value = 0)**
121+
- **void addLongTonUK(float value = 0)**
122+
- **void addShortTonUS(float value = 0)**
123+
- **void addQuarterUK(float value = 0)**
124+
- **void addQuarterUS(float value = 0)**
125+
- **void addSlug(float value = 0)**
126+
- **void addTroyPound(float value = 0)**
127+
- **void addTroyOunce(float value = 0)**
128+
- **void addRobie(float value = 0)**
129+
- **void addDram(float value = 0)**
130+
- **void addDrachme(float value = 0)**
131+
- **void addPoint(float value = 0)**
132+
- **void addGrain(float value = 0)**
133+
- **void addCarat(float value = 0)**
134+
135+
#### Getters
103136

104137
- **float getKilogram()**
105138
- **float getGram()**
@@ -120,32 +153,32 @@ Internal representation is the gram as it the standard.
120153
- **float getGrain()**
121154
- **float getCarat()**
122155

123-
124156
## Future
125157

126-
#### must
158+
#### Must
127159
- improve documentation
128160
- where are units used
129161

130-
#### should
162+
#### Should
131163

132164

133-
#### could
165+
#### Could
134166
- create data types of stone lbs kilo etc.?
135167

136168

137-
#### won't (unless)
169+
#### Won't (unless)
138170
- large masses - sun planets ? (see relativity library)
139171
- gravity constants of planets REL or ABS eg REL_GRAVITY_EARTH 1.0
140-
- mass of all elements
141-
- an array of floats
142-
- a compressed format with access function (1 byte/ element)
143-
- constants e.g. MASS_OXYGEN
144-
- separate periodicTable.h file ?
145172
- molarity functions
146173
- mass of common substances.
147-
- teaspoon
148-
- that is a volume unit.
149-
- volume conversion too?
174+
175+
176+
## Support
177+
178+
If you appreciate my libraries, you can support the development and maintenance.
179+
Improve the quality of the libraries by providing issues and Pull Requests, or
180+
donate through PayPal or GitHub sponsors.
181+
182+
Thank you,
150183

151184

libraries/weight/examples/weightConverter_test/weightConverter_test.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void setup()
1616
Serial.println(__FILE__);
1717
Serial.println();
1818

19-
weightConvertor WC;
19+
weightConverter WC;
2020

2121
WC.setKilogram(1);
2222
Serial.print(WC.getKilogram(), 4);
@@ -118,4 +118,5 @@ void loop()
118118
}
119119

120120

121-
// -- END OF FILE --
121+
// -- END OF FILE --
122+

libraries/weight/examples/weightPerformance/weightPerformance.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,5 @@ void measure_2()
141141
}
142142

143143

144-
// -- END OF FILE --
144+
// -- END OF FILE --
145145

libraries/weight/examples/weightTest/weightTest.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ void loop()
6060
}
6161

6262

63-
// -- END OF FILE --
63+
// -- END OF FILE --
6464

libraries/weight/keywords.txt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Syntax Colouring Map For weight
22

33
# Data types (KEYWORD1)
4-
weightConvertor KEYWORD1
4+
weightConverter KEYWORD1
55

66

77
# Methods and Functions (KEYWORD2)
@@ -44,6 +44,26 @@ setGrain KEYWORD2
4444
setCarat KEYWORD2
4545

4646

47+
addKilogram KEYWORD2
48+
addGram KEYWORD2
49+
addLBS KEYWORD2
50+
addStone KEYWORD2
51+
addOunce KEYWORD2
52+
addLongTonUK KEYWORD2
53+
addShortTonUS KEYWORD2
54+
addQuarterUK KEYWORD2
55+
addQuarterUS KEYWORD2
56+
addSlug KEYWORD2
57+
addTroyPound KEYWORD2
58+
addTroyOunce KEYWORD2
59+
addRobie KEYWORD2
60+
addDram KEYWORD2
61+
addDrachme KEYWORD2
62+
addPoint KEYWORD2
63+
addGrain KEYWORD2
64+
addCarat KEYWORD2
65+
66+
4767
getKilogram KEYWORD2
4868
getGram KEYWORD2
4969
getLBS KEYWORD2

libraries/weight/library.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
"repository":
1414
{
1515
"type": "git",
16-
"url": "https://github.com/RobTillaart/weight"
16+
"url": "https://github.com/RobTillaart/weight.git"
1717
},
18-
"version": "0.2.0",
18+
"version": "0.3.0",
1919
"license": "MIT",
20-
"frameworks": "arduino",
20+
"frameworks": "*",
2121
"platforms": "*",
2222
"headers": "weight.h"
2323
}

libraries/weight/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=weight
2-
version=0.2.0
2+
version=0.3.0
33
author=Rob Tillaart <[email protected]>
44
maintainer=Rob Tillaart <[email protected]>
55
sentence=Library of weight conversion functions

libraries/weight/test/unit_test_001.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ unittest(test_US2metric)
126126
}
127127

128128

129-
unittest(test_weightConvertor)
129+
unittest(test_weightConverter)
130130
{
131-
weightConvertor WC;
131+
weightConverter WC;
132132

133133
fprintf(stderr, "setKilogram\n");
134134
WC.setKilogram(1);
@@ -206,4 +206,6 @@ unittest(test_weightConvertor)
206206

207207
unittest_main()
208208

209-
// --------
209+
210+
// -- END OF FILE --
211+

libraries/weight/weight.h

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22
//
33
// FILE: weight.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.2.0
5+
// VERSION: 0.3.0
66
// PURPOSE: Collection weight conversion functions
77
// URL: https://github.com/RobTillaart/weight
88

99

1010
#include "Arduino.h"
1111

1212

13-
#define WEIGHT_LIB_VERSION (F("0.2.0"))
13+
#define WEIGHT_LIB_VERSION (F("0.3.0"))
1414

1515

16+
/////////////////////////////////////////////////////////////
17+
//
18+
// WEIGHT CONVERSION FUNCTIONS
19+
//
1620
float lbs2kilo(float lbs) { return lbs * 0.45359237; };
1721
float kilo2lbs(float kilos) { return kilos * 2.20462262185; };
1822

@@ -42,7 +46,7 @@ float US2metric(float stone, float lbs, float ounce)
4246
};
4347

4448

45-
// returns lbs;
49+
// returns lbs
4650
float metric2US(float kilo, float &stone, float &lbs, float &ounce)
4751
{
4852
float val = kilo * 2.20462262185;
@@ -59,10 +63,10 @@ float metric2US(float kilo, float &stone, float &lbs, float &ounce)
5963
//
6064
// WEIGHT CONVERTER CLASS
6165
//
62-
class weightConvertor
66+
class weightConverter
6367
{
6468
public:
65-
weightConvertor() { _w = 0; };
69+
weightConverter() { _w = 0; };
6670

6771
// SETTERS
6872
void setKilogram(float value = 0) { _w = value * 1000; };
@@ -84,6 +88,28 @@ class weightConvertor
8488
void setGrain(float value = 0) { _w = value * 0.0647989; };
8589
void setCarat(float value = 0) { _w = value * 0.2; };
8690

91+
92+
// ADDERS
93+
void addKilogram(float value = 0) { _w += value * 1000; };
94+
void addGram(float value = 0) { _w += value; };
95+
void addLBS(float value = 0) { _w += value * 453.59237; };
96+
void addStone(float value = 0) { _w += value * 6350.29318; };
97+
void addOunce(float value = 0) { _w += value * 28.349523125; };
98+
void addLongTonUK(float value = 0) { _w += value * 1016046.9088; };
99+
void addShortTonUS(float value = 0) { _w += value * 907184.74; };
100+
void addQuarterUK(float value = 0) { _w += value * 12700.58636; };
101+
void addQuarterUS(float value = 0) { _w += value * 11339.80925; };
102+
void addSlug(float value = 0) { _w += value * 14593.903; };
103+
void addTroyPound(float value = 0) { _w += value * 373.2417216; };
104+
void addTroyOunce(float value = 0) { _w += value * 31.1034768; };
105+
void addRobie(float value = 0) { _w += value * 10; };
106+
void addDram(float value = 0) { _w += value * 1.77184519531; };
107+
void addDrachme(float value = 0) { _w += value * 3.8; };
108+
void addPoint(float value = 0) { _w += value * 0.002; };
109+
void addGrain(float value = 0) { _w += value * 0.0647989; };
110+
void addCarat(float value = 0) { _w += value * 0.2; };
111+
112+
87113
// GETTERS
88114
float getKilogram() { return _w * 0.001; }
89115
float getGram() { return _w; }
@@ -109,5 +135,5 @@ class weightConvertor
109135
};
110136

111137

112-
// -- END OF FILE --
138+
// -- END OF FILE --
113139

0 commit comments

Comments
 (0)