6 Commits

Author SHA1 Message Date
f40db8490f WIP 2025-02-07 18:07:26 -05:00
e6ba60da89 [esp] Add temperature and humidity example. 2025-02-01 23:49:53 -05:00
8bf174d256 [esp] Add ESP examples. 2025-02-01 14:33:40 -05:00
5f9f508581 [cpp] Remove ignores 2022-12-24 10:18:19 -05:00
3b6ecaa5e9 [cpp] Add Qt Desginer widget plugin examples 2022-12-24 10:16:30 -05:00
de652bad32 [cpp] Add catch and qt examples 2022-12-18 08:57:41 -05:00
87 changed files with 7428 additions and 18 deletions

2
.gitignore vendored
View File

@@ -10,3 +10,5 @@
**/Makefile **/Makefile
**/*.cbp **/*.cbp
**/node-modules/ **/node-modules/
**/CMakeLists.txt.user
**/catch2/bin/

View File

@@ -2,15 +2,16 @@
This repository is a collection of useful code snippets and configurations. This repository is a collection of useful code snippets and configurations.
``` ```bash
github.com/shaunrd0/klips/ github.com/shaunrd0/klips/
├── ansible # Ansible roles, playbooks, and examples ├── ansible # Ansible roles, playbooks, and examples
├── blockchain # Blockchain related project templates and examples ├── blockchain # Blockchain related project templates and examples
├── cpp # C++ programs, datastructures, and other examples ├── cpp # C++ programs, datastructures, and other examples
├── dotnet # .NET projects and examples ├── dotnet # .NET projects and examples
├── esp # ESP32 projects and examples
├── figlet # Figlet fonts I like :) ├── figlet # Figlet fonts I like :)
├── javascript # Javascript projects and examples ├── javascript # Javascript projects and examples
├── python # Python scripts or tools I've made ├── python # Python scripts and tools I've made
├── README.md ├── README.md
└── scripts # Bash scripts └── scripts # Bash scripts
``` ```

View File

@@ -1,4 +1,4 @@
# Ansible # ansible
A few simple roles / plays I've put together in learning how to use Ansible can be found under their corresponding directories. A few simple roles / plays I've put together in learning how to use Ansible can be found under their corresponding directories.

View File

