Skip to content

Commit cb92c89

Browse files
committed
Added examples and info
1 parent e513b83 commit cb92c89

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

README.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,57 @@
1-
ByteConvert
1+
# ByteConvert
2+
[![Build Status](https://travis-ci.org/SloCompTech/ByteConvert_arduino.svg?branch=master)](https://travis-ci.org/SloCompTech/ByteConvert_arduino)
3+
[![Packagist](https://img.shields.io/packagist/l/doctrine/orm.svg)]()
4+
5+
## What's about ?
6+
Have you ever wanted to transmit `int`,`short`,`long`,`double` or any other numeric type over I2C,SPI,serial or other protocol or bus, but you converted variable to string to be able to transmit it char by char. This library enables you to convert any numeric value to bytes or other way around and you can also print array of bytes.
7+
8+
## What you need to consider, when you are using this library
9+
When you are using this library, you need to consider variable byte size, because if you are using different platform, then there may be some errors, because int on platform 1 has 4 bytes and int on platform 2 has 2 bytes.
10+
11+
## Examples
12+
Convert numeric variable for eg. `int`,`short`,`float`,`double` to array of bytes.
13+
``` c++
14+
int somevar = 5;
15+
size_t blk_size = 0;
16+
uint8_t *block = ByteConvert::varToArray<int>(blk_size,somevar);
17+
18+
// Use array
19+
20+
delete block; // Don't forget to free memory, when you don't need array any more
21+
```
22+
23+
Convert array of bytes to numeric variable.
24+
``` c++
25+
uint8_t *block; // Predefined byte array with size of int
26+
int somevar = ByteConvert::arrayToVar<int>(block);
27+
28+
// Use block & somevar
29+
30+
delete block; // Don't forget to free memory, when you don't need array any more
31+
32+
// Use somevar
33+
```
34+
35+
Convert array of bytes to string of hex characters
36+
``` c++
37+
size_t blk_size; // Predefined size of byte array
38+
uint8_t *block; // Predefined byte array with size of int
39+
String somevar = ByteConvert::arrayToString(blk_size,block);
40+
41+
// Use block & somevar
42+
43+
delete block; // Don't forget to free memory, when you don't need array any more
44+
45+
// Use somevar
46+
```
47+
48+
Convert string of hex characters to array of bytes
49+
``` c++
50+
String somevar = ""; // Predefined string
51+
size_t blk_size = 0;
52+
uint8_t *block ByteConvert::stringToArray(blk_size,somevar);
53+
54+
// Use block
55+
56+
delete block; // Don't forget to free memory, when you don't need array any more
57+
```

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ByteConvert
2-
version=0.0.1
2+
version=0.1.0
33
author=Martin Dagarin
44
maintainer=Martin Dagarin <SloCompTech@gmail.com>
55
sentence=Library for converting variables to bytes and reverse

0 commit comments

Comments
 (0)