Skip to content

Commit

Permalink
Merge pull request #85 from MK16kawai/dev
Browse files Browse the repository at this point in the history
update tof100&lvglcfg&tmc2209&camera
  • Loading branch information
Neutree authored Jan 11, 2025
2 parents 6c5440e + d195698 commit ab43515
Show file tree
Hide file tree
Showing 21 changed files with 1,553 additions and 144 deletions.
2 changes: 2 additions & 0 deletions components/3rd_party/lvgl/src/maix_lvgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "maix_basic.hpp"

#include "pointing_device.hpp"
#include "lv_indev_private.h"

// extern "C" {
// #include "cursor_48.c"
Expand Down Expand Up @@ -99,6 +100,7 @@ namespace maix
* Use the 'mouse' driver which reads the PC's mouse*/
#if CONFIG_LVGL_USE_MOUSE
lv_indev_t * indev = lv_indev_create();
indev->long_press_repeat_time = 100;
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
pointing_device_init(indev);
lv_indev_set_read_cb(indev, pointing_device_read);
Expand Down
12 changes: 8 additions & 4 deletions components/ext_devs/ext_dev/include/maix_tmc2209.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include <memory>
#include <string>
#include <cmath>
#include "TMC2209.h"
#include "maix_basic.hpp"
#include <functional>

