Skip to content

Commit f7c09fa

Browse files
authored
Merge pull request #39 from bxparks/develop
merge v1.0.0 into master
2 parents 03b7d9b + b887097 commit f7c09fa

File tree

19 files changed

+493
-86
lines changed

19 files changed

+493
-86
lines changed

.github/workflows/aunit_tests.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,11 @@ jobs:
2626
2727
- name: Verify tests
2828
run: |
29+
# tests/IPAddressTest requires EPOXY_CORE_ESP8266, which requires clean
30+
make -C tests clean
31+
make -C tests tests
32+
make -C tests runtests
33+
# clean after tests/IPAddressTest to revert to EPOXY_CORE_AVR
34+
make -C libraries clean
2935
make -C libraries tests
3036
make -C libraries runtests

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
# Changelog
22

33
* Unreleased
4+
* 1.0 (2021-09-30)
5+
* Add `epoxy_argc` and `epoxy_argv` as extern global variables which
6+
are set to the `argc` and `argv` parameters passed into the global
7+
`main()`.
8+
* Allows command line arguments to be passed into an Arduino
9+
application, to facilitate debugging on a Unix desktop machine.
10+
* Add `examples/CommandLine` which provides a basic command line parser
11+
that can be copied and modified for other applications.
12+
* Add `toString()` to `IPAddress` class, activated with `EPOXY_CORE_ESP8266`
13+
for compatibility with ESP8266 Core.
14+
* Add `strstr_P()` to `pgmspace.h`.
15+
* Finally fix [Issue #2](https://github.com/bxparks/EpoxyDuino/issues/2) and
16+
[Issue #25](https://github.com/bxparks/EpoxyDuino/issues/25).
417
* 0.8 (2021-08-08)
518
* Add `EpoxyMockTimerOne` mock library for `TimerOne`
619
(https://github.com/PaulStoffregen/TimerOne).

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
# Users of this library will use 'EpoxyDuino.mk' instead.
33

44
all:
5+
$(MAKE) -C tests
56
$(MAKE) -C libraries
67
$(MAKE) -C examples
78

9+
runtests:
10+
$(MAKE) -C tests runtests
11+
$(MAKE) -C libraries runtests
12+
813
clean:
14+
$(MAKE) -C tests clean
915
$(MAKE) -C libraries clean
1016
$(MAKE) -C examples clean

README.md

Lines changed: 63 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
[![AUnit Tests](https://github.com/bxparks/EpoxyDuino/actions/workflows/aunit_tests.yml/badge.svg)](https://github.com/bxparks/EpoxyDuino/actions/workflows/aunit_tests.yml)
44

5-
**New**: [GitHub Discussions](https://github.com/bxparks/EpoxyDuino/discussions)
6-
for this project is now active! Let's use that for general support questions,
7-
and reserve the [GitHub Issues](https://github.com/bxparks/EpoxyDuino/issues)
8-
section for bugs and feature requests.
9-
105
This project contains a small (but often effective) implementation of the
116
Arduino programming framework for Linux, MacOS, FreeBSD (experimental) and
127
potentially other POSIX-like systems. Originally, it was created to allow
@@ -60,16 +55,10 @@ The disadvantages are:
6055
environments (e.g. 16-bit `int` versus 32-bit `int`, or 32-bit `long` versus
6156
64-bit `long`).
6257

63-
**Version**: 0.8 (2021-08-08)
58+
**Version**: 1.0 (2021-09-30)
6459

6560
**Changelog**: See [CHANGELOG.md](CHANGELOG.md)
6661

67-
**Breaking Change**: Prior to v0.5, this project was known as "UnixHostDuino".
68-
The old `UNIX_HOST_DUINO` macro and `UnixHostDuino.mk` include file still exist
69-
for backwards compatibility. See
70-
[Issue #15](https://github.com/bxparks/EpoxyDuino/issues/15)
71-
for more details.
72-
7362
## Table of Contents
7463

7564
* [Installation](#Installation)
@@ -87,6 +76,7 @@ for more details.
8776
* [Additional Clean Up](#AdditionalCleanUp)
8877
* [Alternate Arduino Core](#AlternateArduinoCore)
8978
* [PlatformIO](#PlatformIO)
79+
* [Command Line Flags and Arguments](#CommandLineFlagsAndArguments)
9080
* [Supported Arduino Features](#SupportedArduinoFeatures)
9181
* [Arduino Functions](#ArduinoFunctions)
9282
* [Serial Port Emulation](#SerialPortEmulation)
@@ -320,9 +310,9 @@ FooLibrary
320310
|-- library.properties
321311
|-- src
322312
| |-- FooLibrary.h
323-
| |-- foolib
324-
| | |-- file.h
325-
| | `-- file.cpp
313+
| `-- foolib
314+
| |-- file.h
315+
| `-- file.cpp
326316
`-- tests
327317
|-- AxxTest
328318
| |-- AxxTest.ino
@@ -513,8 +503,12 @@ Core. EpoxyDuino provides the ability substitute a different Arduino API Core
513503
through 2 Makefile variables:
514504

515505
* `EPOXY_CORE`
516-
* This Makefile variable defines the C-preprocessor macro which will be
517-
defined through the `-D` flag through `-D $(EPOXY_CORE)`.
506+
* `EPOXY_CORE_PATH`
507+
508+
#### `EPOXY_CORE`
509+
510+
The `EPOXY_CORE` Makefile variable defines the C-preprocessor macro which will
511+
be defined through the `-D` flag through `-D $(EPOXY_CORE)`.
518512

519513
There are currently 2 valid options for this Makefile variable:
520514

@@ -538,12 +532,12 @@ compiler, which will activate any code that is guarded by:
538532
#endif
539533
```
540534

535+
#### `EPOXY_CORE_PATH`
536+
541537
If the `EPOXY_CORE` make variable is insufficient (e.g. because the appropriate
542538
changes have not been incorporated into `$(EPOXY_DUINO_DIR)/cores/epoxy/`), then
543-
there is an even bigger hammer with the following make variable:
544-
545-
* `EPOXY_CORE_PATH`
546-
* Defines the full-path to the Arduino Core API files.
539+
the `EPOXY_CORE_PATH` provides an even bigger hammer. It defines the the
540+
full-path to the Arduino Core API files.
547541

548542
By default, this is set to `$(EPOXY_DUINO_DIR)/cores/epoxy`. You can create your
549543
own set of Arduino API files in a directory of your choosing, and set this
@@ -562,6 +556,50 @@ in [Issue #31](https://github.com/bxparks/EpoxyDuino/pull/31) (thanks
562556
https://github.com/lopsided98). However, this functionality is *unsupported*. If
563557
it becomes broken in the future, please send me a PR to fix it.
564558

559+
<a name="CommandLineFlagsAndArguments"></a>
560+
### Command Line Flags and Arguments
561+
562+
The standard Arduino environment does not provide command line arguments, since
563+
a microcontroller does not normally provide a command line environment.
564+
When an Arduino application is compiled Using EpoxyDuino, the Unix command line
565+
parameters (`argc` and `argv`) become available through 2 global variables:
566+
567+
* `extern int epoxy_argc`
568+
* `extern const char* const* epoxy_argv`
569+
570+
The [examples/CommandLine](examples/CommandLine) program contains a basic
571+
command line parser which can be copied and customized for different
572+
applications:
573+
574+
```
575+
$ ./CommandLine.out --help
576+
Usage: ./CommandLine.out [--help|-h] [-s] [--include word] [--] [words ...]
577+
578+
$ ./CommandLine.out one two
579+
arg: one
580+
arg: two
581+
582+
$ ./CommandLine.out -s
583+
flag: -s
584+
585+
$ ./CommandLine.out --include inc one two
586+
flag: --include inc
587+
arg: one
588+
arg: two
589+
590+
$ ./CommandLine.out --include inc -- -one two
591+
flag: --include inc
592+
arg: -one
593+
arg: two
594+
595+
$ ./CommandLine.out -a
596+
Unknonwn flag '-a'
597+
Usage: ./CommandLine.out [--help|-h] [-s] [--include word] [--] [words ...]
598+
```
599+
600+
A more advanced example can be seen in
601+
[AUnit/TestRunner.cpp](https://github.com/bxparks/AUnit/blob/develop/src/aunit/TestRunner.cpp).
602+
565603
<a name="SupportedArduinoFeatures"></a>
566604
## Supported Arduino Features
567605

@@ -595,7 +633,7 @@ The following functions and features of the Arduino framework are implemented:
595633
* `pgm_read_byte()`, `pgm_read_word()`, `pgm_read_dword()`,
596634
`pgm_read_float()`, `pgm_read_ptr()`
597635
* `strlen_P()`, `strcat_P()`, `strcpy_P()`, `strncpy_P()`, `strcmp_P()`,
598-
`strncmp_P()`, `strcasecmp_P()`, `strchr_P()`, `strrchr_P()`
636+
`strncmp_P()`, `strcasecmp_P()`, `strchr_P()`, `strrchr_P()`, `strstr_P()`
599637
* `memcpy_P()`, `vsnprintf_P()`
600638
* `PROGMEM`, `PGM_P`, `PGM_VOID_P`, `PSTR()`
601639
* `IPAddress.h`
@@ -606,7 +644,8 @@ The following functions and features of the Arduino framework are implemented:
606644
* `Wire.h` (stub implementation)
607645
* `SPI.h` (stub implementation)
608646

609-
See [Arduino.h](https://github.com/bxparks/EpoxyDuino/blob/develop/Arduino.h)
647+
See
648+
[Arduino.h](https://github.com/bxparks/EpoxyDuino/blob/develop/cores/epoxy/Arduino.h)
610649
for the latest list. Most of the header files included by this `Arduino.h`
611650
file were copied and modified from the [arduino:avr
612651
core](https://github.com/arduino/ArduinoCore-avr/tree/master/cores/arduino),
@@ -809,19 +848,7 @@ This library has been tested on:
809848
<a name="Bugs"></a>
810849
## Bugs and Limitations
811850

812-
If the executable (e.g. `SampleTest.out`) is piped to the `less(1)` or `more(1)`
813-
command, sometimes (not all the time) the executable hangs and displays nothing
814-
on the pager program. I don't know why, it probably has to do with the way that
815-
the `less` or `more` programs manipulate the `stdin`. The solution is to
816-
explicitly redirect the `stdin`:
817-
818-
```
819-
$ ./SampleTest.out | grep failed # works
820-
821-
$ ./SampleTest.out | less # hangs
822-
823-
$ ./SampleTest.out < /dev/null | less # works
824-
```
851+
None that I am aware of.
825852

826853
<a name="FeedbackAndSupport"></a>
827854
## Feedback and Support

cores/epoxy/Arduino.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#define EPOXY_DUINO_EPOXY_ARDUINO_H
1515

1616
// xx.yy.zz => xxyyzz (without leading 0)
17-
#define EPOXY_DUINO_VERSION 800
18-
#define EPOXY_DUINO_VERSION_STRING "0.8.0"
17+
#define EPOXY_DUINO_VERSION 10000
18+
#define EPOXY_DUINO_VERSION_STRING "1.0.0"
1919

2020
#include <stdlib.h>
2121
#include <stdint.h>
@@ -28,6 +28,9 @@
2828
#include "WCharacter.h"
2929
#include "Print.h"
3030
#include "StdioSerial.h"
31+
#if defined(EPOXY_CORE_ESP8266)
32+
#include "Esp.h"
33+
#endif
3134

3235
// Used by digitalRead() and digitalWrite()
3336
#define HIGH 0x1
@@ -213,6 +216,12 @@ int unixhostduino_main(int argc, char** argv);
213216
/** Calls unixhostduino_main() unless overriden by user */
214217
int main(int argc, char** argv);
215218

219+
/** Copy of the argc parameter of main() as a global variable. */
220+
extern int epoxy_argc;
221+
222+
/** Copy of the argv parameter of main() as a global variable. */
223+
extern const char* const* epoxy_argv;
224+
216225
}
217226

218227
// WMath prototypes

cores/epoxy/Esp.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,8 @@
33

44
#if defined(EPOXY_CORE_ESP8266)
55

6-
#include <Arduino.h>
7-
#include <Stream.h>
86
#include <sys/time.h>
9-
10-
class _FLOAT
11-
{
12-
public:
13-
int digits;
14-
float val;
15-
};
7+
#include "Stream.h"
168

179
class EspClass
1810
{

cores/epoxy/IPAddress.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,23 @@ size_t IPAddress::printTo(Print& p) const
114114
n += p.print(_address.bytes[3], DEC);
115115
return n;
116116
}
117+
118+
#if defined(EPOXY_CORE_ESP8266)
119+
String IPAddress::toString() const
120+
{
121+
String s;
122+
s.reserve(16);
123+
124+
s.concat(_address.bytes[0]);
125+
s.concat('.');
126+
s.concat(_address.bytes[1]);
127+
s.concat('.');
128+
s.concat(_address.bytes[2]);
129+
s.concat('.');
130+
s.concat(_address.bytes[3]);
131+
132+
return s;
133+
}
134+
#endif
135+
136+
const IPAddress INADDR_NONE(0,0,0,0);

cores/epoxy/IPAddress.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
Copied from Arduino AVR core 1.8.3 by Erik Tideman. Removed
66
unnecessary 'friend' declarations.
77
8+
Merged selected features from ESP8266 Core 2.7.4 by Brian T. Park.
9+
810
This library is free software; you can redistribute it and/or
911
modify it under the terms of the GNU Lesser General Public
1012
License as published by the Free Software Foundation; either
@@ -32,8 +34,8 @@
3234
class IPAddress : public Printable {
3335
private:
3436
union {
35-
uint8_t bytes[4]; // IPv4 address
36-
uint32_t dword;
37+
uint8_t bytes[4]; // IPv4 address
38+
uint32_t dword;
3739
} _address;
3840

3941
// Access the raw byte array containing the address. Because this returns a pointer
@@ -67,8 +69,12 @@ class IPAddress : public Printable {
6769
IPAddress& operator=(uint32_t address);
6870

6971
virtual size_t printTo(Print& p) const;
72+
73+
#if defined(EPOXY_CORE_ESP8266)
74+
String toString() const;
75+
#endif
7076
};
7177

72-
const IPAddress INADDR_NONE(0,0,0,0);
78+
extern const IPAddress INADDR_NONE;
7379

7480
#endif

0 commit comments

Comments
 (0)