...
 
Commits (2)
......@@ -25,6 +25,7 @@ ltmain.sh
/ar-lib
.deps/
.libs/
.dirstamp
config.h
stamp-h1
*.log
......@@ -95,3 +96,9 @@ build/
# Doxygen
doc/html
doc/Doxyfile
platformio.ini
.pioenvs
buttontest
library.properties
before_script:
- ./autogen.sh
stages:
- build
- test
......@@ -6,25 +9,19 @@ stages:
build:
stage: build
script:
- ./autogen.sh
- ./configure
- make
- make firmware
check:
stage: test
script:
- ./autogen.sh
- ./configure --enable-coverage
- make
- make check
- make coverage | tail -10
dependencies:
- build
distribute:
stage: deploy
script:
- ./autogen.sh
- ./configure
- make dist
artifacts:
......@@ -33,13 +30,10 @@ distribute:
expire_in: 1 week
except:
- tags
dependencies:
- build
distribute-release:
stage: deploy
script:
- ./autogen.sh
- ./configure
- make dist
artifacts:
......@@ -47,6 +41,4 @@ distribute-release:
- libbutton-*.tar.gz
only:
- tags
dependencies:
- check
9 Adrien Oliva <olivaa+gitlab@yapbreak.fr>
11 Adrien Oliva <olivaa+gitlab@yapbreak.fr>
# ChangeLog
## 1.1.0
- Add support for Arduino UNO board
- Add support for ESP8266 board
- Implement support for PlatformIO in autotools system
## 1.0.0
- First functional version with its test
......@@ -2,7 +2,10 @@ ACLOCAL_AMFLAGS = -I m4
include Makefile.common
SOURCE_DIR = src
SOURCE_DIR = src
if ARDSIM
SOURCE_DIR += simulation
endif
if CPPUTEST
SOURCE_DIR += utests
endif
......@@ -103,4 +106,24 @@ CLEANFILES = "coverage-report.info" "coverage-report2.info" "coverage-report" "c
clean-local:
@rm -rf $(CLEANFILES)
if PLATFORMIO
firmware:
@platformio run
upload: firmware
@platformio run --target upload
else # PLATFORMIO
firmware:
@(echo "Building firmware only allowed if platformio is available")
upload: firmware
endif
ALLPHONY += firmware
ALLPHONY += upload
.PHONY: $(ALLPHONY)
......@@ -3,15 +3,17 @@ AM_CXXFLAGS = -std=c++11 -Wall -Wextra ${extra_CXXFLAGS}
AM_LDFLAGS = ${extra_LDFLAGS}
AM_CFLAGS += -I$(top_srcdir)/src
AM_CFLAGS += -I$(top_srcdir)/
AM_CFLAGS += -I$(top_srcdir)/simulation
AM_CFLAGS += -I$(top_builddir)/src
AM_CFLAGS += -I$(top_builddir)/utests
AM_CFLAGS += -I$(top_srcdir)/utests/fixtures
AM_CFLAGS += -include $(top_builddir)/src/config.h
AM_CFLAGS += $(ARDSIM_CFLAGS)
AM_CXXFLAGS += -I$(top_srcdir)/src
AM_CXXFLAGS += -I$(top_srcdir)/
AM_CXXFLAGS += -I$(top_srcdir)/simulation
AM_CXXFLAGS += -I$(top_builddir)/src
AM_CXXFLAGS += -I$(top_builddir)/utests
AM_CXXFLAGS += -I$(top_srcdir)/utests/fixtures
AM_CXXFLAGS += -include $(top_builddir)/src/config.h
AM_CXXFLAGS += $(ARDSIM_CFLAGS)
AM_LDFLAGS += -L$(top_builddir)
### Feature
- Support of Arduino UNO and ESP8266 boards
- Control buttons
......@@ -9,7 +9,7 @@ See examples folder to know how to use.
This library is released under the terms of WTF-PL:
```
Copyright (C) 2017 Adrien Oliva <olivaa+gitlab@yapbreak.fr>
Copyright (C) 2018 Adrien Oliva <olivaa+gitlab@yapbreak.fr>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
......
AC_PREREQ([2.69])
AC_INIT()
AM_INIT_AUTOMAKE([-Wall -Werror])
AM_INIT_AUTOMAKE([-Wall -Werror subdir-objects])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR([src/button.h])
AC_CONFIG_HEADERS([src/config.h])
......@@ -129,6 +129,7 @@ AC_SUBST([extra_LDFLAGS])
# Checks for header files
AC_CHECK_HEADERS([stdint.h ])
AC_CHECK_HEADERS([string.h ])
# Checks for typedefs, structures, and compiler characteristics
AC_C_INLINE
......@@ -148,6 +149,11 @@ PKG_CHECK_MODULES([CPPUTEST], [cpputest], [have_cpputest=yes], [have_cpputest=no
AM_CONDITIONAL([CPPUTEST], [test "x${have_cpputest}" = "xyes"])
AS_IF([test "x$have_cpputest" = "xno"],
[AC_MSG_WARN([Please install CppUTest package to get support of unit tests.])])
PKG_CHECK_MODULES([ARDSIM], [ardsim >= 0.0.4], [have_ardsim=yes], [have_ardsim=no])
AM_CONDITIONAL([ARDSIM], [test "x${have_ardsim}" = "xyes"])
AS_IF([test "x$have_ardsim" = "xno"],
[AC_MSG_WARN([Please install Ardsim library from https://gitlab.yapbreak.fr/libraries/libardsim])],
[AC_DEFINE([HAVE_ARDSIM], [1], [Define if Arduino simulator is available])])
# Check coverage tools
AC_CHECK_PROG([gcovr], [gcovr], [yes])
......@@ -159,16 +165,21 @@ AM_CONDITIONAL(LCOV, [test "x${lcov}" = "xyes"])
AC_CHECK_PROG([genhtml], [genhtml], [yes])
AM_CONDITIONAL(GENHTML, [test "x${genhtml}" = "xyes"])
AM_CONDITIONAL(PERLGD, [perldoc -l GD])
AC_CHECK_PROG([platformio], [platformio], [yes])
AM_CONDITIONAL(PLATFORMIO, [test "x${platformio}" = "xyes"])
# Check doxygen installation
AC_CHECK_PROG([doxygen], [doxygen], [yes])
AM_CONDITIONAL(DOXYGEN, [test "x${doxygen}" = "xyes"])
# Generate files
AC_CONFIG_FILES([Makefile
AC_CONFIG_FILES([platformio.ini
library.properties
Makefile
utests/Makefile
utests/fixtures/Makefile
src/Makefile
simulation/Makefile
doc/Makefile
doc/Doxyfile
])
......
......@@ -26,10 +26,10 @@ fi
/usr/bin/cppcheck --enable=all --verbose --quiet \
--suppress=missingIncludeSystem \
-I./src/.. \
-I./src \
-I./utests/fixtures \
--inline-suppr \
-DHAVE_SOCAT=1 \
"${OUTPUT_FLAGS[@]}" \
"$@" \
src/ examples/
src/ simulation/ examples/
......@@ -34,6 +34,7 @@ void doubleclick(void *arg)
/**
* @brief Arduino function to setup and initialize everything.
*/
// cppcheck-suppress unusedFunction
void setup() {
Serial.begin(115200);
......@@ -51,26 +52,3 @@ void loop() {
my_button.loop();
}
/// [Click]
#ifndef ARDUINO
/**
* @brief Stub of Arduino main.
*
* @param argc (UNUSED)
* @param argv (UNUSED)
*
* @return Exit code
*/
int main(int argc, char *argv)
{
(void) argc;
(void) argv;
setup();
for (;;)
loop();
return 0;
}
#endif
name=@PACKAGE_NAME@
version=@PACKAGE_VERSION@
author=YapBreak
maintainer=YapBreak <@PACKAGE_BUGREPORT@>
sentence=Button library for any board Arduino framework compatible.
paragraph=Simple button library that allow simple control of buttons on Arduino boards.
category=button
url=@PACKAGE_URL@
; PlatformIO Project Configuration File
[env:witty]
platform = espressif8266
board = nodemcuv2
framework = arduino
build_flags = -DTESTFIRMWARE
[env:uno]
platform = atmelavr
board = uno
framework = arduino
build_flags = -DTESTFIRMWARE
#ifndef ARDUINO_H_ERPC3NVU
#define ARDUINO_H_ERPC3NVU
#ifdef HAVE_ARDSIM
#include <ardsim.h>
#else
#include "utests/fixtures/Arduino.h"
#endif
#endif /* end of include guard: ARDUINO_H_ERPC3NVU */
ACLOCAL_AMFLAGS = -I $(top_srcdir)/m4
include $(top_srcdir)/Makefile.common
bin_PROGRAMS = buttontest
buttontest_CFLAGS = -DTESTFIRMWARE $(AM_CFLAGS)
buttontest_CXXFLAGS = -DTESTFIRMWARE $(AM_CXXFLAGS)
buttontest_SOURCES = ../src/test.cpp
buttontest_SOURCES += simulate.cpp
buttontest_LDADD = $(top_builddir)/src/libbutton.la $(ARDSIM_LIBS)
#include "Arduino.h"
#include "button.h"
#include <time.h>
#include <stdio.h>
int main(int argc, const char *argv[])
{
(void) argc;
(void) argv;
return ardsim_run();
}
......@@ -3,7 +3,6 @@
* @brief Button interface implementation using Arduino framework.
*/
#include <Arduino.h>
#include "button.h"
/**
......
......@@ -33,14 +33,15 @@
#ifndef __BUTTON_H__
#define __BUTTON_H__
#include <functional>
#include <stdint.h>
#include <stdlib.h>
/**
* @brief Generic click callback function.
*
* User defined callback called on every click (single, double or long).
*/
typedef std::function<void(void *)> button_callback_t;
typedef void (*button_callback_t)(void *);
/**
* @brief Abstract a button.
......
#if defined(TESTFIRMWARE)
#include <Arduino.h>
#include "button.h"
// Create a button connected to pin 4.
button_t my_button(4);
/**
* @brief Callback for a single click.
*
* @param arg (UNUSED)
*/
void click(void *arg)
{
(void) arg;
Serial.println("Click");
}
/**
* @brief Callback for a double click.
*
* @param arg (UNUSED)
*/
void doubleclick(void *arg)
{
(void) arg;
Serial.println("Double click");
}
/**
* @brief Callback for a long click.
*
* @param arg (UNUSED)
*/
void longclick(void *arg)
{
(void) arg;
Serial.println("Long click");
}
/**
* @brief Arduino function to setup and initialize everything.
*/
extern "C" void setup() {
Serial.begin(115200);
my_button.on_single_click(click, NULL);
my_button.on_double_click(doubleclick, NULL);
my_button.on_long_click(longclick, NULL);
}
/**
* @brief Arduino function called in the main loop.
*/
extern "C" void loop() {
my_button.loop();
}
#endif
......@@ -10,10 +10,16 @@ noinst_PROGRAMS = $(TESTS)
check_PROGRAMS = $(TESTS)
lib_LTLIBRARIES = libbutton_utests.la
libbutton_utests_la_CFLAGS = $(TESTCFLAGS)
libbutton_utests_la_CXXFLAGS = $(TESTCXXFLAGS)
libbutton_utests_la_SOURCES = ../src/button.h
libbutton_utests_la_SOURCES += ../src/button.cpp
ut_button_xtest_SOURCES = ut_button.h
ut_button_xtest_SOURCES += main.cpp
ut_button_xtest_CFLAGS = $(TESTCFLAGS)
ut_button_xtest_CXXFLAGS = $(TESTCXXFLAGS)
ut_button_xtest_LDFLAGS = $(TESTLDFLAGS)
ut_button_xtest_LDADD = $(top_builddir)/src/libbutton.la
ut_button_xtest_LDADD = $(top_builddir)/utests/libbutton_utests.la
ut_button_xtest_LDADD += $(top_builddir)/utests/fixtures/libfixtures.la
......@@ -2,9 +2,11 @@ include $(top_srcdir)/Makefile.common
TEST_ROOT = $(top_srcdir)/utests
TESTCFLAGS = $(AM_CFLAGS)\
$(CPPUTEST_CFLAGS)
TESTCXXFLAGS = $(AM_CXXFLAGS)\
$(CPPUTEST_CFLAGS)
TESTCFLAGS = -I$(TEST_ROOT)/fixtures \
$(CPPUTEST_CFLAGS) \
$(AM_CFLAGS)
TESTCXXFLAGS = -I$(TEST_ROOT)/fixtures \
$(CPPUTEST_CFLAGS) \
$(AM_CXXFLAGS)
TESTLDFLAGS = $(AM_LDFLAGS) $(CPPUTEST_LIBS)
......@@ -23,6 +23,7 @@ void analogWrite(uint8_t pin, uint8_t value)
f->set_actual_analog_value(pin, value);
f->call("analogWrite");
}
void digitalWrite(uint8_t pin, uint8_t value)
{
fixtures *f = fixtures::getInstance();
......@@ -45,7 +46,14 @@ unsigned long millis()
{
fixtures *f = fixtures::getInstance();
return f->get_millis();
return static_cast<uint32_t>(f->get_millis());
}
unsigned long micros()
{
fixtures *f = fixtures::getInstance();
return static_cast<uint32_t>(f->get_micros());
}
void pinMode(uint8_t pin, uint8_t mode)
......
#ifndef ARDUINO_H_NID3LW9T
#define ARDUINO_H_NID3LW9T
#ifdef __cplusplus
#include <map>
#include <CppUTest/TestHarness.h>
#include <iostream>
#include <string>
extern "C"
{
#endif
#include <stdint.h>
/* Arduino fixtures */
......@@ -28,7 +34,10 @@ void pinMode(uint8_t pin, uint8_t mode);
* Arduino timing *
********************/
unsigned long millis();
unsigned long micros();
#ifdef __cplusplus
};
/*******************
* Test fixtures *
......@@ -98,4 +107,6 @@ class fixtures
void check() const;
};
#endif
#endif /* end of include guard: ARDUINO_H_NID3LW9T */
#!/bin/sh
PKGNAME="libbutton"
REPORT="yapbreak+libcomserial@yapbreak.fr"
REPORT="yapbreak+gitlab@yapbreak.fr"
TARNAME="$PKGNAME"
URL="https://gitlab.yapbreak.fr/iot/libbutton"
......