@@ -1,3 +1,4 @@
# blockchain
A template project for getting started working on the Ethereum blockchain. A template project for getting started working on the Ethereum blockchain.
This project comes with basic packages for compiling and deploying Solidity contracts with Truffle. This project comes with basic packages for compiling and deploying Solidity contracts with Truffle.
@@ -72,7 +73,7 @@ I explain how to configure metamask on ropsten on [Knoats - Solidity](https://kn
Give yourself test Ethereum with the [Ropsten ETH Faucet](https://faucet.ropsten.be) Give yourself test Ethereum with the [Ropsten ETH Faucet](https://faucet.ropsten.be)
To deploy to ropsten test network, and verify using `truffle-verify-plugin` - To deploy to ropsten test network, and verify using `truffle-verify-plugin` -
```asm ```asm
npx truffle migrate --network ropsten npx truffle migrate --network ropsten

View File

@@ -21,9 +21,11 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_compile_options("-Wall") add_compile_options("-Wall")
add_subdirectory(algorithms) add_subdirectory(algorithms)
add_subdirectory(catch2)
add_subdirectory(cmake-example) add_subdirectory(cmake-example)
add_subdirectory(cryptography) add_subdirectory(cryptography)
add_subdirectory(datastructs) add_subdirectory(datastructs)
add_subdirectory(graphics) add_subdirectory(graphics)
add_subdirectory(multithreading) add_subdirectory(multithreading)
add_subdirectory(patterns) add_subdirectory(patterns)
add_subdirectory(qt)

View File

@@ -1,4 +1,4 @@
# Cpp # cpp
```bash ```bash
shaunrd0/klips/cpp/ shaunrd0/klips/cpp/
@@ -9,14 +9,15 @@ shaunrd0/klips/cpp/
├── graphics # Examples of graphics projects written in C++ ├── graphics # Examples of graphics projects written in C++
├── multithreading # Basic multithreading examples in C++ ├── multithreading # Basic multithreading examples in C++
├── patterns # Examples of various design patterns written in C++ ├── patterns # Examples of various design patterns written in C++
├── qt # Qt project examples using C++
└── README.md └── README.md
``` ```
This directory contains a `CMakeLists.txt`, which can be selected to open as a This directory contains a `CMakeLists.txt`, which can be selected to open as a
project within your preferred IDE. From there, all nested examples can be built, project within your preferred IDE. From there, all nested examples can be built,
debugged, and ran. debugged, and ran.
Some of the more recent projects in this repository requires the latest CMake LTS. Some of the more recent projects in this repository requires the latest CMake LTS.
To install `cmake` LTS with `apt` we can follow [official instructions from kitware](https://apt.kitware.com/) To install `cmake` LTS with `apt` we can follow [official instructions from kitware](https://apt.kitware.com/)
Alternatively, we can install the LTS with python's `pip`. Alternatively, we can install the LTS with python's `pip`.
```bash ```bash
@@ -33,7 +34,7 @@ cmake version 3.22.1
Once cmake is installed, dependencies for all examples can be installed with the command below. Once cmake is installed, dependencies for all examples can be installed with the command below.
```bash ```bash
sudo apt install libsdl2-dev freeglut3-dev sudo apt install libsdl2-dev freeglut3-dev
``` ```
If we build from this directory, we build all C++ projects and examples If we build from this directory, we build all C++ projects and examples
@@ -62,7 +63,7 @@ graph-test-object sdl-test visitor-test
graph-test-simple select-sort graph-test-simple select-sort
``` ```
We can also build from subdirectories. We can also build from subdirectories.
To only build projects related to design patterns we build from the `patterns/` subdirectory, for example To only build projects related to design patterns we build from the `patterns/` subdirectory, for example
```bash ```bash
cd /path/to/klips/cpp/patterns cd /path/to/klips/cpp/patterns
@@ -79,5 +80,5 @@ adapter-test factory-test prototype-test state-test
If cmake is not being used in a project, it can be built with `g++` manually using If cmake is not being used in a project, it can be built with `g++` manually using
the commands outlined in `*/.vscode/tasks.json`, or by using VSCode to open the example the commands outlined in `*/.vscode/tasks.json`, or by using VSCode to open the example
and running the build task. and running the build task.
Check the header comments in the main source file for the example for instructions. Check the header comments in the main source file for the example for instructions.

31
cpp/catch2/CMakeLists.txt Normal file
View File

@@ -0,0 +1,31 @@
################################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Practice project for testing with catch2 framework ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
cmake_minimum_required(VERSION 3.15)
project(
#[[NAME]] Catch2
VERSION 1.0
DESCRIPTION "Practice project for learning Catch2"
LANGUAGES CXX
)
add_compile_options(-Wall)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
Include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.0.1
)
FetchContent_MakeAvailable(Catch2)
add_subdirectory(src)
add_subdirectory(test)

View File

@@ -0,0 +1,10 @@
#ifndef KLIPS_KLIPS_H
#define KLIPS_KLIPS_H
class klips { };
unsigned int factorial(unsigned int);
#endif // KLIPS_KLIPS_H

View File

@@ -0,0 +1,29 @@
// Authored by 康桓瑋 on SO: https://stackoverflow.com/a/56766138
#ifndef CATCH2_TYPE_NAME_HPP
#include <string_view>
template <typename T>
constexpr auto type_name() {
std::string_view name, prefix, suffix;
#ifdef __clang__
name = __PRETTY_FUNCTION__;
prefix = "auto type_name() [T = ";
suffix = "]";
#elif defined(__GNUC__)
name = __PRETTY_FUNCTION__;
prefix = "constexpr auto type_name() [with T = ";
suffix = "]";
#elif defined(_MSC_VER)
name = __FUNCSIG__;
prefix = "auto __cdecl type_name<";
suffix = ">(void)";
#endif
name.remove_prefix(prefix.size());
name.remove_suffix(suffix.size());
return name;
}
#define CATCH2_TYPE_NAME_HPP
#endif // CATCH2_TYPE_NAME_HPP

View File

@@ -0,0 +1,22 @@
################################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Practice project for testing with catch2 framework ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
cmake_minimum_required(VERSION 3.15)
project(
#[[NAME]] Catch2
VERSION 1.0
DESCRIPTION "Practice project for learning Catch2"
LANGUAGES CXX
)
add_compile_options(-Wall)
add_definitions("-std=c++17")
add_library(klips SHARED klips.cpp)
target_include_directories(klips PRIVATE ${CMAKE_SOURCE_DIR}/include)

4
cpp/catch2/src/klips.cpp Normal file
View File

@@ -0,0 +1,4 @@
unsigned int factorial( unsigned int number ) {
return number <= 1 ? number : factorial(number-1)*number;
}

View File

@@ -0,0 +1,22 @@
################################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Practice project for testing with catch2 framework ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
cmake_minimum_required(VERSION 3.15)
project(
#[[NAME]] Catch2
VERSION 1.0
DESCRIPTION "Practice project for learning Catch2"
LANGUAGES CXX
)
add_compile_options(-Wall)
add_executable(test_klips test_klips.cpp)
target_link_libraries(test_klips PRIVATE Catch2::Catch2WithMain klips)
target_include_directories(test_klips PRIVATE ${CMAKE_SOURCE_DIR}/include)

View File

@@ -0,0 +1,147 @@
#define CATCH_CONFIG_MAIN
#include <iostream>
#include "../bin/catch.hpp"
#include "klips.hpp"
#include "type_name.hpp"
#define TT() std::cout << "T = " << type_name<TestType>() << std::endl;
#define TD(x) \
std::cout << type_name<decltype(x)>() << " " << #x << " = " << x << std::endl;
#define T(x) std::cout << "T = " << type_name<x>() << std::endl;
TEST_CASE("factorials are computed", "[factorial]") {
REQUIRE(factorial(1) == 1);
REQUIRE(factorial(2) == 2);
REQUIRE(factorial(3) == 6);
REQUIRE(factorial(10) == 3628800);
}
TEST_CASE("Generators") {
auto i = GENERATE(1, 3, 5);
TD(i);
}
TEST_CASE("Generators 2") {
auto i = GENERATE(1, 2);
SECTION("one") {
auto j = GENERATE(-3, -2);
REQUIRE(j < i);
std::cout << "i = " << i << "; j = " << j << std::endl;
}
SECTION("two") {
auto k = GENERATE(4, 5, 6);
REQUIRE(i != k);
std::cout << "i = " << i << "; k = " << k << std::endl;
}
}
TEST_CASE("Complex mix of sections and generates") {
auto i = GENERATE(1, 2);
SECTION("A") {
std::cout << "i = " << i << "; A passed" << std::endl;
SUCCEED("A");
}
std::cout << "left A\n";
auto j = GENERATE(3, 4);
std::cout << "i = " << i << "; j = " << j << std::endl;
SECTION("B") {
std::cout << "i = " << i << "; j = " << j << "; B passed;" << std::endl;
SUCCEED("B");
}
auto k = GENERATE(5, 6);
std::cout << "i = " << i << "; k = " << k << std::endl;
SUCCEED();
}
TEST_CASE("Test generaators 3", "[test]") { GENERATE(values({1, 2})); }
TEMPLATE_TEST_CASE("Testing template tests", "[test][template]", int8_t,
int16_t, int32_t, int64_t) {
TT();
}
template <typename T> struct Foo {
size_t size() { return 0; }
};
template <typename T> struct Test {
T test() {
T x;
return x;
}
};
TEMPLATE_PRODUCT_TEST_CASE("A Template product test case",
"[template][product]", (std::vector, Test),
(int, float)) {
TT();
}
TEMPLATE_PRODUCT_TEST_CASE("Product with differing arities",
"[template][product]", std::tuple,
(int, (int, double), (int, double, float))) {
TT();
}
using types = std::tuple<int8_t, int16_t, int32_t, int64_t>;
TEMPLATE_LIST_TEST_CASE("Testing template list tests", "[test][template][list]",
types) {
TT();
}
TEMPLATE_TEST_CASE_SIG(
"TemplateTestSig: arrays can be created from NTTP arguments",
"[vector][template][nttp]", ((typename T, int V), T, V), (int, 5),
(float, 4), (std::string, 15), ((std::tuple<int, float>), 6)) {
T(T);
std::cout << "V = " << V;
std::array<T, V> v;
REQUIRE(v.size() > 1);
}
template <typename T, size_t S> struct Bar {
size_t size() { return S; }
};
TEMPLATE_PRODUCT_TEST_CASE_SIG(
"A Template product test case with array signature",
"[template][product][nttp]", ((typename T, size_t S), T, S),
(std::array, Bar), ((int, 9), (float, 42))) {
TT();
TestType x;
REQUIRE(x.size() > 0);
}
template <typename T> struct test_config_get {
template <bool must_find> void run() {
// Config c{};
// std::string key{"the_key"};
// std::string value{"the_value"};
// c.set(key, value);
if constexpr (must_find) {
std::cout << "Test 1 ran";
} else {
std::cout << "Test 2 ran";
}
}
};
template <> template <bool must_find> void test_config_get<std::string>::run() {
if constexpr (must_find) {
std::cout << "Test 1 ran for strings";
} else {
std::cout << "Test 2 ran for strings";
}
}
TEMPLATE_PRODUCT_TEST_CASE("Test", "[test]", test_config_get,
(int, std::string)) {
TT();
TestType t;
test_config_get<int> s;
s.template run<true>();
// TestType t;
// t.run<true>();
}

24
cpp/qt/CMakeLists.txt Normal file
View File

@@ -0,0 +1,24 @@
################################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: A root project for practicing Qt 6 projects in C++ ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
cmake_minimum_required(VERSION 3.15)
project(
#[[NAME]] Klips
VERSION 1.0
DESCRIPTION "A root project for several small Qt6 practice projects"
LANGUAGES CXX
)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_compile_options("-Wall")
add_subdirectory(designer)
add_subdirectory(designer-plugin)
add_subdirectory(designer-plugin-collection)
add_subdirectory(slots)

32
cpp/qt/README.md Normal file
View File

@@ -0,0 +1,32 @@
# Cpp
```bash
shaunrd0/klips/cpp/qt/
├── designer # Using Qt Designer to create application GUI
├── designer-plugin # Adding custom widgets as Qt Designer plugins
├── designer-plugin-collection # Adding a collection of widget plugins to Qt Designer
└── README.md
```
This directory contains a `CMakeLists.txt`, which can be selected to open as a
project within your preferred IDE. From there, all nested examples can be built,
debugged, and ran.
The plugin examples will need to be installed for Qt Designer integration to work.
On Linux, Qt Designer looks under `/some/path/to/Qt/Tools/QtCreator/lib/Qt/plugins/designer/`.
On windows or Mac, this path may differ. Unfortunately I don't have these machines to test for myself.
```bash
cd klips/cpp/qt/designer-plugin-collection
mkdir build && cd build
cmake .. && cmake --build . --target install
```
After installing the plugin collection example above, we can open Qt Creator and navigate to the Designer.
We should see the custom collection is available within the Designer, and the contents of the widgets render correctly in the application view.
![side-panel-view.png](side-panel-view.png)
![plugin-render-view.png](plugin-render-view.png)

View File

@@ -0,0 +1,110 @@
################################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Example of making a collection of widget plugins for Qt Designer ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
cmake_minimum_required(VERSION 3.15)
project(
#[[NAME]] DesignerPluginCollection
VERSION 1.0
DESCRIPTION "Example of a widget plugin collection for Qt Designer"
LANGUAGES CXX
)
include(GenerateExportHeader)
add_compile_options(-Wall)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_SHARED_MODULE_PREFIX "")
set(QT_DIR "$ENV{HOME}/Code/Clones/Qt/" CACHE PATH "Path to Qt6")
# Qt Designer will look in different locations if WIN / Unix.
# These paths are for using Qt Designer integrated within Qt Creator.
# Standalone Qt Designer may use different paths.
if (WIN32)
set(QT_PLUGIN_INSTALL_DIR
"${QT_DIR}/Tools/QtCreator/bin/plugins/designer"
)
# This path may be different on windows. I have not tested this.
set(QT_PLUGIN_LIBRARY_DIR
"${QT_DIR}/Tools/QtCreator/lib/Qt/lib"
)
else()
set(QT_PLUGIN_INSTALL_DIR
"${QT_DIR}/Tools/QtCreator/lib/Qt/plugins/designer"
)
set(QT_PLUGIN_LIBRARY_DIR
"${QT_DIR}/Tools/QtCreator/lib/Qt/lib"
)
endif()
# This should be set to your Qt6 installation directory.
set(QT_INSTALL_DIR "${QT_DIR}/6.3.1/gcc_64/" CACHE PATH "Path to Qt6 install")
list(APPEND CMAKE_PREFIX_PATH "${QT_INSTALL_DIR}")
find_package(Qt6 REQUIRED COMPONENTS UiPlugin Core Gui Widgets)
# Creating a library with two plugins for the collection.
qt_add_library(widget-plugin-library
textview.cpp textview.h
widgetplugin.cpp widgetplugin.h
)
target_sources(widget-plugin-library PRIVATE
textview.cpp textview.h
treeview.cpp treeview.h
widgetplugin.cpp widgetplugin.h
)
set_target_properties(widget-plugin-library PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)
target_link_libraries(widget-plugin-library
PUBLIC Qt::UiPlugin Qt::Core Qt::Gui Qt::Widgets
)
install(TARGETS widget-plugin-library
RUNTIME DESTINATION "${QT_PLUGIN_LIBRARY_DIR}"
BUNDLE DESTINATION "${QT_PLUGIN_LIBRARY_DIR}"
LIBRARY DESTINATION "${QT_PLUGIN_LIBRARY_DIR}"
)
generate_export_header(widget-plugin-library)
# Creating the collection
qt_add_library(widget-plugin-collection
widgetplugincollection.cpp widgetplugincollection.h
)
target_link_libraries(widget-plugin-collection
Qt6::Widgets Qt6::UiPlugin widget-plugin-library
)
install(TARGETS widget-plugin-collection
RUNTIME DESTINATION "${QT_PLUGIN_INSTALL_DIR}"
BUNDLE DESTINATION "${QT_PLUGIN_INSTALL_DIR}"
LIBRARY DESTINATION "${QT_PLUGIN_INSTALL_DIR}"
)
# Application that will use the widget plugin
set(APP_DIR ${CMAKE_CURRENT_SOURCE_DIR})
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/app-dir.h.in"
"${CMAKE_CURRENT_SOURCE_DIR}/app-dir.h"
@ONLY
)
qt_add_executable(widget-app
widgetapp.cpp widgetapp.h widgetapp.ui
main.cpp
)
target_link_libraries(widget-app
PRIVATE Qt::Widgets widget-plugin-library
)

