diff --git a/workspace/m5stack_button/CMakeLists.txt b/workspace/m5stack_button/CMakeLists.txt new file mode 100644 index 0000000..330bf28 --- /dev/null +++ b/workspace/m5stack_button/CMakeLists.txt @@ -0,0 +1,9 @@ +# The following lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.16) + +set(EXTRA_COMPONENT_DIRS ../../ ../common) +add_compile_options(-w) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(m5stack_button) \ No newline at end of file diff --git a/workspace/m5stack_button/main/CMakeLists.txt b/workspace/m5stack_button/main/CMakeLists.txt new file mode 100644 index 0000000..f78c1d6 --- /dev/null +++ b/workspace/m5stack_button/main/CMakeLists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRCS "app.cpp" + INCLUDE_DIRS "." + PRIV_REQUIRES "mros2-esp32" "wifi" "M5Unified") diff --git a/workspace/m5stack_button/main/app.cpp b/workspace/m5stack_button/main/app.cpp new file mode 100644 index 0000000..b7fd204 --- /dev/null +++ b/workspace/m5stack_button/main/app.cpp @@ -0,0 +1,74 @@ +/* mros2 example + * Copyright (c) 2022 mROS-base + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mros2.h" +#include "std_msgs/msg/string.hpp" + +#include "cmsis_os.h" +#include "wifi.h" + +#include "M5Unified.h" +/* convert TARGET_NAME to put into message */ +#define quote(x) std::string(q(x)) +#define q(x) #x + +void userCallback(std_msgs::msg::String *msg) +{ + printf("Msg arrived from PC: '%s'\r\n", msg->data.c_str()); + M5.Lcd.printf("Msg arrived from PC: '%s' \r\n", msg->data.c_str()); +} + + +extern "C" void app_main(void) +{ + init_wifi(); + osKernelStart(); + + auto cfg = M5.config(); + M5.begin(cfg); + M5.Lcd.setTextSize(2); + M5.Lcd.println("mbed mros2 start!\r\n"); + M5.Lcd.printf("app name: m5stack_sample\r\n"); + + mros2::init(0, NULL); + MROS2_DEBUG("mROS 2 initialization is completed\r\n"); + + mros2::Node node = mros2::Node::create_node("mros2_node"); + mros2::Publisher pub = node.create_publisher("to_linux", 10); + mros2::Subscriber sub = node.create_subscription("to_stm", 10, userCallback); + + osDelay(100); + MROS2_INFO("ready to pub/sub message\r\n"); + + auto count = 0; + while (1) + { + M5.update(); + + if(M5.BtnA.wasClicked()) + { + auto msg = std_msgs::msg::String(); + msg.data = "Button A is pressed"; + printf("publishing msg: '%s'\r\n", msg.data.c_str()); + pub.publish(msg); + M5.Lcd.println("BtnA is pressed"); + } + osDelay(100); + } + + mros2::spin(); + return; +} \ No newline at end of file diff --git a/workspace/m5stack_button/main/templates.hpp b/workspace/m5stack_button/main/templates.hpp new file mode 100644 index 0000000..87345ce --- /dev/null +++ b/workspace/m5stack_button/main/templates.hpp @@ -0,0 +1,14 @@ +/* + * This file was automatically generated by generate_templates.py + * as one of mros2 features. You do not need to modify this. + */ +#include "std_msgs/msg/string.hpp" + + +template mros2::Publisher mros2::Node::create_publisher(std::string topic_name, int qos); +template void mros2::Publisher::publish(std_msgs::msg::String &msg); + + + +template mros2::Subscriber mros2::Node::create_subscription(std::string topic_name, int qos, void (*fp)(std_msgs::msg::String*)); +template void mros2::Subscriber::callback_handler(void *callee, const rtps::ReaderCacheChange &cacheChange);