PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Simple Libraries
Social
libbadgewxtools
ir_rjdec.c
1
#include <stdlib.h>
2
#include <propeller.h>
3
#include "
badgewxtools.h
"
4
5
jm_ir_hdserial
*irself;
6
7
int32_t ircom_rjdec(int32_t val, int32_t width, int32_t pchar)
8
{
9
int32_t tmpval, pad;
10
// Transmit right-justified decimal value
11
// -- val is value to print
12
// -- width is width of (pchar padded) field for value
13
// Original code by Dave Hein
14
// Modified by Jon McPhalen
15
if
(val >= 0) {
16
// if positive
17
// copy value
18
tmpval = val;
19
// make room for 1 digit
20
pad = width - 1;
21
}
else
{
22
if
(val == (int32_t)0x80000000U) {
23
// if max negative
24
// use max positive for width
25
tmpval = 2147483647;
26
}
else
{
27
// else
28
// make positive
29
tmpval = -val;
30
}
31
// make room for sign and 1 digit
32
pad = width - 2;
33
}
34
while
(tmpval >= 10) {
35
// adjust pad for value width > 1
36
(pad--);
37
tmpval = tmpval / 10;
38
}
39
{
40
int32_t _idx__0048;
41
int32_t _limit__0049 = pad;
42
for
(_idx__0048 = 0; _idx__0048 < _limit__0049; _idx__0048++) {
43
// transmit pad
44
ircom_tx(pchar);
45
}
46
}
47
// trasnmit value
48
ircom_dec(val);
49
return
0;
50
}
51
52
/*
53
TERMS OF USE: MIT License
54
55
Permission is hereby granted, free of charge, to any person obtaining a
56
copy of this software and associated documentation files (the "Software"),
57
to deal in the Software without restriction, including without limitation
58
the rights to use, copy, modify, merge, publish, distribute, sublicense,
59
and/or sell copies of the Software, and to permit persons to whom the
60
Software is furnished to do so, subject to the following conditions:
61
62
The above copyright notice and this permission notice shall be included in
63
all copies or substantial portions of the Software.
64
65
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
66
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
67
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
68
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
69
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
70
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
71
DEALINGS IN THE SOFTWARE.
72
*/
73
badgewxtools.h
This library provides convenient functions for a variety of Parallax eBadge operations.
jm_ir_hdserial
Definition:
badgetools.h:1526
Generated on Fri May 20 2022 16:48:05 for PropWare by
1.8.17