Skip to content

Commit a5789d7

Browse files
Modify implementation to work with new library
- Add a new definition that is necessary for providing the expected functions - Rename _putchar to putchar_()
1 parent 1053d3e commit a5789d7

File tree

6 files changed

+14
-10
lines changed

6 files changed

+14
-10
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Arduino Printf
22

3-
This library adds support for the `printf()` function to Arduino projects. This code leverages the wonderful [mpaland/printf](https://github.com/mpaland/printf) library, which is designed for use in embedded systems. For more information about what is available, please refer to the [parent library documentation](https://github.com/mpaland/printf/blob/master/README.md).
3+
This library adds support for the `printf()` function to Arduino projects. This code leverages the wonderful [eyalroz/printf](https://github.com/mpaland/printf) library, which is designed for use in embedded systems. For more information about what is available, please refer to the [parent library documentation](https://github.com/mpaland/printf/blob/master/README.md).
44

55
## What This Library Provides
66

@@ -96,5 +96,5 @@ Multiple examples are provided with this library in the [examples/](examples/) f
9696
- Any class derived from the `Print` base class can be used with the **Arduino Printf** library
9797
- This example initializes `printf` with `Serial1` instead of `Serial`
9898
* [Override Putchar](examples/override_putchar/override_putchar.ino)
99-
- This example overrides `_putchar()` and adds a space in between every letter
100-
- You can implement any kind of logic within `_putchar()` that you like, such as outputting information to multiple ports
99+
- This example overrides `putchar_()` and adds a space in between every letter
100+
- You can implement any kind of logic within `putchar_()` that you like, such as outputting information to multiple ports

advanced_usage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Advanced Usage
22

3-
You can include `printf.h` directly and supply your own implementation of `_putchar()`. This approach is useful if you want to use the library in a test suite (skipping Arduino SDK headers).
3+
You can include `printf.h` directly and supply your own implementation of `putchar_()`. This approach is useful if you want to use the library in a test suite (skipping Arduino SDK headers).
44

55
### Changing Default Output Target
66

@@ -13,4 +13,4 @@ Serial1.begin(115200);
1313

1414
### More Complicated Output Scenarios
1515

16-
More complicated logic is possible, such as sending `printf()` output to multiple locations. The `mpaland/printf` library requires that the end-user defines a `_putchar()` function, which is used by all other library functions. There is an example script that explains this.
16+
More complicated logic is possible, such as sending `printf()` output to multiple locations. The `mpaland/printf` library requires that the end-user defines a `putchar_()` function, which is used by all other library functions. There is an example script that explains this.

examples/override_putchar/override_putchar.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* This sketch demonstrates the ability to override the ArduinoPrintf library's
3-
* default implementation of _putchar() with a custom user implementation.
4-
* You can do anything you want in your _putchar() function: output to multiple ports,
3+
* default implementation of putchar_() with a custom user implementation.
4+
* You can do anything you want in your putchar_() function: output to multiple ports,
55
* filter data, add extra characters, etc.
66
*/
77

@@ -12,7 +12,7 @@ void setup() {
1212
Serial.begin(115200);
1313
}
1414

15-
void _putchar(char character)
15+
void putchar_(char character)
1616
{
1717
Serial.print(character);
1818
Serial.print(' ');

extras/printf/printf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
#include "printf_config.h"
5050
#endif
5151

52-
#include <printf/printf.h>
52+
#include "printf.h"
5353

5454
#if PRINTF_ALIAS_STANDARD_FUNCTION_NAMES
5555
# define printf_ printf

src/LibPrintf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void printf_init(Print& PrintClass)
2121

2222
// If you use the default printf() implementation, this function will route the output
2323
// to the Serial class
24-
extern "C" __attribute__((weak)) void _putchar(char character)
24+
extern "C" __attribute__((weak)) void putchar_(char character)
2525
{
2626
print_instance->print(character);
2727
}

src/LibPrintf.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
#define ARDUINO_PRINTF_H_
33

44
#include "Print.h"
5+
#define PRINTF_ALIAS_STANDARD_FUNCTION_NAMES 1
56
#include "../extras/printf/printf.h"
67

8+
// Adds a compatibility definition for those who were using the old library
9+
#define _putchar(c) putchar_(c)
10+
711
// In Setup(), you must initialize printf with a Print class if you don't want
812
// to use the default Serial object. If you want the default behavior, calling this
913
// function is not necessary.

0 commit comments

Comments
 (0)