Skip to content

Commit 20e7576

Browse files
committed
0.1.0 VolumeConverter
1 parent 4ff96f0 commit 20e7576

File tree

14 files changed

+620
-0
lines changed

14 files changed

+620
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
platforms:
2+
rpipico:
3+
board: rp2040:rp2040:rpipico
4+
package: rp2040:rp2040
5+
gcc:
6+
features:
7+
defines:
8+
- ARDUINO_ARCH_RP2040
9+
warnings:
10+
flags:
11+
12+
packages:
13+
rp2040:rp2040:
14+
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
15+
16+
compile:
17+
# Choosing to run compilation tests on 2 different Arduino platforms
18+
# selected only those that work
19+
platforms:
20+
- uno
21+
# - due
22+
# - zero
23+
# - leonardo
24+
- m4
25+
- esp32
26+
- esp8266
27+
# - mega2560
28+
- rpipico
29+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# These are supported funding model platforms
2+
3+
github: RobTillaart
4+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
name: Arduino-lint
3+
4+
on: [push, pull_request]
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- uses: arduino/arduino-lint-action@v1
11+
with:
12+
library-manager: update
13+
compliance: strict
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
name: Arduino CI
3+
4+
on: [push, pull_request]
5+
6+
jobs:
7+
runTest:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v3
12+
- uses: ruby/setup-ruby@v1
13+
with:
14+
ruby-version: 2.6
15+
- run: |
16+
gem install arduino_ci
17+
arduino_ci.rb
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: JSON check
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.json'
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: json-syntax-check
15+
uses: limitusus/json-syntax-check@v1
16+
with:
17+
pattern: "\\.json$"
18+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Change Log VolumeConverter
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/).
7+
8+
9+
## [0.1.0] - 2023-08-29
10+
- initial version
11+

