Skip to content

Commit cc7e03d

Browse files
committed
update libs
1 parent f9cf7e8 commit cc7e03d

File tree

32 files changed

+1001
-71
lines changed

32 files changed

+1001
-71
lines changed

libraries/Angle/Warning.txt

Lines changed: 0 additions & 10 deletions
This file was deleted.

libraries/Cozir/test/unit_test_001.cpp

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,33 @@
33
// AUTHOR: Rob Tillaart
44
// DATE: 2020-12-03
55
// PURPOSE: unit tests for the Cozir CO2 library
6-
// https://github.com/RobTillaart/
6+
// https://github.com/RobTillaart/Cozir
77
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
88
//
99

1010
// supported assertions
1111
// https://github.com/Arduino-CI/arduino_ci/blob/master/cpp/unittest/Assertion.h#L33-L42
1212
// ----------------------------
13-
// assertEqual(expected, actual)
14-
// assertNotEqual(expected, actual)
15-
// assertLess(expected, actual)
16-
// assertMore(expected, actual)
17-
// assertLessOrEqual(expected, actual)
18-
// assertMoreOrEqual(expected, actual)
19-
// assertTrue(actual)
20-
// assertFalse(actual)
21-
// assertNull(actual)
22-
// assertNotNull(actual)
13+
// assertEqual(expected, actual); // a == b
14+
// assertNotEqual(unwanted, actual); // a != b
15+
// assertComparativeEquivalent(expected, actual); // abs(a - b) == 0 or (!(a > b) && !(a < b))
16+
// assertComparativeNotEquivalent(unwanted, actual); // abs(a - b) > 0 or ((a > b) || (a < b))
17+
// assertLess(upperBound, actual); // a < b
18+
// assertMore(lowerBound, actual); // a > b
19+
// assertLessOrEqual(upperBound, actual); // a <= b
20+
// assertMoreOrEqual(lowerBound, actual); // a >= b
21+
// assertTrue(actual);
22+
// assertFalse(actual);
23+
// assertNull(actual);
24+
25+
// // special cases for floats
26+
// assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon
27+
// assertNotEqualFloat(unwanted, actual, epsilon); // fabs(a - b) >= epsilon
28+
// assertInfinity(actual); // isinf(a)
29+
// assertNotInfinity(actual); // !isinf(a)
30+
// assertNAN(arg); // isnan(a)
31+
// assertNotNAN(arg); // !isnan(a)
32+
2333

2434
#include <ArduinoUnitTests.h>
2535

@@ -60,6 +70,7 @@ unittest(test_software_serial)
6070
assertEqual("K 2\r\n", state->digitalPin[transmitPin].toAscii(1, bigEndian));
6171
}
6272

73+
6374
unittest(test_constructor)
6475
{
6576
GodmodeState* state = GODMODE();
@@ -269,6 +280,18 @@ unittest(test_streaming_mode)
269280
co.SetOutputFields(CZR_HUMIDITY | CZR_RAWTEMP | CZR_RAWCO2);
270281
assertEqual("M 4226\r\n", state->serialPort[0].dataOut);
271282

283+
fprintf(stderr, "COZIR.GetRecentFields()\n");
284+
state->serialPort[0].dataIn = "";
285+
state->serialPort[0].dataOut = "";
286+
co.GetRecentFields();
287+
assertEqual("Q\r\n", state->serialPort[0].dataOut);
288+
289+
fprintf(stderr, "COZIR.ClrOutputFields()\n");
290+
state->serialPort[0].dataIn = "";
291+
state->serialPort[0].dataOut = "";
292+
co.ClrOutputFields();
293+
assertEqual("M 1\r\n", state->serialPort[0].dataOut);
294+
272295
fprintf(stderr, "COZIR.GetRecentFields()\n");
273296
state->serialPort[0].dataIn = "";
274297
state->serialPort[0].dataOut = "";
@@ -306,6 +329,27 @@ unittest(test_eeprom)
306329

307330

308331

332+
unittest(test_PPM)
333+
{
334+
GodmodeState* state = GODMODE();
335+
336+
COZIR co(&Serial);
337+
338+
fprintf(stderr, "COZIR.init()\n");
339+
state->serialPort[0].dataIn = "";
340+
state->serialPort[0].dataOut = "";
341+
co.init();
342+
assertEqual("K 2\r\n", state->serialPort[0].dataOut);
343+
344+
fprintf(stderr, "COZIR.getPPMFactor()\n");
345+
state->serialPort[0].dataIn = "";
346+
state->serialPort[0].dataOut = "";
347+
co.getPPMFactor();
348+
assertEqual(".\r\n", state->serialPort[0].dataOut);
349+
}
350+
351+
352+
309353
unittest_main()
310354

311355
// --------

libraries/Currency/.arduino-ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
compile:
2+
# Choosing to run compilation tests on 2 different Arduino platforms
3+
platforms:
4+
- uno
5+
- leonardo
6+
- due
7+
- zero
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
name: Arduino CI
3+
4+
on: [push, pull_request]
5+
6+
jobs:
7+
arduino_ci:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v2
12+
- uses: Arduino-CI/action@master
13+
# Arduino-CI/[email protected]

libraries/Currency/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) 2021-2021 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.