View File

@@ -0,0 +1,6 @@
#ifndef APPDIR_H_IN
#define APPDIR_H_IN
#define APP_DIR "/home/kapper/Code/klips/cpp/qt/designer-plugin-collection"
#endif // APPDIR_H_IN

View File

@@ -0,0 +1,6 @@
#ifndef APPDIR_H_IN
#define APPDIR_H_IN
#define APP_DIR "@APP_DIR@"
#endif // APPDIR_H_IN

View File

@@ -0,0 +1,18 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Main driver fprogram for practice using signals and slots in Qt ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#include "widgetapp.h"
#include <QApplication>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
WidgetApp widgetApp;
widgetApp.show();
return app.exec();
}

View File

@@ -0,0 +1,10 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Text viewer for signals and slots examples ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#include "textview.h"

View File

@@ -0,0 +1,44 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Text viewer for signals and slots examples ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#ifndef KLIPS_TEXTVIEW_H
#define KLIPS_TEXTVIEW_H
#include "widget-plugin-library_export.h"
#include <QPlainTextEdit>
class WIDGET_PLUGIN_LIBRARY_EXPORT TextView : public QPlainTextEdit {
Q_OBJECT
public:
explicit TextView(QWidget *parent = nullptr) : QPlainTextEdit(parent) {
appendPlainText("This is an example of a custom QTextView widget.");
}
~TextView() = default;
QString includeFile() const { return QStringLiteral("text-view.h"); };
public:
signals:
void sendTest();
private:
signals:
void sentTestPrivate();
public slots:
void test() { appendPlainText("Test signal received by TextView."); }
void testArgs(const QString &message) { appendPlainText(message); }
private slots:
void testPrivate() {}
};
#endif // KLIPS_TEXTVIEW_H

View File

@@ -0,0 +1,10 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Tree viewer ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#include "treeview.h"

View File

@@ -0,0 +1,36 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Tree viewer ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#ifndef KLIPS_TREEVIEW_H
#define KLIPS_TREEVIEW_H
#include "widget-plugin-library_export.h"
#include <app-dir.h>
#include <QFileSystemModel>
#include <QSortFilterProxyModel>
#include <QTreeView>
class WIDGET_PLUGIN_LIBRARY_EXPORT TreeView : public QTreeView {
Q_OBJECT
public:
explicit TreeView(QWidget *parent = nullptr) : QTreeView(parent) {
QFileSystemModel *model = new QFileSystemModel;
QSortFilterProxyModel *proxy = new QSortFilterProxyModel(this);
QModelIndex rootModelIndex = model->setRootPath(APP_DIR);
proxy->setSourceModel(model);
setModel(proxy);
setRootIndex(proxy->mapFromSource(rootModelIndex));
}
~TreeView() = default;
};
#endif // KLIPS_TREEVIEW_H

View File

@@ -0,0 +1,15 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Application that uses widget from the collection ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#include "widgetapp.h"
WidgetApp::WidgetApp(QWidget *parent) : QMainWindow(parent) {
m_widgetApp = new Ui::MainWindow;
m_widgetApp->setupUi(this);
}

View File

@@ -0,0 +1,37 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Application that uses a custom Qt Designer widget plugin ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#ifndef KLIPS_WIDGETAPP_H
#define KLIPS_WIDGETAPP_H
#include <QDockWidget>
#include <QMainWindow>
#include <QPlainTextEdit>
#include <QVBoxLayout>
#include <QWidget>
#include "ui_widgetapp.h"
class WidgetApp : public QMainWindow {
Q_OBJECT
public:
explicit WidgetApp(QWidget *parent = nullptr);
~WidgetApp() = default;
Ui::MainWindow * m_widgetApp;
public:
signals:
void sendTest();
public slots:
void test(){};
};
#endif // KLIPS_WIDGETAPP_H

View File

@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="TextView" name="text-view_4" native="true"/>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="actionOption1"/>
<addaction name="actionOption2"/>
<addaction name="separator"/>
<addaction name="actionCategory_2"/>
</widget>
<widget class="QMenu" name="menuEdit">
<property name="title">
<string>Edit</string>
</property>
</widget>
<widget class="QMenu" name="menuHelp">
<property name="title">
<string>Help</string>
</property>
</widget>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuHelp"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<widget class="QDockWidget" name="dockWidget_5">
<attribute name="dockWidgetArea">
<number>1</number>
</attribute>
<widget class="QWidget" name="dockWidgetContents_8">
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="TreeView" name="tree-view"/>
</item>
</layout>
</widget>
</widget>
<action name="actionOption1">
<property name="text">
<string>Option1</string>
</property>
</action>
<action name="actionOption2">
<property name="text">
<string>Option2</string>
</property>
</action>
<action name="actionCategory_2">
<property name="text">
<string>Section 2</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>TreeView</class>
<extends>QWidget</extends>
<header>treeview.h</header>
</customwidget>
<customwidget>
<class>TextView</class>
<extends>QWidget</extends>
<header>textview.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,52 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Example of a generic Qt Designer widget plugin ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#include "widgetplugin.h"
#include "textview.h"
#include <QtPlugin>
#include <utility>
WidgetPlugin::WidgetPlugin(QString group, QString name,
WidgetPlugin::Factory factory)
: m_group(std::move(group)), m_name(std::move(name)),
m_includeFile(name + ".h"), m_factory(std::move(factory)) {}
WidgetPlugin::WidgetPlugin(QString group, QString name, QString include,
WidgetPlugin::Factory factory)
: m_group(std::move(group)), m_name(std::move(name)),
m_includeFile(std::move(include)), m_factory(std::move(factory)) {}
QString WidgetPlugin::toolTip() const { return {}; }
QString WidgetPlugin::whatsThis() const { return {}; }
QIcon WidgetPlugin::icon() const { return {}; }
bool WidgetPlugin::isContainer() const { return false; }
QString WidgetPlugin::group() const { return m_group; }
QString WidgetPlugin::name() const { return m_name; }
// TODO: The generated UI headers do not use this member appropriately.
QString WidgetPlugin::includeFile() const { return m_includeFile; }
QWidget *WidgetPlugin::createWidget(QWidget *parent) {
return m_factory(parent);
}
bool WidgetPlugin::isInitialized() const { return m_initialized; }
void WidgetPlugin::initialize(QDesignerFormEditorInterface *) {
if (m_initialized)
return;
m_initialized = true;
}

View File

@@ -0,0 +1,52 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Example Qt Designer widget plugin ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#ifndef KLIPS_WIDGETPLUGIN_H
#define KLIPS_WIDGETPLUGIN_H
#include <QDesignerCustomWidgetInterface>
class WidgetPlugin : public QObject, public QDesignerCustomWidgetInterface {
Q_OBJECT
Q_PLUGIN_METADATA(IID "com.Klips.WidgetPlugin")
Q_INTERFACES(QDesignerCustomWidgetInterface)
using Factory = std::function<QWidget *(QWidget *)>;
public:
WidgetPlugin(QString group, QString name, Factory factory);
WidgetPlugin(QString group, QString name, QString include, Factory factory);
explicit WidgetPlugin(QObject *parent = nullptr) : QObject(parent) {}
~WidgetPlugin() = default;
public:
[[nodiscard]] QString group() const override;
[[nodiscard]] QString name() const override;
[[nodiscard]] QString includeFile() const override;
QWidget *createWidget(QWidget *parent) override;
[[nodiscard]] QString toolTip() const override;
[[nodiscard]] QString whatsThis() const override;
[[nodiscard]] QIcon icon() const override;
[[nodiscard]] bool isContainer() const override;
[[nodiscard]] bool isInitialized() const override;
void initialize(QDesignerFormEditorInterface *core) override;
private:
bool m_initialized = false;
QString m_group;
QString m_name;
QString m_includeFile;
Factory m_factory;
};
#endif // KLIPS_WIDGETPLUGIN_H

View File

@@ -0,0 +1,28 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Collection of widget plugins for Qt Designer ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#include "widgetplugincollection.h"
#include "textview.h"
#include "treeview.h"
#include "widgetplugin.h"
WidgetPluginCollection::WidgetPluginCollection(QObject *parent)
: QObject(parent), m_collectionName("Klips Widget Plugin Collection") {
m_collection = {
new WidgetPlugin(m_collectionName, "Text View Widget", "text-view.h",
[](QWidget *parent) { return new TextView(parent); }),
new WidgetPlugin(m_collectionName, "tree-view",
[](QWidget *parent) { return new TreeView(parent); }),
};
}
QList<QDesignerCustomWidgetInterface *>
WidgetPluginCollection::customWidgets() const {
return m_collection;
}

