Compare commits
7 Commits
de652bad32
...
old-graph-
| Author | SHA1 | Date | |
|---|---|---|---|
| 26839b82b7 | |||
| 6cd7d7db29 | |||
| 17c559a31f | |||
| e6ba60da89 | |||
| 8bf174d256 | |||
| 5f9f508581 | |||
| 3b6ecaa5e9 |
2
.gitignore
vendored
@@ -10,3 +10,5 @@
|
||||
**/Makefile
|
||||
**/*.cbp
|
||||
**/node-modules/
|
||||
**/CMakeLists.txt.user
|
||||
**/catch2/bin/
|
||||
|
||||
11
README.md
@@ -2,15 +2,16 @@
|
||||
|
||||
This repository is a collection of useful code snippets and configurations.
|
||||
|
||||
```
|
||||
github.com/shaunrd0/klips/
|
||||
```bash
|
||||
shaunrd0/klips/
|
||||
├── ansible # Ansible roles, playbooks, and examples
|
||||
├── blockchain # Blockchain related project templates and examples
|
||||
├── cpp # C++ programs, datastructures, and other examples
|
||||
├── dotnet # .NET projects and examples
|
||||
├── esp # ESP32 projects and examples
|
||||
├── figlet # Figlet fonts I like :)
|
||||
├── javascript # Javascript projects and examples
|
||||
├── python # Python scripts or tools I've made
|
||||
├── README.md
|
||||
└── scripts # Bash scripts
|
||||
├── python # Python scripts and tools I've made
|
||||
├── scripts # Bash scripts
|
||||
└── README.md
|
||||
```
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# 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.
|
||||
@@ -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)
|
||||
|
||||
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
|
||||
npx truffle migrate --network ropsten
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Cpp
|
||||
# cpp
|
||||
|
||||
```bash
|
||||
shaunrd0/klips/cpp/
|
||||
@@ -13,11 +13,11 @@ shaunrd0/klips/cpp/
|
||||
└── 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,
|
||||
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/)
|
||||
Alternatively, we can install the LTS with python's `pip`.
|
||||
```bash
|
||||
@@ -34,7 +34,7 @@ cmake version 3.22.1
|
||||
|
||||
Once cmake is installed, dependencies for all examples can be installed with the command below.
|
||||
```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
|
||||
@@ -63,7 +63,7 @@ graph-test-object sdl-test visitor-test
|
||||
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
|
||||
```bash
|
||||
cd /path/to/klips/cpp/patterns
|
||||
@@ -80,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
|
||||
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.
|
||||
|
||||
17970
cpp/catch2/bin/catch.hpp
21
cpp/problems/CMakeLists.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
################################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: A root project for C++ practice problems and solutions ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
################################################################################
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(
|
||||
#[[NAME]] Problems
|
||||
VERSION 1.0
|
||||
DESCRIPTION "Practice problems and solutions written in C++"
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY, ${CMAKE_BINARY_DIR}/bin)
|
||||
add_compile_options("-Wall")
|
||||
|
||||
add_subdirectory(graphs)
|
||||
24
cpp/problems/README.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# Problems
|
||||
|
||||
A collection of some example problems and solutions written in C++. Mostly these
|
||||
are based off questions I found on [hackerrank](https://www.hackerrank.com),
|
||||
[leetcode](https://leetcode.com/), [codility](https://www.codility.com/), or
|
||||
similar programming practice platforms.
|
||||
|
||||
```
|
||||
klips/cpp/problems
|
||||
.
|
||||
├── graphs # Graph implementations with related problems and solutions
|
||||
└── README.md
|
||||
```
|
||||
|
||||
We can build the examples with the following commands.
|
||||
|
||||
```bash
|
||||
cd /path/to/klips/cpp/problems/
|
||||
mkdir build && cd build
|
||||
cmake .. && cmake --build .
|
||||
ls bin/
|
||||
|
||||
problems-graphs
|
||||
```
|
||||
21
cpp/problems/graphs/CMakeLists.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
################################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: Collection of problems and solutions to graph problems in C++ ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
################################################################################
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(
|
||||
#[[NAME]] ProblemsGraphs
|
||||
VERSION 1.0
|
||||
DESCRIPTION "Problems and solutions using graphs in C++"
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
add_compile_options("-Wall")
|
||||
|
||||
add_executable(problems-graphs driver.cpp lib-graph.cpp lib-graph.hpp)
|
||||
32
cpp/problems/graphs/driver.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: Driver program solving various C++ graph problems ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
################################################################################
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "lib-graph.hpp"
|
||||
|
||||
int main(const int argc, const char * argv[]) {
|
||||
Simple::Graph g({ {1,2,3}, {2,3,4} });
|
||||
g.Print();
|
||||
std::cout << std::endl;
|
||||
|
||||
std::vector<int> graphA = {6,0,1,2,3,4,5};
|
||||
std::vector<std::pair<int, int>> graphB = { {9, 2}, {2, 3}, {3, 1} };
|
||||
std::vector<std::vector<int>> graphC = {{1}, {2, 3}, {3, 1, 0}};
|
||||
g.ReadEdges(graphA);
|
||||
g.Print();
|
||||
std::cout << std::endl;
|
||||
g.ReadEdges(graphB);
|
||||
g.Print();
|
||||
std::cout << std::endl;
|
||||
g.ReadEdges(graphC);
|
||||
g.Print();
|
||||
|
||||
return 0;
|
||||
}
|
||||
12
cpp/problems/graphs/lib-graph.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: Graph implementations to solve various problems in C++ ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
################################################################################
|
||||
*/
|
||||
|
||||
#include "lib-graph.hpp"
|
||||
|
||||
|
||||
335
cpp/problems/graphs/lib-graph.hpp
Normal file
@@ -0,0 +1,335 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: Graph implementations to solve various problems in C++ ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
################################################################################
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
|
||||
#ifndef GRAPHS_LIB_GRAPH_HPP
|
||||
#define GRAPHS_LIB_GRAPH_HPP
|
||||
|
||||
|
||||
namespace Simple {
|
||||
typedef int32_t Node;
|
||||
typedef std::vector<Node> Nodes;
|
||||
typedef std::vector<Nodes> Edges;
|
||||
|
||||
class Graph {
|
||||
public:
|
||||
Graph() = default;
|
||||
explicit Graph(Edges e) : edges(std::move(e)) { }
|
||||
|
||||
void Print()
|
||||
{
|
||||
for (size_t node = 0; node < edges.size(); node++) {
|
||||
for (const auto & to : edges[node]) {
|
||||
std::cout << "(" << node << ")-----(" << to << ")" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Where graph[i] represents the connection between node i and graph[i]
|
||||
// {1, 1, 2, 2}
|
||||
void ReadEdges(const std::vector<int> & graph)
|
||||
{
|
||||
edges.clear();
|
||||
edges.assign(graph.size(), {});
|
||||
for (int i = 0; i < graph.size(); i++) {
|
||||
if (i == graph[i]) continue;
|
||||
edges[graph[i]].push_back(i);
|
||||
edges[i].push_back(graph[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Where each graph[i] represents a single edge between two nodes
|
||||
// { {1, 2}, {2, 3}, {3, 1} }
|
||||
void ReadEdges(const std::vector<std::pair<int, int>> & graph)
|
||||
{
|
||||
edges.clear();
|
||||
for (const auto & edge : graph) {
|
||||
while (edges.size() <= edge.first || edges.size() <= edge.second) {
|
||||
edges.emplace_back();
|
||||
}
|
||||
edges[edge.first].push_back(edge.second);
|
||||
edges[edge.second].push_back(edge.first);
|
||||
}
|
||||
}
|
||||
|
||||
// Where graph[node] holds all connected adjacent nodes
|
||||
// {{1}, {2, 3}, {2, 1, 0}}
|
||||
void ReadEdges(const std::vector<std::vector<int>> & graph)
|
||||
{
|
||||
edges.clear();
|
||||
edges.assign(graph.size(), {});
|
||||
for (size_t i = 0; i < graph.size(); i++) {
|
||||
for (const auto & adj : graph[i]) {
|
||||
if (adj == i) continue;
|
||||
edges[i].push_back(adj);
|
||||
edges[adj].push_back(int32_t(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Edges edges;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
namespace Object {
|
||||
struct Node {
|
||||
Node() : val(INT32_MIN), adj() { }
|
||||
explicit Node(int32_t v) : val(v), adj() { }
|
||||
Node(int32_t v, std::vector<int32_t> a) : val(v), adj(std::move(a)) { }
|
||||
|
||||
int32_t val;
|
||||
std::vector<int32_t> adj;
|
||||
|
||||
// Define operator== for std::find; And comparisons between nodes
|
||||
bool operator==(const Node & b) const { return this->val == b.val;}
|
||||
bool operator!=(const Node & b) const { return this->val != b.val;}
|
||||
};
|
||||
|
||||
typedef std::vector<Node> Edges;
|
||||
|
||||
class Graph {
|
||||
public:
|
||||
Graph() = default;
|
||||
explicit Graph(Edges e) : edges(std::move(e)) { }
|
||||
|
||||
void Print()
|
||||
{
|
||||
for (int32_t node = 0; node < edges.size(); node++) {
|
||||
for (const auto & to : GetNode(node)->adj) {
|
||||
std::cout << "(" << node << ")-----(" << to << ")" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Node * GetNode(const int32_t & nodeVal)
|
||||
{
|
||||
auto foundNode = std::find(edges.begin(), edges.end(), Node(nodeVal));
|
||||
// [nodeVal](const Node & a)->bool { return a.val == nodeVal;});
|
||||
if (foundNode == edges.end()) return nullptr; // Node does not exist
|
||||
return &*foundNode;
|
||||
}
|
||||
|
||||
Node * CreateNode(const int32_t & nodeVal)
|
||||
{
|
||||
auto newNode = GetNode(nodeVal);
|
||||
if (newNode != nullptr) return newNode;
|
||||
// Create node if not found
|
||||
edges.emplace_back(nodeVal); // Calls Node(int32_t) ctor
|
||||
return &edges.back(); // Get ptr to our new node; Don't copy it
|
||||
}
|
||||
|
||||
// Where graph[i] represents the connection between node i and graph[i]
|
||||
// {1, 1, 2, 2}
|
||||
void ReadEdges(const std::vector<int> & graph)
|
||||
{
|
||||
edges.clear();
|
||||
for (int i = 0; i < graph.size(); i++) {
|
||||
if (i == graph[i]) continue;
|
||||
// Check if nodes already exist; Create them if not found
|
||||
auto nodeFrom = CreateNode(graph[i]);
|
||||
auto nodeTo = CreateNode(i);
|
||||
// Push node ptr to adjacent list
|
||||
nodeFrom->adj.push_back(nodeTo->val);
|
||||
nodeTo->adj.push_back(nodeFrom->val);
|
||||
}
|
||||
}
|
||||
|
||||
// Where each graph[i] represents a single edge between two nodes
|
||||
// { {1, 2}, {2, 3}, {3, 1} }
|
||||
void ReadEdges(const std::vector<std::pair<int, int>> & graph)
|
||||
{
|
||||
edges.clear();
|
||||
for (const auto & edge : graph) {
|
||||
auto nodeFrom = CreateNode(edge.first);
|
||||
auto nodeTo = CreateNode(edge.second);
|
||||
nodeFrom->adj.push_back(nodeTo->val);
|
||||
nodeTo->adj.push_back(nodeFrom->val);
|
||||
}
|
||||
}
|
||||
|
||||
// Where graph[node] holds all connected adjacent nodes
|
||||
// {{1}, {2, 3}, {2, 1, 0}}
|
||||
void ReadEdges(const std::vector<std::vector<int>> & graph)
|
||||
{
|
||||
edges.clear();
|
||||
edges.assign(graph.size(), {});
|
||||
for (size_t i = 0; i < graph.size(); i++) {
|
||||
for (const auto & adj : graph[i]) {
|
||||
if (adj == i) continue;
|
||||
auto nodeFrom = CreateNode(int32_t(i));
|
||||
auto nodeTo = CreateNode(adj);
|
||||
nodeFrom->adj.push_back(nodeTo->val);
|
||||
nodeTo->adj.push_back(nodeFrom->val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Edges edges;
|
||||
};
|
||||
}
|
||||
|
||||
namespace Weighted {
|
||||
using Weight = int32_t;
|
||||
using Adjacent = std::multimap<Weight, int32_t>;
|
||||
struct Node {
|
||||
Node() : val(INT32_MIN), adj() { }
|
||||
explicit Node(int32_t v) : val(v), adj() { }
|
||||
Node(int32_t v, Adjacent a) : val(v), adj(std::move(a)) { }
|
||||
|
||||
int32_t val;
|
||||
Adjacent adj;
|
||||
};
|
||||
using Edge = std::pair<int, int>;
|
||||
|
||||
class Graph {
|
||||
Graph() = default;
|
||||
explicit Graph(Node n) : root(std::move(n)) { }
|
||||
void ReadGraph(std::vector<std::vector<int>> nodeList)
|
||||
{
|
||||
// Read a 2D vector of nodes into a
|
||||
}
|
||||
private:
|
||||
Node root;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
//namespace Object {
|
||||
//struct Edge {
|
||||
// friend struct Node;
|
||||
// friend class Graph;
|
||||
// Edge() : from(INT32_MIN), to(INT32_MIN) { }
|
||||
// Edge(const int32_t & f, const int32_t & t) : from(f), to(t) { }
|
||||
//
|
||||
// private:
|
||||
// int32_t from, to;
|
||||
// };
|
||||
// using Edges = std::vector<Edge>;
|
||||
//
|
||||
//// template <typename T, typename S>
|
||||
//// struct Subscriptor {
|
||||
//// T<int32_t, S> data;
|
||||
//// };
|
||||
//
|
||||
// struct Node {
|
||||
// using Adjacent = std::vector<Node *>;
|
||||
// using NodeMap = std::unordered_map<int32_t, Node *>;
|
||||
// friend class Graph; // Allow Graph to access protected / private members
|
||||
// friend struct GraphData;
|
||||
//
|
||||
// // Struct is public by default
|
||||
// Node () : val(0), adj() { }
|
||||
// explicit Node(int32_t v) : val(v), adj() { }
|
||||
// Node(int32_t v, Adjacent a) : val(v), adj(std::move(a)) { }
|
||||
// inline void SetAdjacent(Adjacent a) { adj = std::move(a);}
|
||||
// inline void SetVal(int32_t v) { val = v;}
|
||||
// NodeMap GetNodeMap() {
|
||||
// NodeMap result;
|
||||
// BuildNodeMap(&result);
|
||||
// return result;
|
||||
// }
|
||||
// void BuildNodeMap(NodeMap & nodeMap, Node * startNode=nullptr) {
|
||||
// auto list = startNode == nullptr ? adj : startNode->adj;
|
||||
// for (const auto & node : list) {
|
||||
// if (!nodeMap.count(node->val)) {
|
||||
// nodeMap[node->val] = node;
|
||||
// BuildNodeMap(nodeMap, startNode);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// protected:
|
||||
// int32_t val;
|
||||
// Adjacent adj;
|
||||
// Edges edges;
|
||||
// };
|
||||
//
|
||||
// struct GraphData {
|
||||
// GraphData() = default;
|
||||
// explicit GraphData(const Node & n)
|
||||
// {
|
||||
// graphEdges n.edges;
|
||||
// for (const auto & edge : n.edges) {
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Implement subscript operators for unordered_multimap
|
||||
// struct GraphEdges {
|
||||
// Edges * operator[](int32_t nodeVal) {
|
||||
// auto found = graphEdges.find(nodeVal):
|
||||
// if (found != graphEdges.end()) {
|
||||
// return &*found->second;
|
||||
// }
|
||||
// else {
|
||||
// return nullptr;
|
||||
// }
|
||||
// }
|
||||
// std::unordered_multimap<int32_t, Edges *> graphEdges;
|
||||
// };
|
||||
//
|
||||
// // Implement subscript operators for unordered_map
|
||||
// struct GraphNodes {
|
||||
// Node * operator[](int32_t nodeVal) {
|
||||
// auto found = graphNodes.find(nodeVal):
|
||||
// if (found != graphNodes.end()) {
|
||||
// return &*found->second;
|
||||
// }
|
||||
// else {
|
||||
// return nullptr;
|
||||
// }
|
||||
// }
|
||||
// std::unordered_map<int32_t, Node *> graphNodes;
|
||||
// };
|
||||
// // unordered_* provides O(1) access and search
|
||||
// GraphEdges graphEdges;
|
||||
// GraphNodes graphNodes;
|
||||
// };
|
||||
//
|
||||
// class Graph {
|
||||
// // Class is private by default
|
||||
// Node root;
|
||||
// std::unordered_map<int32_t, Node *> graphNodes;
|
||||
// std::multimap<int32_t, Edges> graphEdges;
|
||||
//// std::unordered_map<int32_t, Node *> graphNodes;
|
||||
//// GraphData data; // Struct containing all graph edges / nodes
|
||||
//
|
||||
// public:
|
||||
// Graph() = default;
|
||||
// explicit Graph(Node r) : root(std::move(r)) { }
|
||||
//
|
||||
// inline const Node & GetRoot() const { return root;}
|
||||
//// inline Node * GetNode(int32_t nodeVal) { return data.graphNodes[nodeVal];}
|
||||
//// inline const Node * GetConstNode(int32_t nodeVal)
|
||||
//// { return data.graphNodes[nodeVal];}
|
||||
//
|
||||
// const Node * DFS(int32_t nodeVal, int32_t startNode=INT32_MIN)
|
||||
// {
|
||||
// // If startNode was not set, begin search from root node
|
||||
// startNode = startNode == INT32_MIN ? root.val : startNode;
|
||||
// if (startNode == nodeVal) {
|
||||
// return graphNodes[nodeVal];
|
||||
// }
|
||||
// for (const auto & edge : root.edges) {
|
||||
// return DFS(nodeVal, edge.to);
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
//}
|
||||
|
||||
#endif // GRAPHS_LIB_GRAPH_HPP
|
||||
@@ -11,7 +11,7 @@ cmake_minimum_required(VERSION 3.15)
|
||||
project(
|
||||
#[[NAME]] Klips
|
||||
VERSION 1.0
|
||||
DESCRIPTION "A root project for several small cpp practice projects"
|
||||
DESCRIPTION "A root project for several small Qt6 practice projects"
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
@@ -19,4 +19,6 @@ 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
@@ -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.
|
||||
|
||||
|
||||

|
||||
|
||||
|
||||

|
||||
110
cpp/qt/designer-plugin-collection/CMakeLists.txt
Normal 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
|
||||
)
|
||||
6
cpp/qt/designer-plugin-collection/app-dir.h
Normal 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
|
||||
6
cpp/qt/designer-plugin-collection/app-dir.h.in
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef APPDIR_H_IN
|
||||
#define APPDIR_H_IN
|
||||
|
||||
#define APP_DIR "@APP_DIR@"
|
||||
|
||||
#endif // APPDIR_H_IN
|
||||
18
cpp/qt/designer-plugin-collection/main.cpp
Normal 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();
|
||||
}
|
||||
10
cpp/qt/designer-plugin-collection/textview.cpp
Normal 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"
|
||||
44
cpp/qt/designer-plugin-collection/textview.h
Normal 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
|
||||
10
cpp/qt/designer-plugin-collection/treeview.cpp
Normal 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"
|
||||
36
cpp/qt/designer-plugin-collection/treeview.h
Normal 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
|
||||
15
cpp/qt/designer-plugin-collection/widgetapp.cpp
Normal 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);
|
||||
}
|
||||
37
cpp/qt/designer-plugin-collection/widgetapp.h
Normal 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
|
||||
107
cpp/qt/designer-plugin-collection/widgetapp.ui
Normal 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>
|
||||
52
cpp/qt/designer-plugin-collection/widgetplugin.cpp
Normal 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;
|
||||
}
|
||||
52
cpp/qt/designer-plugin-collection/widgetplugin.h
Normal 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
|
||||
28
cpp/qt/designer-plugin-collection/widgetplugincollection.cpp
Normal 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;
|
||||
}
|
||||
22
cpp/qt/designer-plugin-collection/widgetplugincollection.h
Normal 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
|
||||
76
cpp/qt/designer-plugin/CMakeLists.txt
Normal 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
|
||||
)
|
||||
18
cpp/qt/designer-plugin/main.cpp
Normal 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();
|
||||
}
|
||||
10
cpp/qt/designer-plugin/text-view.cpp
Normal 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/designer-plugin/text-view.h
Normal 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
|
||||
16
cpp/qt/designer-plugin/widget-app.cpp
Normal 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);
|
||||
}
|
||||
38
cpp/qt/designer-plugin/widget-app.h
Normal 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
|
||||
33
cpp/qt/designer-plugin/widget-app.ui
Normal 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>
|
||||
67
cpp/qt/designer-plugin/widget-plugin.cpp
Normal 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;
|
||||
}
|
||||
45
cpp/qt/designer-plugin/widget-plugin.h
Normal 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
|
||||
@@ -1,186 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 8.0.1, 2022-12-17T17:29:08. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
<value type="QByteArray">{ce8a8d3d-318d-4c62-a573-71d1755252ce}</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
||||
<value type="qlonglong">0</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.EditorSettings</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
|
||||
<value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
|
||||
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
|
||||
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
|
||||
<value type="QString" key="language">Cpp</value>
|
||||
<valuemap type="QVariantMap" key="value">
|
||||
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
|
||||
</valuemap>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
|
||||
<value type="QString" key="language">QmlJS</value>
|
||||
<valuemap type="QVariantMap" key="value">
|
||||
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
|
||||
</valuemap>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="EditorConfiguration.CodeStyle.Count">2</value>
|
||||
<value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
|
||||
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
|
||||
<value type="int" key="EditorConfiguration.IndentSize">4</value>
|
||||
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
|
||||
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
|
||||
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
|
||||
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
|
||||
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
|
||||
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
|
||||
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
|
||||
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
|
||||
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
|
||||
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
|
||||
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
|
||||
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
|
||||
<value type="int" key="EditorConfiguration.TabSize">8</value>
|
||||
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
|
||||
<value type="bool" key="EditorConfiguration.UseIndenter">false</value>
|
||||
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
|
||||
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
|
||||
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
|
||||
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
|
||||
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
|
||||
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
|
||||
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.PluginSettings</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<valuemap type="QVariantMap" key="AutoTest.ActiveFrameworks">
|
||||
<value type="bool" key="AutoTest.Framework.Boost">true</value>
|
||||
<value type="bool" key="AutoTest.Framework.CTest">false</value>
|
||||
<value type="bool" key="AutoTest.Framework.Catch">true</value>
|
||||
<value type="bool" key="AutoTest.Framework.GTest">true</value>
|
||||
<value type="bool" key="AutoTest.Framework.QtQuickTest">true</value>
|
||||
<value type="bool" key="AutoTest.Framework.QtTest">true</value>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="AutoTest.CheckStates"/>
|
||||
<value type="int" key="AutoTest.RunAfterBuild">0</value>
|
||||
<value type="bool" key="AutoTest.UseGlobal">true</value>
|
||||
<valuemap type="QVariantMap" key="ClangTools">
|
||||
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
|
||||
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
|
||||
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
|
||||
<value type="int" key="ClangTools.ParallelJobs">4</value>
|
||||
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
|
||||
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
|
||||
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
|
||||
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
|
||||
</valuemap>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.Target.0</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<value type="QString" key="DeviceType">Desktop</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Qt 6.3.1 GCC 64bit</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Qt 6.3.1 GCC 64bit</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{6ade7dd7-47b1-42f6-b09c-570bb7fbeb1c}</value>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||
<value type="QString" key="CMake.Build.Type">Debug</value>
|
||||
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_GENERATOR:STRING=Ninja
|
||||
-DCMAKE_BUILD_TYPE:STRING=Debug
|
||||
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake
|
||||
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
|
||||
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
|
||||
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
|
||||
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
|
||||
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}</value>
|
||||
<value type="QString" key="CMake.Source.Directory">/home/kapper/Code/klips/cpp/qt/designer</value>
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/kapper/Code/klips/cpp/qt/designer/cmake-build-debug</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
|
||||
<value type="QString">all</value>
|
||||
</valuelist>
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
|
||||
<value type="QString">clean</value>
|
||||
</valuelist>
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
|
||||
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
|
||||
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
|
||||
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
|
||||
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Debug</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeBuildConfiguration</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
|
||||
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
|
||||
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
|
||||
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
||||
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
||||
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.TargetCount</variable>
|
||||
<value type="qlonglong">1</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
|
||||
<value type="int">22</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>Version</variable>
|
||||
<value type="int">22</value>
|
||||
</data>
|
||||
</qtcreator>
|
||||
BIN
cpp/qt/plugin-render-view.png
Normal file
|
After Width: | Height: | Size: 83 KiB |
BIN
cpp/qt/side-panel-view.png
Normal file
|
After Width: | Height: | Size: 30 KiB |
@@ -22,7 +22,7 @@ public:
|
||||
|
||||
public:
|
||||
signals:
|
||||
void sendTest();
|
||||
void sendTest()QWidget;
|
||||
|
||||
private:
|
||||
signals:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Dotnet
|
||||
# dotnet
|
||||
|
||||
```bash
|
||||
shaunrd0/klips/dotnet/
|
||||
|
||||
38
esp/cpp/01_led-button/01_led-button.ino
Normal 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;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
9
esp/cpp/01_led-button/README.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# 01_led-button
|
||||
|
||||
This example is largely adapted from those 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).
|
||||
|
||||

