forked from alibaba/AliOS-Things
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
c++ support experiment, tested ok on mk3060, esp32
- Loading branch information
1 parent
eeb585f
commit a2cff3b
Showing
6 changed files
with
191 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (C) 2014 Hamburg University of Applied Sciences (HAW) | ||
* Copyright (C) 2014 Ho Chi Minh city University of Technology (HCMUT) | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup examples | ||
* @{ | ||
* | ||
* @file | ||
* @brief implementation of declared functions of object cpp_class | ||
* | ||
* @author Martin Landsmann <martin.landsmann@haw-hamburg.de> | ||
* @author DangNhat Pham-Huu <51002279@hcmut.edu.vn> | ||
* | ||
* @} | ||
*/ | ||
|
||
#include <cstdio> | ||
#include "cpp_class.h" | ||
|
||
cpp_class::cpp_class() | ||
{ | ||
printf("Instanciating Object [constructor called]\n"); | ||
greet(); | ||
} | ||
|
||
cpp_class::~cpp_class() | ||
{ | ||
printf("Destroying Object [destructor called]\n"); | ||
printf("Im shutting down!\n"); | ||
} | ||
|
||
void cpp_class::say_hello(void) | ||
{ | ||
printf("Hello!\n"); | ||
} | ||
|
||
void cpp_class::say_hello(int n) | ||
{ | ||
printf("Hello![int: %d]\n", n); | ||
} | ||
|
||
void cpp_class::say_hello(float f) | ||
{ | ||
printf("Hello![float: %f]\n", f); | ||
} | ||
|
||
void cpp_class::greet(void) | ||
{ | ||
printf("Im starting!\n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (C) 2014 Hamburg University of Applied Sciences (HAW) | ||
* Copyright (C) 2014 Ho Chi Minh city University of Technology (HCMUT) | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @defgroup | ||
* @brief | ||
* @ingroup examples | ||
* @{ | ||
* | ||
* @file | ||
* @brief simple c++ object declaration with public and private functions | ||
* | ||
* @author Martin Landsmann <martin.landsmann@haw-hamburg.de> | ||
* @author DangNhat Pham-Huu <51002279@stu.hcmut.edu.vn> | ||
*/ | ||
|
||
#ifndef CPP_CLASS_H | ||
#define CPP_CLASS_H | ||
|
||
class cpp_class | ||
{ | ||
public: | ||
/** | ||
* @brief constructor | ||
*/ | ||
cpp_class(); | ||
|
||
/** | ||
* @brief destructor | ||
*/ | ||
~cpp_class(); | ||
|
||
/** | ||
* @brief public function | ||
*/ | ||
void say_hello(void); | ||
|
||
/** | ||
* @brief overloaded public function with int parameter | ||
*/ | ||
void say_hello(int n); | ||
|
||
/** | ||
* @brief overloaded public function with float parameter | ||
*/ | ||
void say_hello(float f); | ||
private: | ||
/** | ||
* @brief private function | ||
*/ | ||
void greet(void); | ||
}; | ||
|
||
void setup(void); | ||
void loop(void); | ||
|
||
/** @} */ | ||
#endif /* CPP_CLASS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include "cpp_class.h" | ||
|
||
void setup() { | ||
cpp_class cpp_obj; | ||
cpp_obj.say_hello((float)3.141592653); | ||
} | ||
|
||
void loop() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited | ||
*/ | ||
|
||
#if defined (__cplusplus) | ||
extern "C" { | ||
#endif | ||
#include <aos/aos.h> | ||
#include <assert.h> | ||
#if defined (__cplusplus) | ||
} | ||
#endif | ||
#include <cstdio> | ||
#include "cpp_class.h" | ||
|
||
static void app_delayed_action(void *arg) | ||
{ | ||
LOG("%s:%d %s\r\n", __func__, __LINE__, aos_task_name()); | ||
aos_post_delayed_action(5000, app_delayed_action, NULL); | ||
} | ||
|
||
extern "C" int application_start(int argc, char *argv[]) | ||
{ | ||
cpp_class cpp_obj; | ||
|
||
aos_post_delayed_action(1000, app_delayed_action, NULL); | ||
|
||
printf("hello\n"); | ||
cpp_obj.say_hello(42); | ||
setup(); | ||
|
||
aos_loop_run(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
NAME := sketch | ||
|
||
$(NAME)_SOURCES := \ | ||
sketch.cpp \ | ||
cpp_class.cpp \ | ||
ino.cpp | ||
|
||
GLOBAL_DEFINES += AOS_NO_WIFI | ||
|
||
$(NAME)_COMPONENTS := yloop cli | ||
|
||
#$(NAME)_CXXFLAGS := -std=c++11 -fno-rtti -fno-exceptions | ||
|
||
ifeq ($(BENCHMARKS),1) | ||
$(NAME)_COMPONENTS += benchmarks | ||
GLOBAL_DEFINES += CONFIG_CMD_BENCHMARKS | ||
endif | ||
|
||
ifneq (,${BINS}) | ||
GLOBAL_CFLAGS += -DSYSINFO_OS_BINS | ||
endif | ||
|
||
CURRENT_TIME = $(shell /bin/date +%Y%m%d.%H%M) | ||
CONFIG_SYSINFO_APP_VERSION = APP-1.0.0-$(CURRENT_TIME) | ||
$(info app_version:${CONFIG_SYSINFO_APP_VERSION}) | ||
GLOBAL_CFLAGS += -DSYSINFO_APP_VERSION=\"$(CONFIG_SYSINFO_APP_VERSION)\" |