View File

@@ -0,0 +1,22 @@
#ifndef DESIGNERPLUGINCOLLECTION_WIDGETPLUGINCOLLECTION_H
#define DESIGNERPLUGINCOLLECTION_WIDGETPLUGINCOLLECTION_H
#include <QDesignerCustomWidgetCollectionInterface>
class WidgetPluginCollection : public QObject,
public QDesignerCustomWidgetCollectionInterface {
Q_OBJECT
Q_PLUGIN_METADATA(IID "com.Klips.WidgetPluginCollection")
Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
public:
explicit WidgetPluginCollection(QObject *parent = nullptr);
[[nodiscard]] QList<QDesignerCustomWidgetInterface *> customWidgets() const;
private:
QList<QDesignerCustomWidgetInterface *> m_collection;
QString m_collectionName;
};
#endif // DESIGNERPLUGINCOLLECTION_WIDGETPLUGINCOLLECTION_H

View File

@@ -0,0 +1,76 @@
################################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Example of making widget plugins for Qt Designer ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
cmake_minimum_required(VERSION 3.15)
project(
#[[NAME]] DesignerPlugin
VERSION 1.0
DESCRIPTION "Example of a widget plugin for Qt Designer"
LANGUAGES CXX
)
include(GenerateExportHeader)
add_compile_options(-Wall)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_SHARED_MODULE_PREFIX "")
set(QT_DIR "$ENV{HOME}/Code/Clones/Qt/" CACHE PATH "Path to Qt6")
# Qt Designer will look in different locations if WIN / Unix.
if (WIN32)
set(QT_PLUGIN_INSTALL_DIR
"${QT_DIR}/Tools/QtCreator/bin/plugins/designer"
)
else()
set(QT_PLUGIN_INSTALL_DIR
"${QT_DIR}/Tools/QtCreator/lib/Qt/plugins/designer"
)
endif()
# This should be set to your Qt6 installation directory.
set(QT_INSTALL_DIR "${QT_DIR}/6.3.1/gcc_64/" CACHE PATH "Path to Qt6 install")
list(APPEND CMAKE_PREFIX_PATH "${QT_INSTALL_DIR}")
find_package(Qt6 REQUIRED COMPONENTS UiPlugin Core Gui Widgets)
# Creating the plugin
qt_add_library(widget-plugin)
target_sources(widget-plugin PRIVATE
text-view.cpp text-view.h
widget-plugin.cpp widget-plugin.h
)
set_target_properties(widget-plugin PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)
target_link_libraries(widget-plugin PUBLIC
Qt::UiPlugin Qt::Core Qt::Gui Qt::Widgets
)
install(TARGETS widget-plugin
RUNTIME DESTINATION "${QT_PLUGIN_INSTALL_DIR}"
BUNDLE DESTINATION "${QT_PLUGIN_INSTALL_DIR}"
LIBRARY DESTINATION "${QT_PLUGIN_INSTALL_DIR}"
)
# Application that will use the widget plugin
qt_add_executable(widget-app
widget-app.cpp widget-app.h widget-app.ui
main.cpp
)
target_link_libraries(widget-app PRIVATE
Qt::Widgets widget-plugin
)

View File

@@ -0,0 +1,18 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Main driver fprogram for practice using signals and slots in Qt ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#include "widget-app.h"
#include <QApplication>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
WidgetApp widgetApp;
widgetApp.show();
return app.exec();
}

View File

@@ -0,0 +1,10 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Text viewer for signals and slots examples ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#include "text-view.h"

View File

@@ -0,0 +1,40 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Text viewer for signals and slots examples ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#ifndef KLIPS_TEXTVIEW_H
#define KLIPS_TEXTVIEW_H
#include <QPlainTextEdit>
class TextView : public QPlainTextEdit {
Q_OBJECT
public:
explicit TextView(QWidget *parent = nullptr) : QPlainTextEdit(parent) { }
~TextView() = default;
public:
signals:
void sendTest();
private:
signals:
void sentTestPrivate();
public slots:
void test() { appendPlainText("Test signal received by TextView."); }
void testArgs(const QString &message) { appendPlainText(message); }
private slots:
void testPrivate() {}
};
#endif // KLIPS_TEXTVIEW_H

View File

@@ -0,0 +1,16 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Application that uses a custom Qt Designer widget plugin ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#include "widget-app.h"
#include "widget-plugin.h"
WidgetApp::WidgetApp(QWidget *parent) : QMainWindow(parent) {
m_ui = new Ui::MainWindow;
m_ui->setupUi(this);
}

View File

@@ -0,0 +1,38 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Application that uses a custom Qt Designer widget plugin ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#ifndef KLIPS_WIDGETAPP_H
#define KLIPS_WIDGETAPP_H
#include <QDockWidget>
#include <QMainWindow>
#include <QPlainTextEdit>
#include <QVBoxLayout>
#include <QWidget>
#include "ui_widget-app.h"
class WidgetApp : public QMainWindow {
Q_OBJECT
public:
WidgetApp(QWidget *parent = nullptr);
~WidgetApp() = default;
Ui::MainWindow *m_ui;
public:
signals:
void sendTest();
public slots:
void test(){};
};
#endif // KLIPS_WIDGETAPP_H

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QHBoxLayout" name="horizontalLayout"/>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,67 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Example Qt Designer widget plugin ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#include "widget-plugin.h"
#include "text-view.h"
#include <QtPlugin>
QString WidgetPlugin::toolTip() const
{
return {};
}
QString WidgetPlugin::whatsThis() const
{
return {};
}
QIcon WidgetPlugin::icon() const
{
return {};
}
bool WidgetPlugin::isContainer() const
{
return false;
}
QString WidgetPlugin::group() const
{
return m_group;
}
QString WidgetPlugin::name() const
{
return QStringLiteral("KlipsWidgetPlugin");
}
QString WidgetPlugin::includeFile() const
{
return QStringLiteral("widget-plugin.h");
}
QWidget *WidgetPlugin::createWidget(QWidget *parent)
{
return new TextView(parent);
}
bool WidgetPlugin::isInitialized() const
{
return m_initialized;
}
void WidgetPlugin::initialize(QDesignerFormEditorInterface *)
{
if (m_initialized)
return;
m_initialized = true;
}

View File

@@ -0,0 +1,45 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Example Qt Designer widget plugin ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#ifndef KLIPS_WIDGETPLUGIN_H
#define KLIPS_WIDGETPLUGIN_H
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
class WidgetPlugin : public QObject, public QDesignerCustomWidgetInterface {
Q_OBJECT
Q_PLUGIN_METADATA(IID "com.Klips.WidgetPlugin")
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
explicit WidgetPlugin(QObject *parent = nullptr) : QObject(parent) {}
~WidgetPlugin() = default;
public:
QString group() const override;
QString name() const override;
QString includeFile() const override;
QWidget *createWidget(QWidget *parent) override;
QString toolTip() const override;
QString whatsThis() const override;
QIcon icon() const override;
bool isContainer() const override;
bool isInitialized() const override;
void initialize(QDesignerFormEditorInterface *core) override;
private:
bool m_initialized = false;
QString m_group;
QString m_name;
QString m_includeFile;
};
#endif // KLIPS_WIDGETPLUGIN_H

View File

@@ -0,0 +1,52 @@
################################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Practice project for using Qt Designer with custom C++ widgets ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
cmake_minimum_required(VERSION 3.15)
project(
#[[NAME]] Designer
VERSION 0.1
DESCRIPTION "Practice using Qt designer for desktop applications"
LANGUAGES CXX
)
add_compile_options(-Wall)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(QT_DIR "$ENV{HOME}/Code/Clones/Qt/6.3.1/gcc_64/" CACHE PATH "Path to Qt6")
list(APPEND CMAKE_PREFIX_PATH "${QT_DIR}")
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_add_executable(designer
designer.cpp designer.h designer.ui
debugconsole.h debugconsole.cpp debugconsole.ui
texteditor.h texteditor.cpp texteditor.ui
treeview.h treeview.cpp treeview.ui
main.cpp
)
set_target_properties(designer PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)
target_link_libraries(designer PUBLIC Qt::Core Qt::Gui Qt::Widgets)
install(TARGETS designer
RUNTIME DESTINATION "install/designer"
BUNDLE DESTINATION "install/designer"
LIBRARY DESTINATION "install/designer"
)

View File

@@ -0,0 +1,18 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Debug console widget made in Qt Designer with C++ ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#include "debugconsole.h"
#include "ui_debugconsole.h"
DebugConsole::DebugConsole(QWidget *parent)
: QDockWidget(parent), ui(new Ui::DebugConsole) {
ui->setupUi(this);
}
DebugConsole::~DebugConsole() { delete ui; }

View File