|
||||
|
||||
Simple LED controlled by an on-board button.
|
||||
BIN
esp/cpp/01_led-button/schematic.png
Normal file
|
After Width: | Height: | Size: 304 KiB |
183
esp/cpp/02_led-button-web/02_led-button-web.ino
Normal 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("");
|
||||
}
|
||||
}
|
||||
15
esp/cpp/02_led-button-web/README.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# 02_led-button-web
|
||||
|
||||
This example is largely adapted from those 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).
|
||||
|
||||

|
||||
|
||||
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).
|
||||
|
||||

|
||||
BIN
esp/cpp/02_led-button-web/schematic.png
Normal file
|
After Width: | Height: | Size: 304 KiB |
BIN
esp/cpp/02_led-button-web/screenshot.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
161
esp/cpp/03_temp-humidity-web/03_temp-humidity-web.ino
Normal 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">°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">%</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(){
|
||||
|
||||
}
|
||||
60
esp/cpp/03_temp-humidity-web/README.md
Normal file
@@ -0,0 +1,60 @@
|
||||
# 03_temp-humidity-web
|
||||
|
||||
This example is largely adapted from those 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).
|
||||
|
||||

|
||||
|
||||
Temperature and humidity sensor served on a web page within the local network.
|
||||
|
||||

|
||||
|
||||
## 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
|
||||
```
|
||||
BIN
esp/cpp/03_temp-humidity-web/schematic.png
Normal file
|
After Width: | Height: | Size: 238 KiB |
BIN
esp/cpp/03_temp-humidity-web/screenshot.png
Normal file
|
After Width: | Height: | Size: 33 KiB |
4
esp/cpp/04_esp-idf-arduino/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
build
|
||||
managed_components
|
||||
dependencies.lock
|
||||
sdkconfig.old
|
||||
18
esp/cpp/04_esp-idf-arduino/CMakeLists.txt
Normal 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)
|
||||
81
esp/cpp/04_esp-idf-arduino/README.md
Normal file
@@ -0,0 +1,81 @@
|
||||
# 04_esp-idf-arduino
|
||||
|
||||
There is no schematic for this example, it simply prints some output to the serial monitor at 115200.
|
||||
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
|
||||
# See Dependencies section below for instructions.
|
||||
source ~/path/to/esp-idf/export.sh
|
||||
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make -j $(nproc)
|
||||
|
||||
# Flash the example to the ESP.
|
||||
make flash
|
||||
|
||||
# Check the serial monitor for 'Hello world!' output.
|
||||
idf.py monitor -b 115200
|
||||
```
|
||||
|
||||
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
|
||||
|
||||
Install the [ESP-IDF](https://github.com/espressif/esp-idf?tab=readme-ov-file#setup-build-environment)
|
||||
|
||||
```bash
|
||||
# https://docs.espressif.com/projects/esp-idf/en/v5.3.2/esp32/get-started/linux-macos-setup.html#for-linux-users
|
||||
sudo apt-get install -y git wget flex bison gperf python3 python3-pip python3-venv cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0
|
||||
|
||||
git clone -b v5.3.2 --recursive https://github.com/espressif/esp-idf
|
||||
cd esp-idf
|
||||
./install.sh
|
||||
. ./export.sh
|
||||
```
|
||||
|
||||
In CLion there is an official [Serial Monitor](https://plugins.jetbrains.com/plugin/8031-serial-port-monitor) plugin, or use ESP-IDF -
|
||||
|
||||
```bash
|
||||
idf.py monitor -b 115200
|
||||
```
|
||||
|
||||
## Starting Over
|
||||
|
||||
To set up this project from scratch the following commands were used
|
||||
|
||||
```bash
|
||||
# My example project directory
|
||||
cd ~/Code/klips/esp/cpp/04_esp-idf-arduino
|
||||
idf.py set-target esp32
|
||||
idf.py add-dependency "espressif/arduino-esp32^3.1.1"
|
||||
|
||||
# Autostart Arduino for use of `loop()` and `setup()` functions
|
||||
# You can also use the esp-idf `app_main()` function if preferred
|
||||
# https://docs.espressif.com/projects/arduino-esp32/en/latest/esp-idf_component.html#configuration
|
||||
# You can alternatively do this in the GUI tool `idf.py menuconfig`
|
||||
echo "CONFIG_AUTOSTART_ARDUINO=y" >> sdkconfig
|
||||
sed -i -e 's/CONFIG_FREERTOS_HZ=100/CONFIG_FREERTOS_HZ=1000/' sdkconfig
|
||||
|
||||
# Build the project
|
||||
idf.py build
|
||||
```
|
||||
|
||||
To set this project up in CLion, see [JetBrains documentation](https://www.jetbrains.com/help/clion/esp-idf.html#env-vars).
|
||||
4
esp/cpp/04_esp-idf-arduino/main/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
idf_component_register(
|
||||
SRCS "main.cpp"
|
||||
INCLUDE_DIRS "."
|
||||
)
|
||||
17
esp/cpp/04_esp-idf-arduino/main/idf_component.yml
Normal 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
|
||||
10
esp/cpp/04_esp-idf-arduino/main/main.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.println("Hello world!");
|
||||
delay(1000);
|
||||
}
|
||||
2405
esp/cpp/04_esp-idf-arduino/sdkconfig
Normal file
4
esp/cpp/05_temp-humidity-web/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
build
|
||||
managed_components
|
||||
dependencies.lock
|
||||
sdkconfig.old
|
||||
18
esp/cpp/05_temp-humidity-web/CMakeLists.txt
Normal 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]] temp-humidity-web
|
||||
VERSION 0.1
|
||||
DESCRIPTION "Temperature and humidity from DHT sensor served on a web page"
|
||||
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)
|
||||
27
esp/cpp/05_temp-humidity-web/README.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# 05_temp-humidity-web
|
||||
|
||||
This is the same example in [03_temp-humidity-web](./../03_temp-humidity-web), ported to the cmake ESP-IDF build system.
|
||||
|
||||
For instructions on setting up the ESP-IDF see [04_-esp-idf-arduino](./../04_esp-idf-arduino)
|
||||
|
||||
This example is largely adapted from those 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).
|
||||
|
||||