libraries/VolumeConverter/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023-2023 Rob Tillaart
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
2+
[![Arduino CI](https://github.com/RobTillaart/VolumeConverter/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
3+
[![Arduino-lint](https://github.com/RobTillaart/VolumeConverter/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/VolumeConverter/actions/workflows/arduino-lint.yml)
4+
[![JSON check](https://github.com/RobTillaart/VolumeConverter/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/VolumeConverter/actions/workflows/jsoncheck.yml)
5+
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/VolumeConverter.svg)](https://github.com/RobTillaart/VolumeConverter/issues)
6+
7+
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/VolumeConverter/blob/master/LICENSE)
8+
[![GitHub release](https://img.shields.io/github/release/RobTillaart/VolumeConverter.svg?maxAge=3600)](https://github.com/RobTillaart/VolumeConverter/releases)
9+
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/VolumeConverter.svg)](https://registry.platformio.org/libraries/robtillaart/VolumeConverter)
10+
11+
12+
# VolumeConverter
13+
14+
Arduino library to convert volume units.
15+
16+
17+
## Description
18+
19+
VolumeConverter is a library containing a VolumeConverter class.
20+
21+
It consists of setters to set a certain volume in one of the
22+
many supported units. Internally it is converted to liters.
23+
Then the user can use a getter to get the volume in one of the
24+
supported units.
25+
26+
Besides conversion the class also allows one to add different
27+
units and convert them.
28+
29+
The purpose of the library is conversion and can be used for
30+
educational programs too.
31+
32+
The library is open for additions, including obscure volume metrics
33+
and volume related math functions and constants.
34+
Also good examples (e.g. educational) are welcome.
35+
36+
37+
#### Accuracy
38+
39+
As the library uses floats the accuracy is limited especially
40+
if one tries to add or convert the extremes of the scales.
41+
E.g. Long tons to teaspoons will loose significant digits.
42+
43+
44+
## Interface
45+
46+
47+
```cpp
48+
#include "VolumeConverter.h"
49+
```
50+
51+
Internal representation is the liter as it the ISO standard.
52+
53+
## Interface
54+
55+
56+
#### Constructor
57+
58+
- **VolumeConverter()** sets the internal value to 0.
59+
60+
#### Setters
61+
62+
- **void setLiters(float value = 0)**
63+
- **void setMilliLiters(float value = 0)**
64+
- **void setCubicMeters(float value = 0)**
65+
- **void setLongTons(float value = 0)**
66+
- **void setShortTons(float value = 0)**
67+
- **void setBarrels(float value = 0)**
68+
- **void setGallons(float value = 0)**
69+
- **void setQuarts(float value = 0)**
70+
- **void setPints(float value = 0)**
71+
- **void setCups(float value = 0)**
72+
- **void setFluidOunces(float value = 0)**
73+
- **void setTableSpoons(float value = 0)**
74+
- **void setTeaSpoons(float value = 0)**
75+
76+
#### Adders
77+
78+
- **void addLiters(float value = 0)**
79+
- **void addMilliLiters(float value = 0)**
80+
- **void addCubicMeters(float value = 0)**
81+
- **void addLongTons(float value = 0)**
82+
- **void addShortTons(float value = 0)**
83+
- **void addBarrels(float value = 0)**
84+
- **void addGallons(float value = 0)**
85+
- **void addQuarts(float value = 0)**
86+
- **void addPints(float value = 0)**
87+
- **void addCups(float value = 0)**
88+
- **void addFluidOunces(float value = 0)**
89+
- **void addTableSpoons(float value = 0)**
90+
- **void addTeaSpoons(float value = 0)**
91+
92+
#### getters
93+
94+
- **float getLiters()**
95+
- **float getMilliLiters()**
96+
- **float getCubicMeters()**
97+
- **float getLongTons()**
98+
- **float getShortTons()**
99+
- **float getBarrels()**
100+
- **float getGallons()**
101+
- **float getQuarts()**
102+
- **float getPints()**
103+
- **float getCups()**
104+
- **float getFluidOunces()**
105+
- **float getTableSpoons()**
106+
- **float getTeaSpoons()**
107+
108+
109+
## Future
110+
111+
#### Must
112+
113+
- improve documentation
114+
115+
#### Should
116+
117+
- consider using double instead of float.
118+
119+
#### Could
120+
121+
- add more unit tests
122+
- add more examples
123+
124+
#### won't (unless)
125+
126+
127+
## Support
128+
129+
If you appreciate my libraries, you can support the development and maintenance.
130+
Improve the quality of the libraries by providing issues and Pull Requests, or
131+
donate through PayPal or GitHub sponsors.
132+
133+
Thank you,
134+
135+
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#pragma once
2+
//
3+
// FILE: VolumeConverter.h
4+
// AUTHOR: Rob Tillaart
5+
// VERSION: 0.1.0
6+
// PURPOSE: Arduino library to convert volume units.
7+
// URL: https://github.com/RobTillaart/VolumeConverter
8+
9+
10+
#include "Arduino.h"
11+
12+
13+
#define VOLUMECONVERTER_LIB_VERSION (F("0.1.0"))
14+
15+
16+
/////////////////////////////////////////////////////////////
17+
//
18+
// VOLUME CONVERTER CLASS
19+
//
20+
class VolumeConverter
21+
{
22+
public:
23+
VolumeConverter() { _v = 0; };
24+
25+
// SETTERS
26+
void setLiters(float value = 0) { _v = value; };
27+
void setMilliLiters(float value = 0) { _v = value * 0.001; };
28+
void setCubicMeters(float value = 0) { _v = value * 1000; };
29+
void setLongTons(float value = 0) { _v = value * 1284.16209; };
30+
void setShortTons(float value = 0) { _v = value * 906.98184; };
31+
void setBarrels(float value = 0) { _v = value * 158.9868; };
32+
void setGallons(float value = 0) { _v = value * 3.7854; };
33+
void setQuarts(float value = 0) { _v = value * 0.94635296; };
34+
void setPints(float value = 0) { _v = value * 0.47317648; };
35+
void setCups(float value = 0) { _v = value * 0.23658824; };
36+
void setFluidOunces(float value = 0) { _v = value * 0.02957353; };
37+
void setTableSpoons(float value = 0) { _v = value * 0.01478677; };
38+
void setTeaSpoons(float value = 0) { _v = value * 0.00492892; };
39+
40+
41+
// ADDERS
42+
void addLiters(float value = 0) { _v += value; };
43+
void addMilliLiters(float value = 0) { _v += value * 0.001; };
44+
void addCubicMeters(float value = 0) { _v += value * 1000; };
45+
void addLongTons(float value = 0) { _v += value * 1284.16209; };
46+
void addShortTons(float value = 0) { _v += value * 906.98184; };
47+
void addBarrels(float value = 0) { _v += value * 158.9868; };
48+
void addGallons(float value = 0) { _v += value * 3.7854; };
49+
void addQuarts(float value = 0) { _v += value * 0.94635296; };
50+
void addPints(float value = 0) { _v += value * 0.47317648; };
51+
void addCups(float value = 0) { _v += value * 0.23658824; };
52+
void addFluidOunces(float value = 0) { _v += value * 0.02957353; };
53+
void addTableSpoons(float value = 0) { _v += value * 0.01478677; };
54+
void addTeaSpoons(float value = 0) { _v += value * 0.00492892; };
55+
56+
57+
// GETTERS
58+
float getLiters() { return _v; };
59+
float getMilliLiters() { return _v * 1000; };
60+
float getCubicMeters() { return _v * 0.001; };
61+
float getLongTons() { return _v * (1.0 / 1284.16209); };
62+
float getShortTons() { return _v * (1.0 / 906.98184); };
63+
float getBarrels() { return _v * (1.0 / 158.9868); };
64+
float getGallons() { return _v * (1.0 / 3.7854); };
65+
float getQuarts() { return _v * (1.0 / 0.94635296); };
66+
float getPints() { return _v * (1.0 / 0.47317648); };
67+
float getCups() { return _v * (1.0 / 0.23658824); };
68+
float getFluidOunces() { return _v * (1.0 / 0.02957353); };
69+
float getTableSpoons() { return _v * (1.0 / 0.01478677); };
70+
float getTeaSpoons() { return _v * (1.0 / 0.00492892); };
71+
72+
73+
private:
74+
float _v; // liters
75+
};
76+
77+
78+
// -- END OF FILE --
79+

0 commit comments

Comments
 (0)