@@ -0,0 +1,29 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Debug console widget made in Qt Designer with C++ ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#ifndef DEBUGCONSOLE_H
#define DEBUGCONSOLE_H
#include "ui_debugconsole.h"
#include <QDockWidget>
class DebugConsole : public QDockWidget {
Q_OBJECT
public:
explicit DebugConsole(QWidget *parent = nullptr);
~DebugConsole();
inline QPlainTextEdit *getConsole() { return ui->plainTextEdit; }
private:
Ui::DebugConsole *ui;
};
#endif // DEBUGCONSOLE_H

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DebugConsole</class>
<widget class="QDockWidget" name="DebugConsole">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>DockWidget</string>
</property>
<widget class="QWidget" name="dockWidgetContents">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPlainTextEdit" name="plainTextEdit"/>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,30 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: MainWindow for Qt Designer desktop application ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#include <QtWidgets>
#include "debugconsole.h"
#include "designer.h"
#include "texteditor.h"
#include "treeview.h"
Designer::Designer(QWidget *parent)
: QMainWindow(parent), designer_(new Ui::Designer) {
designer_->setupUi(this);
setCentralWidget(new TextEditor);
auto debugConsole = new DebugConsole;
debugConsole->getConsole()->appendPlainText("Test 1");
debugConsole->getConsole()->appendPlainText("Test 2");
auto treeView = new TreeView;
addDockWidget(Qt::DockWidgetArea::BottomDockWidgetArea, debugConsole);
addDockWidget(Qt::DockWidgetArea::BottomDockWidgetArea, treeView);
sendTest();
}

View File

@@ -0,0 +1,39 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: MainWindow for Qt Designer desktop application ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#ifndef KLIPS_SLOTSAPP_H
#define KLIPS_SLOTSAPP_H
#include <QDockWidget>
#include <QMainWindow>
#include <QPlainTextEdit>
#include <QVBoxLayout>
#include <QWidget>
#include "ui_designer.h"
class Designer : public QMainWindow {
Q_OBJECT
public:
Designer(QWidget *parent = nullptr);
~Designer() = default;
public:
signals:
void sendTest();
public slots:
void test(){};
private:
Ui::Designer *designer_;
};
#endif // KLIPS_SLOTSAPP_H

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Designer</class>
<widget class="QMainWindow" name="Designer">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget"/>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
</widget>
<addaction name="menuFile"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>

19
cpp/qt/designer/main.cpp Normal file
View File

@@ -0,0 +1,19 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Main driver program for Qt Designer desktop application.. ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#include "designer.h"
#include <QApplication>
int main(int argc, char * argv[]) {
QApplication app(argc, argv);
Designer qtk;
qtk.show();
// Show widget.
return app.exec();
}

View File

@@ -0,0 +1,23 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Dockable text editor widget made in Qt Designer with C++ ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#include "texteditor.h"
#include "ui_texteditor.h"
TextEditor::TextEditor(QWidget *parent) :
QDockWidget(parent),
ui(new Ui::TextEditor)
{
ui->setupUi(this);
}
TextEditor::~TextEditor()
{
delete ui;
}

View File

@@ -0,0 +1,31 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Dockable text editor widget made in Qt Designer with C++ ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#ifndef TEXTEDITOR_H
#define TEXTEDITOR_H
#include <QDockWidget>
namespace Ui {
class TextEditor;
}
class TextEditor : public QDockWidget
{
Q_OBJECT
public:
explicit TextEditor(QWidget *parent = nullptr);
~TextEditor();
private:
Ui::TextEditor *ui;
};
#endif // TEXTEDITOR_H

View File

@@ -0,0 +1,17 @@
<ui version="4.0">
<class>TextEditor</class>
<widget class="QDockWidget" name="TextEditor">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>DockWidget</string>
</property>
<widget class="QWidget" name="dockWidgetContents"/>
</widget>
</ui>

View File

@@ -0,0 +1,23 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Dockable tree view widget made in Qt Designer with C++ ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#include "treeview.h"
#include "ui_treeview.h"
TreeView::TreeView(QWidget *parent) :
QDockWidget(parent),
ui(new Ui::TreeView)
{
ui->setupUi(this);
}
TreeView::~TreeView()
{
delete ui;
}

View File

@@ -0,0 +1,31 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Dockable tree view widget made in Qt Designer with C++ ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#ifndef TREEVIEW_H
#define TREEVIEW_H
#include <QDockWidget>
namespace Ui {
class TreeView;
}
class TreeView : public QDockWidget
{
Q_OBJECT
public:
explicit TreeView(QWidget *parent = nullptr);
~TreeView();
private:
Ui::TreeView *ui;
};
#endif // TREEVIEW_H

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TreeView</class>
<widget class="QDockWidget" name="TreeView">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>DockWidget</string>
</property>
<widget class="QWidget" name="dockWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTreeView" name="treeView"/>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

BIN
cpp/qt/side-panel-view.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@@ -0,0 +1,50 @@
################################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Practice project for using signals and slots in Qt ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
cmake_minimum_required(VERSION 3.15)
project(
#[[NAME]] Slots
VERSION 1.0
DESCRIPTION "Practice using signals and slots in Qt 6"
LANGUAGES CXX
)
add_compile_options(-Wall)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(QT_DIR "$ENV{HOME}/Code/Clones/Qt/6.3.1/gcc_64/" CACHE PATH "Path to Qt6")
list(APPEND CMAKE_PREFIX_PATH "${QT_DIR}")
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_add_executable(slots
text-view.cpp text-view.h
slots-app.cpp slots-app.h
main.cpp
)
set_target_properties(slots PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)
target_link_libraries(slots PUBLIC Qt::Core Qt::Gui Qt::Widgets)
install(TARGETS slots
RUNTIME DESTINATION "install/slots"
BUNDLE DESTINATION "install/slots"
LIBRARY DESTINATION "install/slots"
)

18
cpp/qt/slots/main.cpp Normal file
View File

@@ -0,0 +1,18 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Main driver fprogram for practice using signals and slots in Qt ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#include "slots-app.h"
#include <QApplication>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
SlotsApp slotsApp;
slotsApp.show();
return app.exec();
}

View File

@@ -0,0 +1,42 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: MainWindow application for practice using signals and slots in Qt ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#include "slots-app.h"
#include "text-view.h"
SlotsApp::SlotsApp(QWidget *parent) : QMainWindow(parent) {
auto textBox = new QPlainTextEdit;
auto textView = new TextView;
auto frame = new QFrame;
auto dock = new QDockWidget(this);
auto dockWidget = new QWidget;
auto dockWidgetLayout = new QVBoxLayout;
dockWidgetLayout->addWidget(frame);
dockWidgetLayout->addWidget(textBox);
dockWidget->setLayout(dockWidgetLayout);
dock->setWidget(dockWidget);
auto dock2 = new QDockWidget(this);
auto dockWidget2 = new QWidget;
auto dockWidgetLayout2 = new QVBoxLayout;
dockWidgetLayout2->addWidget(textView);
dockWidget2->setLayout(dockWidgetLayout2);
dock2->setWidget(dockWidget2);
textBox->setReadOnly(true);
textBox->appendPlainText("Test 1");
textBox->appendPlainText("Test 2");
addDockWidget(Qt::DockWidgetArea::BottomDockWidgetArea, dock);
addDockWidget(Qt::DockWidgetArea::BottomDockWidgetArea, dock2);
connect(this, &SlotsApp::sendTest, textView, &TextView::test);
sendTest();
}

34
cpp/qt/slots/slots-app.h Normal file
View File

@@ -0,0 +1,34 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: MainWindow application for practice using signals and slots in Qt ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#ifndef KLIPS_SLOTSAPP_H
#define KLIPS_SLOTSAPP_H
#include <QDockWidget>
#include <QMainWindow>
#include <QPlainTextEdit>
#include <QVBoxLayout>
#include <QWidget>
class SlotsApp : public QMainWindow {
Q_OBJECT
public:
SlotsApp(QWidget *parent = nullptr);
~SlotsApp() = default;
public:
signals:
void sendTest();
public slots:
void test(){};
};
#endif // KLIPS_SLOTSAPP_H

View File

@@ -0,0 +1,10 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Text viewer for signals and slots examples ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#include "text-view.h"

40
cpp/qt/slots/text-view.h Normal file
View File

@@ -0,0 +1,40 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: Text viewer for signals and slots examples ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
*/
#ifndef KLIPS_TEXTVIEW_H
#define KLIPS_TEXTVIEW_H
#include <QPlainTextEdit>
class TextView : public QPlainTextEdit {
Q_OBJECT
public:
TextView(QWidget *parent = nullptr) {}
~TextView() = default;
public:
signals:
void sendTest()QWidget;
private:
signals:
void sentTestPrivate();
public slots:
void test() { appendPlainText("Test signal received by TextView."); }
void testArgs(const QString &message) { appendPlainText(message); }
private slots:
void testPrivate() {}
};
#endif // KLIPS_TEXTVIEW_H

View File

@@ -1,4 +1,4 @@
# Dotnet # dotnet
```bash ```bash
shaunrd0/klips/dotnet/ shaunrd0/klips/dotnet/

View File