namespace maix::ext_dev::tmc2209 {
class TMC2209;

namespace maix::ext_dev::tmc2209 {

template<typename T>
class SlideErrorHandler {
Expand Down Expand Up @@ -138,6 +138,8 @@ class Slide {
Slide(Slide&&) = default;
Slide& operator=(Slide&&) = default;

~Slide();

/**
* @brief Load configuration from a file
*
Expand Down Expand Up @@ -225,7 +227,7 @@ class Slide {
uint8_t stop_default_per_;

private:
std::unique_ptr<TMC2209> tmc2209;
std::unique_ptr<TMC2209> tmc2209{nullptr};
float step_angle;
uint16_t micro_step;
float round_mm;
Expand Down Expand Up @@ -275,6 +277,8 @@ class ScrewSlide {
ScrewSlide(ScrewSlide&&) = default;
ScrewSlide& operator=(ScrewSlide&&) = default;

~ScrewSlide();

/**
* @brief Move the slide by a specified length
*
Expand Down Expand Up @@ -334,7 +338,7 @@ class ScrewSlide {


private:
std::unique_ptr<TMC2209> tmc2209;
std::unique_ptr<TMC2209> tmc2209{nullptr};
float step_angle;
uint16_t micro_step;
float screw_pitch;
Expand Down
5 changes: 5 additions & 0 deletions components/ext_devs/ext_dev/src/tmc2209/maix_tmc2209.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <fstream>
#include <deque>
#include <memory>
#include "TMC2209.h"

namespace maix::ext_dev::tmc2209 {

Expand Down Expand Up @@ -572,6 +573,8 @@ Slide::Slide(const char* port, uint8_t addr, long baud, /* Uart init param */
this->tmc2209->setMicrostepsPerStep(micro_step);
}

Slide::~Slide() {}

void Slide::load_conf(std::string path)
{
if (path.empty()) {
Expand Down Expand Up @@ -776,6 +779,8 @@ ScrewSlide::ScrewSlide(const char* port, uint8_t addr, long baud, /* Uart init p
this->tmc2209->setMicrostepsPerStep(micro_step);
}

ScrewSlide::~ScrewSlide() {}

void ScrewSlide::move(float oft, int speed_mm_s, std::function<bool(float)> callback)
{
uint16_t speed_factor = (speed_mm_s<=0) ? \
Expand Down
2 changes: 1 addition & 1 deletion components/ext_devs/ext_dev_tof100/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ append_srcs_dir(ADD_SRCS "src")
append_srcs_dir(ADD_SRCS "src/tof100_lib")


list(APPEND ADD_REQUIREMENTS basic peripheral vision)
list(APPEND ADD_REQUIREMENTS basic peripheral vision ext_dev)

# if (PLATFORM_LINUX)
# append_srcs_dir(ADD_SRCS "port/linux")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#ifndef __MAIX_OPNS303x_HPP__
#define __MAIX_OPNS303x_HPP__
#ifndef __MAIX_Tof100_HPP__
#define __MAIX_Tof100_HPP__

#include <vector>
#include <cstdint>
#include <memory>

#include "maix_cmap.hpp"
#include "maix_image.hpp"
#include "dragonfly.h"

namespace maix::ext_dev::opns303x {
namespace maix::ext_dev::tof100 {

#if CONFIG_BUILD_WITH_MAIXPY
#define TOFMatrix std::vector<std::vector<uint32_t>>
Expand All @@ -20,8 +19,8 @@ namespace maix::ext_dev::opns303x {
#endif

/**
* @brief Opns303x Resolution
* @maixpy maix.ext_dev.opns303x.Resolution
* @brief Tof100 Resolution
* @maixpy maix.ext_dev.tof100.Resolution
*/
enum class Resolution : uint32_t {
RES_100x100 = 100,
Expand All @@ -30,14 +29,14 @@ enum class Resolution : uint32_t {
};

/**
* @brief Opns303x TOF
* @maixpy maix.ext_dev.opns303x.Opns303x
* @brief Tof100 TOF
* @maixpy maix.ext_dev.tof100.Tof100
*/
class Opns303x final {
class Tof100 final {
public:

/**
* @brief Construct a new Opns303x object
* @brief Construct a new Tof100 object
*
* @param spi_bus_num SPI bus number.
* @param resolution @see Resolution
Expand All @@ -48,10 +47,10 @@ class Opns303x final {
* the maximum distance in the frame is taken as the maximum reference distance,
* and the minimum distance in the frame is taken as the minimum reference distance.
*
* @maixpy maix.ext_dev.opns303x.Opns303x.__init__
* @maixpy maix.ext_dev.tof100.Tof100.__init__
*/
Opns303x(int spi_bus_num,
::maix::ext_dev::opns303x::Resolution resolution=::maix::ext_dev::opns303x::Resolution::RES_50x50,
Tof100(int spi_bus_num,
::maix::ext_dev::tof100::Resolution resolution=::maix::ext_dev::tof100::Resolution::RES_50x50,
::maix::ext_dev::cmap::Cmap cmap=::maix::ext_dev::cmap::Cmap::JET,
int dis_min=-1, int dis_max=-1);

Expand All @@ -60,7 +59,7 @@ class Opns303x final {
*
* @return Matrix containing the distance data, or an empty matrix ([]) if the operation fails.
*
* @maixpy maix.ext_dev.opns303x.Opns303x.matrix
* @maixpy maix.ext_dev.Tof100.Tof100.matrix
*/
TOFMatrix matrix();

Expand All @@ -71,7 +70,7 @@ class Opns303x final {
* It is the responsibility of the caller to free this memory
* in C/C++ to prevent memory leaks.
*
* @maixpy maix.ext_dev.opns303x.Opns303x.image
* @maixpy maix.ext_dev.tof100.Tof100.image
*/
::maix::image::Image* image();

Expand All @@ -82,7 +81,7 @@ class Opns303x final {
* (x, y, distance) of the pixel with the maximum distance.
* If the operation fails, the return values will be x, y < 0.
*
* @maixpy maix.ext_dev.opns303x.Opns303x.max_dis_point
* @maixpy maix.ext_dev.tof100.Tof100.max_dis_point
*/
TOFPoint max_dis_point();

Expand All @@ -93,7 +92,7 @@ class Opns303x final {
* (x, y, distance) of the pixel with the minimum distance.
* If the operation fails, the return values will be x, y < 0.
*
* @maixpy maix.ext_dev.opns303x.Opns303x.min_dis_point
* @maixpy maix.ext_dev.tof100.Tof100.min_dis_point
*/
TOFPoint min_dis_point();

Expand All @@ -104,7 +103,7 @@ class Opns303x final {
* (x, y, distance) of the center pixel in the distance matrix.
* If the operation fails, the return values will be x, y < 0.
*
* @maixpy maix.ext_dev.opns303x.Opns303x.center_point
* @maixpy maix.ext_dev.tof100.Tof100.center_point
*/
TOFPoint center_point();

Expand All @@ -116,7 +115,7 @@ class Opns303x final {
* It is the responsibility of the caller to free this memory
* in C/C++ to prevent memory leaks.
*
* @maixpy maix.ext_dev.opns303x.Opns303x.image_from
* @maixpy maix.ext_dev.tof100.Tof100.image_from
*/
::maix::image::Image* image_from(const TOFMatrix& matrix);

Expand All @@ -128,7 +127,7 @@ class Opns303x final {
* (x, y, distance) of the pixel with the maximum distance.
* If the operation fails, the return values will be x, y < 0.
*
* @maixpy maix.ext_dev.opns303x.Opns303x.max_dis_point_from
* @maixpy maix.ext_dev.tof100.Tof100.max_dis_point_from
*/
static TOFPoint max_dis_point_from(const TOFMatrix& matrix);

Expand All @@ -140,7 +139,7 @@ class Opns303x final {
* (x, y, distance) of the pixel with the minimum distance.
* If the operation fails, the return values will be x, y < 0.
*
* @maixpy maix.ext_dev.opns303x.Opns303x.min_dis_point_from
* @maixpy maix.ext_dev.tof100.Tof100.min_dis_point_from
*/
static TOFPoint min_dis_point_from(const TOFMatrix& matrix);

Expand All @@ -152,7 +151,7 @@ class Opns303x final {
* (x, y, distance) of the center pixel in the matrix.
* If the operation fails, the return values will be x, y < 0.
*
* @maixpy maix.ext_dev.opns303x.Opns303x.center_point_from
* @maixpy maix.ext_dev.tof100.Tof100.center_point_from
*/
static TOFPoint center_point_from(const TOFMatrix& matrix);

Expand All @@ -165,7 +164,7 @@ class Opns303x final {
TOFPoint _dis_min;
TOFPoint _dis_max;
TOFPoint _dis_center;
MSL_BinningMode _mode;
uint32_t _mode;
uint32_t _data_size;
std::unique_ptr<uint8_t[]> _frame_buffer;
uint8_t _quantization_step{0};
Expand All @@ -177,4 +176,4 @@ class Opns303x final {



#endif // __MAIX_OPNS303x_HPP__
#endif // __MAIX_Tof100_HPP__
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "maix_opns303x.hpp"
#include "maix_tof100.hpp"
#include "dragonfly.h"
#include "maix_basic.hpp"
#include "maix_pinmap.hpp"
#include "maix_gpio.hpp"
#include "dragonfly.h"

#include <functional>

Expand All @@ -23,12 +24,12 @@
throw std::runtime_error(std::string(_buff));} while(0)


namespace maix::ext_dev::opns303x {
namespace maix::ext_dev::tof100 {

constexpr TOFPoint empty_point{-1,-1, 0};

const char* TAG() {
return "Maix OPNS303x";
return "Maix Tof100";
}

void _for_each_in_matrix(const TOFMatrix& matrix, std::function<void(int,int,uint32_t)> cb)
Expand All @@ -46,7 +47,7 @@ void _for_each_in_matrix(const TOFMatrix& matrix, std::function<void(int,int,uin
}


Opns303x::Opns303x(int spi_bus_num, Resolution resolution, ::maix::ext_dev::cmap::Cmap cmap, int dis_min, int dis_max)
Tof100::Tof100(int spi_bus_num, Resolution resolution, ::maix::ext_dev::cmap::Cmap cmap, int dis_min, int dis_max)
: _cmap(cmap), _min(dis_min), _max(dis_max), _wh(static_cast<uint32_t>(resolution)), _fps_limit(20) /* FPS: auto */
{

Expand Down Expand Up @@ -87,11 +88,11 @@ Opns303x::Opns303x(int spi_bus_num, Resolution resolution, ::maix::ext_dev::cmap

// msl_process_startup(this->_wh, this->_fps_limit, true);
if (this->_wh == 25) {
this->_mode = MSL_BinningMode2_4x4;
this->_mode = static_cast<uint32_t>(MSL_BinningMode2_4x4);
} else if (this->_wh == 50) {
this->_mode = MSL_BinningMode1_2x2;
this->_mode = static_cast<uint32_t>(MSL_BinningMode1_2x2);
} else if (this->_wh == 100) {
this->_mode = MSL_BinningMode0_1x1;
this->_mode = static_cast<uint32_t>(MSL_BinningMode0_1x1);
}

msl_setup(this->_fps_limit, static_cast<BinningMode>(this->_mode), 1);
Expand All @@ -114,7 +115,7 @@ Opns303x::Opns303x(int spi_bus_num, Resolution resolution, ::maix::ext_dev::cmap

}

TOFMatrix Opns303x::matrix()
TOFMatrix Tof100::matrix()
{
uint8_t* FrameBuf = this->_frame_buffer.get();
int ret = SPII2CBurstDataRead(DATA_BASE_ADDRESS + DATA_OFFSET_ADDRESS,
Expand Down Expand Up @@ -211,27 +212,27 @@ TOFMatrix Opns303x::matrix()
return res;
}

::maix::image::Image* Opns303x::image()
::maix::image::Image* Tof100::image()
{
return this->image_from(this->matrix());
}

TOFPoint Opns303x::max_dis_point()
TOFPoint Tof100::max_dis_point()
{
return this->_dis_max;
}

TOFPoint Opns303x::min_dis_point()
TOFPoint Tof100::min_dis_point()
{
return this->_dis_min;
}

TOFPoint Opns303x::center_point()
TOFPoint Tof100::center_point()
{
return this->_dis_center;
}

::maix::image::Image* Opns303x::image_from(const TOFMatrix& matrix)
::maix::image::Image* Tof100::image_from(const TOFMatrix& matrix)
{
if (matrix.empty()) return nullptr;

Expand Down Expand Up @@ -292,7 +293,7 @@ ::maix::image::Image* Opns303x::image_from(const TOFMatrix& matrix)
return new ::maix::image::Image(this->_wh, this->_wh, image::FMT_RGB888, buffer, this->_data_size*3, true);
}

TOFPoint Opns303x::max_dis_point_from(const TOFMatrix& matrix)
TOFPoint Tof100::max_dis_point_from(const TOFMatrix& matrix)
{
int _x, _y;
uint32_t v = std::numeric_limits<uint32_t>::min();
Expand All @@ -306,7 +307,7 @@ TOFPoint Opns303x::max_dis_point_from(const TOFMatrix& matrix)
return std::make_tuple(_x, _y, v);
}

TOFPoint Opns303x::min_dis_point_from(const TOFMatrix& matrix)
TOFPoint Tof100::min_dis_point_from(const TOFMatrix& matrix)
{
int _x, _y;
uint32_t v = std::numeric_limits<uint32_t>::max();
Expand All @@ -320,7 +321,7 @@ TOFPoint Opns303x::min_dis_point_from(const TOFMatrix& matrix)
return std::make_tuple(_x, _y, v);
}

TOFPoint Opns303x::center_point_from(const TOFMatrix& matrix)
TOFPoint Tof100::center_point_from(const TOFMatrix& matrix)
{
return std::make_tuple(matrix.size()/2, matrix.at(0).size()/2, matrix[matrix.at(0).size()/2][matrix.size()/2]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "dragonfly.h"

#include "tof_adapter.hpp"
#include "cmap_jet.hpp"
// #include "cmap_jet.hpp"

#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
#pragma GCC diagnostic ignored "-Wsign-compare"
Expand Down
Loading

0 comments on commit ab43515

Please sign in to comment.