|
||||
|
||||
Temperature and humidity sensor served on a web page within the local network.
|
||||
|
||||

|
||||
|
||||
To build this example run the following commands.
|
||||
|
||||
```bash
|
||||
source ~/path/to/esp-idf/export.sh
|
||||
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make -j $(nproc)
|
||||
make flash
|
||||
```
|
||||
4
esp/cpp/05_temp-humidity-web/main/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
idf_component_register(
|
||||
SRCS "main.cpp"
|
||||
INCLUDE_DIRS "."
|
||||
)
|
||||
19
esp/cpp/05_temp-humidity-web/main/idf_component.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
## 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
|
||||
zorxx/dht: ^1.0.1
|
||||
esp32async/espasyncwebserver: ^3.7.0~1
|
||||
189
esp/cpp/05_temp-humidity-web/main/main.cpp
Normal file
@@ -0,0 +1,189 @@
|
||||
#include "WiFi.h"
|
||||
#include "ESPAsyncWebServer.h"
|
||||
#include "main.h"
|
||||
|
||||
// Replace with your network credentials
|
||||
const char *ssid = "wifi";
|
||||
const char *password = "password";
|
||||
|
||||
#define DHTPIN GPIO_NUM_4 // Digital pin connected to the DHT sensor
|
||||
|
||||
// Uncomment the type of sensor in use:
|
||||
#define DHTTYPE DHT_TYPE_DHT11 // DHT 11
|
||||
//#define DHTTYPE DHT_TYPE_DHT22 // DHT 22 (AM2302)
|
||||
//#define DHTTYPE DHT_TYPE_DHT21 // DHT 21 (AM2301)
|
||||
|
||||
float DHT::readTemperature(bool f)
|
||||
{
|
||||
float humidity = 0;
|
||||
float temperature = 0;
|
||||
esp_err_t result = dht_read_float_data(type_, gpio_, &humidity,
|
||||
&temperature);
|
||||
if (result == ESP_OK) {
|
||||
ESP_LOGI("[DHT::readTemperature]", "Humidity: %.1f%% Temperature: %.1f°C",
|
||||
humidity,
|
||||
temperature);
|
||||
} else {
|
||||
ESP_LOGE("[DHT::readTemperature]", "Failed to read sensor data: %s",
|
||||
esp_err_to_name(result));
|
||||
}
|
||||
return f ? (temperature * 1.8f) + 32 : temperature;
|
||||
}
|
||||
|
||||
float DHT::readHumidity()
|
||||
{
|
||||
float humidity = 0;
|
||||
float temperature = 0;
|
||||
esp_err_t result = dht_read_float_data(type_, gpio_, &humidity,
|
||||
&temperature);
|
||||
if (result == ESP_OK) {
|
||||
ESP_LOGI("[DHT::readTemperature]", "Humidity: %.1f%% Temperature: %.1f°C",
|
||||
humidity,
|
||||
temperature);
|
||||
} else {
|
||||
ESP_LOGE("[DHT::readTemperature]", "Failed to read sensor data: %s",
|
||||
esp_err_to_name(result));
|
||||
}
|
||||
return humidity;
|
||||
}
|
||||
|
||||
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)
|
||||
float t = dht.readTemperature();
|
||||
// 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">°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">%</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);
|
||||
|
||||
// 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(200, "text/html", index_html, processor);
|
||||
});
|
||||
server.on("/temperature", HTTP_GET, [ ](AsyncWebServerRequest *request) {
|
||||
request->send(200, "text/plain", readDHTTemperature().c_str());
|
||||
});
|
||||
server.on("/humidity", HTTP_GET, [ ](AsyncWebServerRequest *request) {
|
||||
request->send(200, "text/plain", readDHTHumidity().c_str());
|
||||
});
|
||||
|
||||
// Start server
|
||||
server.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
}
|
||||
33
esp/cpp/05_temp-humidity-web/main/main.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
|
||||
#include <cstdint>
|
||||
#include "dht.h"
|
||||
|
||||
class DHT {
|
||||
public:
|
||||
DHT(gpio_num_t gpio, dht_sensor_type_t type) :
|
||||
gpio_(gpio), type_(type) { }
|
||||
|
||||
~DHT() = default;
|
||||
|
||||
/**
|
||||
* Read temperature from DHT sensor
|
||||
*
|
||||
* @param f True to return in Fahrenheit, False for Celsius.
|
||||
*/
|
||||
float readTemperature(bool f = true);
|
||||
|
||||
/**
|
||||
* Read humidity from DHT sensor.
|
||||
*/
|
||||
float readHumidity();
|
||||
|
||||
private:
|
||||
gpio_num_t gpio_;
|
||||
dht_sensor_type_t type_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // MAIN_H
|
||||
BIN
esp/cpp/05_temp-humidity-web/schematic.png
Normal file
|
After Width: | Height: | Size: 238 KiB |
BIN
esp/cpp/05_temp-humidity-web/screenshot.png
Normal file
|
After Width: | Height: | Size: 33 KiB |
2415
esp/cpp/05_temp-humidity-web/sdkconfig
Normal file
BIN
esp/cpp/ESP32-basic-starter-kit.pdf
Normal file
BIN
esp/cpp/ESP32-dev-module.png
Normal file
|
After Width: | Height: | Size: 66 KiB |
20
esp/cpp/README.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# 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.
|
||||
├── 04_esp-idf-arduino # CMake example instead of Arduino IDE for ESP development.
|
||||
├── 05_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
|
||||
```
|
||||
|
||||
Examples 1-3 are built using the Arduino IDE.
|
||||
|
||||
All examples after `04_esp-idf-arduino` are built with cmake and the [ESP-IDF](https://github.com/espressif/esp-idf).
|
||||
|
||||
[Arduino ESP32 GitHub](https://github.com/espressif/arduino-esp32) \
|
||||
[Arduino ESP32 API reference](https://docs.espressif.com/projects/arduino-esp32/en/latest/libraries.html)
|
||||
@@ -1,9 +1,9 @@
|
||||
# Javascript
|
||||
# javascript
|
||||
|
||||
This directory contains Javascript projects and examples that I've made.
|
||||
|
||||
```
|
||||
github.com/shaunrd0/klips/javascript
|
||||
```bash
|
||||
shaunrd0/klips/javascript
|
||||
├── webgl # Examples of using WebGL within JS
|
||||
└── README.md
|
||||
```
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
# python
|
||||
|
||||
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.
|
||||
|
||||
To install Python 3.9 and `pip`
|
||||
|
||||
```bash
|
||||
sudo apt install python3.9 python3-pip
|
||||
sudo apt install python3.9 python3-pip
|
||||
python3.9 -m pip install -U pip
|
||||
```
|
||||
|
||||
|
||||