@@ -0,0 +1,38 @@
// set pin numbers
const int buttonPin = 4; // the number of the pushbutton pin
const int ledPin = 5; // the number of the LED pin
// variable for storing the pushbutton status
int buttonState = 0;
bool light_on = false;
bool handled = false;
void setup() {
Serial.begin(115200);
// initialize the pushbutton pin as an input
pinMode(buttonPin, INPUT);
// initialize the LED pin as an output
pinMode(ledPin, OUTPUT);
}
void loop() {
// read the state of the pushbutton value
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
if (buttonState == HIGH) {
if (!handled) {
Serial.println("Handling button pressed.");
light_on = !light_on;
handled = true;
digitalWrite(ledPin, light_on ? HIGH : LOW);
}
// turn LED on
} else {
if (handled) {
Serial.println("Reset button handled state.");
handled = false;
}
}
}

View File

@@ -0,0 +1,5 @@
# 01_led-button
![schematic](./schematic.png)
Simple LED controlled by an on-board button.

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 KiB

View File

@@ -0,0 +1,183 @@
#include <WiFi.h>
//
// Web server project globals
// Replace with your network credentials
const char* ssid = "network-name";
const char* password = "password";
WiFiServer server(80);
// Variable to store the HTTP request
String header;
// Current time
unsigned long currentTime = millis();
// Previous time
unsigned long previousTime = 0;
// Define timeout time in milliseconds (example: 2000ms = 2s)
const long timeoutTime = 2000;
//
// Button / light project globals
// set pin numbers
const int buttonPin = 4; // the number of the pushbutton pin
const int ledPin = 5; // the number of the LED pin
// variable for storing the pushbutton status
int buttonState = 0;
bool light_on = false;
bool handled = false;
void setup() {
Serial.begin(115200);
// initialize the pushbutton pin as an input
pinMode(buttonPin, INPUT);
// initialize the LED pin as an output
pinMode(ledPin, OUTPUT);
// wait for the Serial Monitor to be open
while (!Serial) {
delay(100);
}
// Connect to Wi-Fi network with SSID and password
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Print local IP address and start web server
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("Web Server IP address: ");
Serial.println(WiFi.localIP());
server.begin();
}
// Handles the on-board button press.
void handleButtonPress() {
// read the state of the pushbutton value
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
if (buttonState == HIGH) {
if (!handled) {
Serial.println("Handling button pressed.");
light_on = !light_on;
handled = true;
digitalWrite(ledPin, light_on ? HIGH : LOW);
}
// turn LED on
} else {
if (handled) {
Serial.println("Reset button handled state.");
handled = false;
}
}
}
void displayPinState(WiFiClient client, int gpio_pin, bool state) {
// Display current state, and ON/OFF buttons for GPIO <gpio_pin>
client.println(String("<p>GPIO ") + String(gpio_pin) + String(" - Current State ") + String(state ? "ON" : "OFF") + String("</p>"));
// If the output state is off, it displays the ON button
if (state) {
client.println(String("<p><a href=\"/") + String(gpio_pin) + String("/off\"><button class=\"button button2\">OFF</button></a></p>"));
} else {
client.println(String("<p><a href=\"/") + String(gpio_pin) + String("/on\"><button class=\"button\">ON</button></a></p>"));
}
}
void handleStateChange(WiFiClient client, int gpio_pin) {
if (header.indexOf(String("GET /") + String(gpio_pin) + String("/on")) >= 0) {
Serial.println(String("GPIO ") + String(gpio_pin) + String(" on"));
light_on = true;
digitalWrite(gpio_pin, HIGH);
} else if (header.indexOf(String("GET /") + String(gpio_pin) + String("/off")) >= 0) {
Serial.println(String("GPIO ") + String(gpio_pin) + String(" off"));
light_on = false;
digitalWrite(gpio_pin, LOW);
}
}
void loop() {
WiFiClient client = server.available(); // Listen for incoming clients
handleButtonPress();
if (client) { // If a new client connects,
currentTime = millis();
previousTime = currentTime;
Serial.println("New Client."); // print a message out in the serial port
Serial.println("Web Server IP address: ");
Serial.println(WiFi.localIP());
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected() && currentTime - previousTime <= timeoutTime) { // loop while the client's connected
// Also handle the button press in this loop to not miss events.
handleButtonPress();
currentTime = millis();
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
header += c;
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println();
// turns the GPIOs on and off
// Display the HTML web page
client.println("<!DOCTYPE html><html>");
client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
client.println("<link rel=\"icon\" href=\"data:,\">");
// CSS to style the on/off buttons
// Feel free to change the background-color and font-size attributes to fit your preferences
client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");
client.println(".button { background-color: #4CAF50; border: none; color: white; padding: 16px 40px;");
client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}");
client.println(".button2 {background-color: #555555;}</style></head>");
//
// Web Page Heading
client.println("<body><h1>ESP32 Web Server</h1>");
//
// Web Page Body Contents
// Button Controls
displayPinState(client, ledPin, light_on);
//
// Close Web Page Body / Heading
client.println("</body></html>");
// The HTTP response ends with another blank line
client.println();
// Break out of the while loop
break;
} else { // if you got a newline, then clear currentLine
currentLine = "";
}
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
}
}
// Clear the header variable
header = "";
// Close the connection
client.stop();
Serial.println("Client disconnected.");
Serial.println("");
}
}

View File

@@ -0,0 +1,11 @@
# 02_led-button-web
![schematic](./schematic.png)
This example uses the same schematic as [01_led-button](../01_led-button/).
The only difference is that you can also control the button through a web browser from any device connected to your local network.
This example was adapted from the example code in the [Arduino ESP32 API reference](https://docs.espressif.com/projects/arduino-esp32/en/latest/api/wifi.html#wi-fi-ap-example).
![screenshot](./screenshot.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@@ -0,0 +1,161 @@
// Import required libraries
#include "WiFi.h"
#include "ESPAsyncWebServer.h"
#include <Adafruit_Sensor.h>
#include <DHT.h>
// Replace with your network credentials
const char* ssid = "network-name";
const char* password = "password";
#define DHTPIN 4 // Digital pin connected to the DHT sensor
// Uncomment the type of sensor in use:
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
// Create AsyncWebServer object on port 80
AsyncWebServer server(80);
String readDHTTemperature() {
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
//float t = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return "--";
}
else {
Serial.println(t);
return String(t);
}
}
String readDHTHumidity() {
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
if (isnan(h)) {
Serial.println("Failed to read from DHT sensor!");
return "--";
}
else {
Serial.println(h);
return String(h);
}
}
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<style>
html {
font-family: Arial;
display: inline-block;
margin: 0px auto;
text-align: center;
}
h2 { font-size: 3.0rem; }
p { font-size: 3.0rem; }
.units { font-size: 1.2rem; }
.dht-labels{
font-size: 1.5rem;
vertical-align:middle;
padding-bottom: 15px;
}
</style>
</head>
<body>
<h2>ESP32 DHT Server</h2>
<p>
<i class="fas fa-thermometer-half" style="color:#059e8a;"></i>
<span class="dht-labels">Temperature</span>
<span id="temperature">%TEMPERATURE%</span>
<sup class="units">&deg;C</sup>
</p>
<p>
<i class="fas fa-tint" style="color:#00add6;"></i>
<span class="dht-labels">Humidity</span>
<span id="humidity">%HUMIDITY%</span>
<sup class="units">&percnt;</sup>
</p>
</body>
<script>
setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("temperature").innerHTML = this.responseText;
}
};
xhttp.open("GET", "/temperature", true);
xhttp.send();
}, 10000 ) ;
setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("humidity").innerHTML = this.responseText;
}
};
xhttp.open("GET", "/humidity", true);
xhttp.send();
}, 10000 ) ;
</script>
</html>)rawliteral";
// Replaces placeholder with DHT values
String processor(const String& var){
//Serial.println(var);
if(var == "TEMPERATURE"){
return readDHTTemperature();
}
else if(var == "HUMIDITY"){
return readDHTHumidity();
}
return String();
}
void setup(){
// Serial port for debugging purposes
Serial.begin(115200);
dht.begin();
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}
// Print ESP32 Local IP Address
Serial.println(WiFi.localIP());
// Route for root / web page
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/html", index_html, processor);
});
server.on("/temperature", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/plain", readDHTTemperature().c_str());
});
server.on("/humidity", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/plain", readDHTHumidity().c_str());
});
// Start server
server.begin();
}
void loop(){
}

View File