libraries/Currency/README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
2+
[![Arduino CI](https://github.com/RobTillaart/currency/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
3+
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/currency/blob/master/LICENSE)
4+
[![GitHub release](https://img.shields.io/github/release/RobTillaart/currency.svg?maxAge=3600)](https://github.com/RobTillaart/currency/releases)
5+
6+
7+
8+
# Currency
9+
10+
Arduino library to help formatting integers for printing as currency
11+
12+
## Warning: experimental
13+
14+
15+
## Description
16+
17+
The currency library contains a number of functions that help to print
18+
integers as currency.
19+
20+
The currency functions assume you do the currency math in integer units.
21+
For dollars and euro's this would be cents. For numbers with more decimals
22+
it is a smaller unit.
23+
24+
Using integers makes addition, subtraction and multiplication exact.
25+
26+
Choosing int32_t as 'base' also means that there is a limit in terms
27+
of minimum and maximum values. When large amounts are needed one can
28+
use the currency64() or one of its derived formatters as this is based
29+
upon int64_t numbers.
30+
31+
There is a relation with the printhelpers class - https://github.com/RobTillaart/printHelpers
32+
When this library has matured it might be merged with it.
33+
34+
35+
## Interface
36+
37+
The following functions are implemented:
38+
39+
40+
### Core function
41+
42+
- **char \* currency(int32_t value, uint8_t decimals, char decimalseparator, char thousandseparator, char symbol);**
43+
- **char \* currency64(int64_t value, uint8_t decimals, char decimalseparator, char thousandseparator, char symbol);**
44+
45+
46+
### int32 Wrapper functions
47+
48+
- **char \* bitcoin(int32_t value)**
49+
- **char \* dollar(int32_t value)**
50+
- **char \* euro(int32_t value)**
51+
- **char \* roebel(int32_t value)**
52+
- **char \* yen(int32_t value)**
53+
- **char \* yuan(int32_t value)**
54+
55+
56+
### int64 Wrapper functions
57+
58+
- **char \* bitcoin64(int64_t value)**
59+
- **char \* dollar64(int64_t value)**
60+
- **char \* euro64(int64_t value)**
61+
- **char \* roebel64(int64_t value)**
62+
- **char \* yen64(int64_t value)**
63+
- **char \* yuan64(int64_t value)**
64+
65+
66+
### float Wrapper functions
67+
68+
Even more experimental - not tested
69+
70+
- **char \* bitcoinf(double value)**
71+
- **char \* dollarf(double value)**
72+
- **char \* eurof(double value)**
73+
- **char \* roebelf(double value)**
74+
- **char \* yenf(double value)**
75+
- **char \* yuanf(double value)**
76+
77+
78+
## Future
79+
80+
- More wrapper functions?
81+
- test double parameters.
82+
83+
84+
## Operation
85+
86+
See examples
87+

libraries/Currency/currency.h

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#pragma once
2+
3+
//
4+
// FILE: currency.h
5+
// AUTHOR: Rob Tillaart
6+
// VERSION: 0.1.0
7+
// PURPOSE: Currency library for Arduino
8+
// URL: https://github.com/RobTillaart/Currency
9+
10+
// HISTORY
11+
// 0.1.0 2021-02-27 initial version
12+
13+
14+
#include "Arduino.h"
15+
16+
17+
#define CURRENCY_VERSION (F("0.1.0"))
18+
19+
20+
// TODO
21+
// optimize this 99% same code currency - currency64
22+
// print to string and "merge" with formatters?
23+
//
24+
// ALT-0165 = ¥
25+
// ALT-0128 = €
26+
// U+20BF = Bitcoin
27+
28+
29+
char * currency(int32_t value, int decimals, char dsep, char tsep, char sym)
30+
{
31+
static char tmp[16];
32+
int idx = 0;
33+
34+
int32_t v = value;
35+
bool neg = v < 0;
36+
if (neg) v = -v;
37+
38+
int p = -decimals; // decimal places
39+
40+
while ((p < 1) || ( v > 0))
41+
{
42+
// separators
43+
if ((p == 0) && (decimals > 0) ) tmp[idx++] = dsep;
44+
if ((p > 0) && (p % 3 == 0) && (v > 0)) tmp[idx++] = tsep;
45+
46+
int d = (v % 10) + '0';
47+
v /= 10;
48+
tmp[idx++] = d;
49+
p++;
50+
}
51+
if (neg) tmp[idx++] = '-';
52+
else tmp[idx++] = ' ';
53+
tmp[idx++] = sym;
54+
tmp[idx] = 0;
55+
56+
// reverse string
57+
int len = strlen(tmp);
58+
for (int i = 0; i < len / 2; i++)
59+
{
60+
char c = tmp[i];
61+
tmp[i] = tmp[len - i - 1];
62+
tmp[len - i - 1] = c;
63+
}
64+
return tmp;
65+
}
66+
67+
68+
char * currency64(int64_t value, int decimals, char dsep, char tsep, char sym)
69+
{
70+
static char tmp[32];
71+
int idx = 0;
72+
73+
int64_t v = value;
74+
bool neg = v < 0;
75+
if (neg) v = -v;
76+
77+
int p = -decimals; // decimal places
78+
79+
while ((p < 1) || ( v > 0))
80+
{
81+
// separators
82+
if ((p == 0) && (decimals > 0) ) tmp[idx++] = dsep;
83+
if ((p > 0) && (p % 3 == 0) && (v > 0)) tmp[idx++] = tsep;
84+
85+
int d = (v % 10) + '0';
86+
v /= 10;
87+
tmp[idx++] = d;
88+
p++;
89+
}
90+
if (neg) tmp[idx++] = '-';
91+
else tmp[idx++] = ' ';
92+
tmp[idx++] = sym;
93+
tmp[idx] = 0;
94+
95+
// reverse string
96+
int len = strlen(tmp);
97+
for (int i = 0; i < len / 2; i++)
98+
{
99+
char c = tmp[i];
100+
tmp[i] = tmp[len - i - 1];
101+
tmp[len - i - 1] = c;
102+
}
103+
return tmp;
104+
}
105+
106+
107+
//
108+
// DERIVED FUNCTIONS
109+
//
110+
char * bitcoin(int32_t value) { return currency(value, 6, '.', ',', 'B'); }
111+
char * dollar(int32_t value) { return currency(value, 2, '.', ',', '$'); }
112+
char * euro(int32_t value) { return currency(value, 2, ',', '.', 'E'); }
113+
char * roebel(int32_t value) { return currency(value, 2, ',', '.', 'P'); }
114+
char * yen(int32_t value) { return currency(value, 2, '.', ',', 'Y'); }
115+
char * yuan(int32_t value) { return currency(value, 2, '.', ',', 'R'); }
116+
117+
char * bitcoin64(int64_t value) { return currency64(value, 6, '.', ',', 'B'); }
118+
char * dollar64(int64_t value) { return currency64(value, 2, '.', ',', '$'); }
119+
char * euro64(int64_t value) { return currency64(value, 2, ',', '.', 'E'); }
120+
char * roebel64(int64_t value) { return currency64(value, 2, ',', '.', 'P'); }
121+
char * yen64(int64_t value) { return currency64(value, 2, '.', ',', 'Y'); }
122+
char * yuan64(int64_t value) { return currency64(value, 2, '.', ',', 'R'); }
123+
124+
char * bitcoinf(double value) { return currency64(round(value * 1000000), 6, '.', ',', 'B'); }
125+
char * dollarf(double value) { return currency64(round(value * 100), 2, '.', ',', '$'); }
126+
char * eurof(double value) { return currency64(round(value * 100), 2, ',', '.', 'E'); }
127+
char * roebelf(double value) { return currency64(round(value * 100), 2, ',', '.', 'P'); }
128+
char * yenf(double value) { return currency64(round(value * 100), 2, '.', ',', 'Y'); }
129+
char * yuanf(double value) { return currency64(round(value * 100), 2, '.', ',', 'R'); }
130+
131+
132+
// -- END OF FILE --

0 commit comments

Comments
 (0)