@@ -0,0 +1,56 @@
# 03_temp-humidity-web
![schematic](./schematic.png)
Temperature and humidity sensor served on a web page within the local network.
![screenshot](./screenshot.png)
## Dependencies
You need to install a couple of libraries for this project:
* The DHT and the Adafruit Unified Sensor Driver libraries to read from the DHT sensor.
* ESPAsyncWebServer and Async TCP libraries to build the asynchronous web server.
The default Arduino IDE installation will store libraries at `~/Arduino/ibraries` - if this directory doesn't exist, create it.
### Installing DHT Sensor Library
To read from the DHT sensor using Arduino IDE, you need to install the [DHT sensor library](https://github.com/adafruit/DHT-sensor-library).
```bash
wget -O DHT_sensor.zip https://github.com/adafruit/DHT-sensor-library/archive/master.zip
unzip DHT_sensor.zip
mv DHT-sensor-library-master/ ~/Arduino/libraries/DHT_sensor
```
## Install Adafruit Unified Sensor Driver Library
You also need to install the [Adafruit Unified Sensor Driver library](https://github.com/adafruit/Adafruit_Sensor) to work with the DHT sensor.
```bash
wget -O Adafruit_sensor.zip https://github.com/adafruit/Adafruit_Sensor/archive/master.zip
unzip Adafruit_sensor.zip
mv Adafruit_Sensor-master/ ~/Arduino/libraries/Adafruit_sensor
```
## Installing ESPAsyncWebServer Library
Follow the next steps to install the [ESPAsyncWebServer library](https://github.com/me-no-dev/ESPAsyncWebServer):
```bash
wget -O ESPAsyncWebServer.zip https://github.com/me-no-dev/ESPAsyncWebServer/archive/master.zip
unzip ESPAsyncWebServer.zip
mv ESPAsyncWebServer-master/ ~/Arduino/libraries/ESPAsyncWebServer
```
## Installing Async TCP Library
The ESPAsyncWebServer library requires the [AsyncTCP library](https://github.com/me-no-dev/AsyncTCP) to work. Follow the next steps to install that library:
```bash
wget -O AsyncTCP.zip https://github.com/me-no-dev/AsyncTCP/archive/master.zip
unzip AsyncTCP.zip
mv AsyncTCP-master/ ~/Arduino/libraries/AsyncTCP
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

4
esp/cpp/04_esp-idf-arduino/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
build
managed_components

View File

@@ -0,0 +1,18 @@
# For more information about build system see
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
# The following five 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.26)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(
#[[NAME]] esp-idf-arduino
VERSION 0.1
DESCRIPTION "Example ESP-IDF cmake project"
LANGUAGES CXX
)
# For writing pure cmake components, see the documentation
# https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/build-system.html#writing-pure-cmake-components
idf_build_set_property(COMPILE_OPTIONS "-Wno-error" APPEND)

View File

@@ -0,0 +1,47 @@
# 03_temp-humidity-web
There is no schematic for this example, it simply prints some output to the serial monitor.
This is more of a build system example for untethering yourself from the Arduino IDE.
To build this example you can run the following commands.
```bash
mkdir build
cd build
cmake ..
make -j $(nproc)
```
To flash to your ESP or access the `idf.py menuconfig` menu from the ESP-IDF you can run the same commands with `make`.
```bash
make flash
make menuconfig
```
If Ninja is preferred:
```bash
mkdir build
cd build
cmake .. -G Nina
ninja
```
## Dependencies
The [Arduino IDE](https://github.com/arduino/arduino-ide) must be installed.
install [ESP-IDF](https://github.com/espressif/esp-idf?tab=readme-ov-file#setup-build-environment)
```bash
git clone -b v5.3.2 git@github.com:espressif/esp-idf.git
cd esp-idf
./install.sh
# You only need to do this if you want to use ESP-IDF's idf.py helper script.
# This example uses cmake, so it's not required.
. ./export.sh
```

View File

@@ -0,0 +1,431 @@
dependencies:
chmorgan/esp-libhelix-mp3:
component_hash: cbb76089dc2c5749f7b470e2e70aedc44c9da519e04eb9a67d4c7ec275229e53
dependencies:
- name: idf
require: private
version: '>=4.1.0'
source:
registry_url: https://components.espressif.com
type: service
version: 1.0.3
espressif/arduino-esp32:
component_hash: f5fc427eaeb4b84d6b644e3fac1251240a38b8c5e08122f1810a59145f00ccb0
dependencies:
- name: chmorgan/esp-libhelix-mp3
registry_url: https://components.espressif.com
require: private
version: 1.0.3
- name: espressif/cbor
registry_url: https://components.espressif.com
require: private
rules:
- if: target not in [esp32c2, esp32p4]
version: 0.6.0~1
- name: espressif/esp-dsp
registry_url: https://components.espressif.com
require: private
rules:
- if: target != esp32c2
version: ^1.3.4
- name: espressif/esp-modbus
registry_url: https://components.espressif.com
require: private
version: ^1.0.15
- name: espressif/esp-sr
registry_url: https://components.espressif.com
require: private
rules:
- if: target in [esp32s3]
version: ^1.4.2
- name: espressif/esp-zboss-lib
registry_url: https://components.espressif.com
require: private
rules:
- if: target not in [esp32c2, esp32p4]
version: ==1.6.0
- name: espressif/esp-zigbee-lib
registry_url: https://components.espressif.com
require: private
rules:
- if: target not in [esp32c2, esp32p4]
version: ==1.6.0
- name: espressif/esp_diag_data_store
registry_url: https://components.espressif.com
require: private
rules:
- if: target not in [esp32c2, esp32p4]
version: 1.0.1
- name: espressif/esp_diagnostics
registry_url: https://components.espressif.com
require: private
rules:
- if: target not in [esp32c2, esp32p4]
version: 1.0.2
- name: espressif/esp_hosted
registry_url: https://components.espressif.com
require: private
rules:
- if: target == esp32p4
version: ^0.0.25
- name: espressif/esp_insights
registry_url: https://components.espressif.com
require: private
rules:
- if: target not in [esp32c2, esp32p4]
version: 1.0.1
- name: espressif/esp_modem
registry_url: https://components.espressif.com
require: private
version: ^1.1.0
- name: espressif/esp_rainmaker
registry_url: https://components.espressif.com
require: private
rules:
- if: target not in [esp32c2, esp32p4]
version: 1.5.0
- name: espressif/esp_wifi_remote
registry_url: https://components.espressif.com
require: private
rules:
- if: target == esp32p4
version: ^0.4.1
- name: espressif/libsodium
registry_url: https://components.espressif.com
require: private
version: ^1.0.20~1
- name: espressif/mdns
registry_url: https://components.espressif.com
require: private
version: ^1.2.3
- name: espressif/network_provisioning
registry_url: https://components.espressif.com
require: private
version: 1.0.2
- name: espressif/qrcode
registry_url: https://components.espressif.com
require: private
rules:
- if: target not in [esp32c2, esp32p4]
version: 0.1.0~2
- name: espressif/rmaker_common
registry_url: https://components.espressif.com
require: private
rules:
- if: target not in [esp32c2, esp32p4]
version: 1.4.6
- name: idf
require: private
version: '>=5.3,<5.4'
- name: joltwallet/littlefs
registry_url: https://components.espressif.com
require: private
version: ^1.10.2
source:
registry_url: https://components.espressif.com/
type: service
targets:
- esp32
- esp32s2
- esp32s3
- esp32c2
- esp32c3
- esp32c6
- esp32h2
- esp32p4
version: 3.1.1
espressif/cbor:
component_hash: 440f4ee4504841cc9b4f3a8ef755776a612ac9dace355514c68b999868f990ff
dependencies:
- name: idf
require: private
version: '>=4.3'
source:
registry_url: https://components.espressif.com
type: service
version: 0.6.0~1
espressif/esp-dsp:
component_hash: fa7fe74305df6da25867437ebcd4213e047cbfc0556cf92067ab657fce537c6e
dependencies:
- name: idf
require: private
version: '>=4.2'
source:
registry_url: https://components.espressif.com
type: service
version: 1.5.2
espressif/esp-modbus:
component_hash: e42ebfdfc9d8e46821a915b4c1a5c6465c44dbd4e1bca10531e26f4adc7acc42
dependencies:
- name: idf
require: private
version: '>=4.3'
source:
registry_url: https://components.espressif.com
type: service
version: 1.0.17
espressif/esp-serial-flasher:
component_hash: dcc42a16712a1a636509cf0bf90e14032d7f2141784b533613b267b6aa318d52
dependencies: []
source:
registry_url: https://components.espressif.com
type: service
version: 0.0.11
espressif/esp-zboss-lib:
component_hash: fad683f7e04366398b61c0eea6e6517d4fe7ec4112407e26743dc80bafc0dcdc
dependencies:
- name: idf
require: private
version: '>=5.0'
source:
registry_url: https://components.espressif.com
type: service
version: 1.6.0
espressif/esp-zigbee-lib:
component_hash: 0026979f590d7f2b07f433bb0fd031a12b0c2cc0eec8584b59cb6e567d5afd82
dependencies:
- name: idf
require: private
version: '>=5.0'
source:
registry_url: https://components.espressif.com
type: service
version: 1.6.0
espressif/esp_diag_data_store:
component_hash: 8849195251dbb8a2d7268335277cfa310cef36e4ac1e90cd59ad3be4269a30d7
dependencies:
- name: idf
require: private
version: '>=4.1'
source:
registry_url: https://components.espressif.com
type: service
version: 1.0.1
espressif/esp_diagnostics:
component_hash: fe19f5ee7f0145f406d36a4d5310e4ae0c6ee1afa47f2681ada8a2ea8582d390
dependencies:
- name: idf
require: private
version: '>=4.1'
- name: espressif/rmaker_common
registry_url: https://components.espressif.com
require: private
version: ~1.4.0
source:
registry_url: https://components.espressif.com
type: service
version: 1.0.2
espressif/esp_insights:
component_hash: 2472a19de98a8b991baeeac7209765b70ce14ec2b1435dbed3abd020dd0f7227
dependencies:
- name: idf
require: private
version: '>=4.1'
- name: espressif/cbor
registry_url: https://components.espressif.com
require: private
rules:
- if: idf_version >=5.0
version: ~0.6
- name: espressif/esp_diag_data_store
registry_url: https://components.espressif.com
require: private
version: ~1.0
- name: espressif/esp_diagnostics
registry_url: https://components.espressif.com
require: private
version: ~1.0
- name: espressif/rmaker_common
registry_url: https://components.espressif.com
require: private
version: ~1.4.0
source:
registry_url: https://components.espressif.com
type: service
version: 1.0.1
espressif/esp_modem:
component_hash: 681d7c8417ce0f2a11a562c6998b7b379a4847be41d84673c11c0c7a6b00e918
dependencies:
- name: idf
require: private
version: '>=4.1'
source:
registry_url: https://components.espressif.com
type: service
version: 1.3.0
espressif/esp_rainmaker:
component_hash: f89a4759347f3909417fb33059452f36c86befae9d10bda78b5417b7a5d19d11
dependencies:
- name: espressif/rmaker_common
registry_url: https://components.espressif.com
require: private
version: ~1.4.6
- name: espressif/network_provisioning
registry_url: https://components.espressif.com
require: private
rules:
- if: idf_version >= 5.1
version: ~1.0.0
- name: espressif/mdns
registry_url: https://components.espressif.com
require: private
rules:
- if: idf_version >=5.0
version: ^1.2.0
- name: espressif/json_parser
registry_url: https://components.espressif.com
require: private
version: ~1.0.3
- name: espressif/json_generator
registry_url: https://components.espressif.com
require: private
version: ~1.1.1
- name: espressif/esp_secure_cert_mgr
registry_url: https://components.espressif.com
require: private
rules:
- if: idf_version >=4.3
version: ^2.2.1
- name: espressif/esp_schedule
registry_url: https://components.espressif.com
require: private
version: ~1.2.0
- name: espressif/esp_rcp_update
registry_url: https://components.espressif.com
require: private
rules:
- if: idf_version >= 5.1
version: ~1.2.0
source:
registry_url: https://components.espressif.com
type: service
version: 1.5.0
espressif/esp_rcp_update:
component_hash: c10afbd54a17f27eed880e61262b161656e6d36ad63376c307f9273e99d0abcd
dependencies:
- name: idf
require: private
version: '>=5.0'
- name: espressif/esp-serial-flasher
registry_url: https://components.espressif.com
require: private
version: ~0.0.0
source:
registry_url: https://components.espressif.com
type: service
version: 1.2.0
espressif/esp_schedule:
component_hash: e202a9c688f7f1ab601efb91d682e4bcfaebc508dcceee1a1e0a0d2d1ca75a26
dependencies:
- name: espressif/rmaker_common
registry_url: https://components.espressif.com
require: private
version: ~1.4.2
source:
registry_url: https://components.espressif.com
type: service
version: 1.2.0
espressif/esp_secure_cert_mgr:
component_hash: 5d9175b416f751ba6a7cb35bdf092f0af85658ce06c4a592c7c541d8017ebeb9
dependencies:
- name: idf
require: private
version: '>=4.3'
source:
registry_url: https://components.espressif.com
type: service
version: 2.5.0
espressif/jsmn:
component_hash: d80350c41bbaa827c98a25b6072df00884e72f54885996fab4a4f0aebce6b6c3
dependencies:
- name: idf
require: private
version: '>=4.3'
source:
registry_url: https://components.espressif.com
type: service
version: 1.1.0
espressif/json_generator:
component_hash: 45033e1c199b13f1c8c1b544fb7d4e2df6a8e3071ebdcb1b22582b61a7974ff2
dependencies: []
source:
registry_url: https://components.espressif.com
type: service
version: 1.1.2
espressif/json_parser:
component_hash: d74b81729ad06ec11ff5eb5b1b0d7df1d00e6027fc11471f4b139c70dcf1b1e4
dependencies:
- name: espressif/jsmn
registry_url: https://components.espressif.com
require: private
rules:
- if: idf_version >=5.0
version: ~1.1
source:
registry_url: https://components.espressif.com
type: service
version: 1.0.3
espressif/libsodium:
component_hash: 25b968723c584a2742ca36cebe5a7ef049c6767e059f7b1e1eec69946019025d
dependencies:
- name: idf
require: private
version: '>=4.2'
source:
registry_url: https://components.espressif.com
type: service
version: 1.0.20~2
espressif/mdns:
component_hash: 4e21149422be01c24d4b1d4dec64fa07d136d8c5d234e931f3ebf375cbde51a0
dependencies:
- name: idf
require: private
version: '>=5.0'
source:
registry_url: https://components.espressif.com
type: service
version: 1.5.2
espressif/network_provisioning:
component_hash: ef2e10182fd1861e68b821491916327c25416ca7ae70e5a6e43313dbc71fe993
dependencies:
- name: idf
require: private
version: '>=5.1'
source:
registry_url: https://components.espressif.com
type: service
version: 1.0.2
espressif/qrcode:
component_hash: 3b493771bc5d6ad30cbf87c25bf784aada8a08c941504355b55d6b75518ed7bc
dependencies: []
source:
registry_url: https://components.espressif.com
type: service
version: 0.1.0~2
espressif/rmaker_common:
component_hash: a3a1df881278d0351fc850b77792fe8a196ddd6dcacbea203d606329cc6a0239
dependencies: []
source:
registry_url: https://components.espressif.com
type: service
version: 1.4.6
idf:
source:
type: idf
version: 5.3.2
joltwallet/littlefs:
component_hash: add3caf39a265868f70e55f17e8bfb401f200e45a601dc392832e7ac2c1487bc
dependencies:
- name: idf
require: private
version: '>=4.3'
source:
registry_url: https://components.espressif.com
type: service
version: 1.16.4
direct_dependencies:
- espressif/arduino-esp32
- idf
manifest_hash: fe35c802ba6a89901a8000205c3dac0c8d85b17fbd036b7a7dcb213e5f6e5361
target: esp32
version: 2.0.0

View File

@@ -0,0 +1,4 @@
idf_component_register(
SRCS "main.cpp"
INCLUDE_DIRS "."
)

View File

@@ -0,0 +1,17 @@
## IDF Component Manager Manifest File
dependencies:
## Required IDF version
idf:
version: '>=4.1.0'
# # Put list of dependencies here
# # For components maintained by Espressif:
# component: "~1.0.0"
# # For 3rd party components:
# username/component: ">=1.0.0,<2.0.0"
# username2/component2:
# version: "~1.0.0"
# # For transient dependencies `public` flag can be set.
# # `public` flag doesn't have an effect dependencies of the `main` component.
# # All dependencies of `main` are public by default.
# public: true
espressif/arduino-esp32: ^3.1.1

View File

@@ -0,0 +1,10 @@
#include "Arduino.h"
void setup() {
Serial.begin(115200);
}
void loop() {
Serial.println("Hello world!");
delay(1000);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

22
esp/cpp/README.md Normal file
View File

@@ -0,0 +1,22 @@
# esp
```bash
shaunrd0/klips/esp/
├── 01_led-button # Simple LED circuit controlled by an on board button.
├── 02_led-button-web # LED controlled by a button or within a web browser.
├── 03_temp-humidity-web # Temperature and humidity sensor within a web browser.
├── ESP32-basic-starter-kit.pdf # PDF for tutorials in ESP32 starter kit.
├── ESP32-dev-module.png
└── README.md
```
This directory contains ESP32 projects largely adapted from the examples in [ESP32-basic-starter-kit.pdf](./ESP32-basic-starter-kit.pdf).
The APIs in the original examples paired with this PDF have changed, and I decided to do some different things with the code and/or circuits, but the original code can be [found here](https://www.dropbox.com/scl/fo/6znlij3eb23ih4jxcpv2w/AKvB1t9CCUgoVRVtGen8Yrw?rlkey=z84anl0hs940qf9fpl7l8q8q2&e=1&dl=0).
The board selected in [Arduino IDE](https://www.arduino.cc/en/software) is ESP32 Dev Module -
![ESP32 Dev Module](./ESP32-dev-module.png)
[Arduino ESP32 GitHub](https://github.com/espressif/arduino-esp32) \
[Arduino ESP32 API reference](https://docs.espressif.com/projects/arduino-esp32/en/latest/libraries.html)

View File

@@ -1,9 +1,9 @@
# Javascript # javascript
This directory contains Javascript projects and examples that I've made. This directory contains Javascript projects and examples that I've made.
``` ```bash
github.com/shaunrd0/klips/javascript shaunrd0/klips/javascript
├── webgl # Examples of using WebGL within JS ├── webgl # Examples of using WebGL within JS
└── README.md └── README.md
``` ```

View File

@@ -1,12 +1,13 @@
# python
This directory contains a collection of Python scripts or CLI tools that I've made. This directory contains a collection of Python scripts or CLI tools that I've made.
Each of these projects provide a `requirements.txt` that can be used to Each of these projects provide a `requirements.txt` that can be used to
install the required Python packages and dependencies. install the required Python packages and dependencies.
To install Python 3.9 and `pip` To install Python 3.9 and `pip`
```bash ```bash
sudo apt install python3.9 python3-pip sudo apt install python3.9 python3-pip
python3.9 -m pip install -U pip python3.9 -m pip install -U pip
``` ```