Skip to content

Commit

Permalink
move drop down select list(s) for camera type to camera.hpp
Browse files Browse the repository at this point in the history
fetch camera type from cpp (in qml)
renames geekworm to hdmi to csi
  • Loading branch information
Consti10 committed Apr 4, 2024
1 parent 93ef6a5 commit 4a1a31a
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 178 deletions.
2 changes: 1 addition & 1 deletion app/telemetry/models/aohdsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ void AOHDSystem::process_onboard_computer_status(const mavlink_onboard_computer_
set_air_reported_fc_sys_id(air_reported_sys_id);
const uint8_t ohd_platform=msg.link_type[0];
set_ohd_platform(ohd_platform);
const auto platform_as_str=openhd::x_platform_type_to_string(ohd_platform);
const auto platform_as_str=x_platform_type_to_string(ohd_platform);
set_ohd_platform_type_as_string(platform_as_str.c_str());
}

Expand Down
45 changes: 45 additions & 0 deletions app/telemetry/models/camerastreammodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,48 @@ std::string CameraStreamModel::resolution_framerate_to_string(const ResolutionFr
ss<<(int)data.width<<"x"<<(int)data.height<<"@"<<data.framerate;
return ss.str();
}

QVariantList CameraStreamModel::get_camera_choices(int platform_type)
{
QList<QCameraNameAndType> list{
QCameraNameAndType{"XLOL",1}
};
auto tmp= QManufacturerForPlatform{
"LOL",
list
};
QVariantList ret;
return ret;
}

QStringList CameraStreamModel::get_manufacturer_choices(int platform_type)
{
auto all_choices=get_camera_choices_for_platform(platform_type,m_camera_index!=0);
QStringList ret;
for(auto& choice: all_choices){
ret.push_back(choice.manufacturer_name.c_str());
}
return ret;
}

QList<int> CameraStreamModel::get_manufacturer_cameras_type(int platform_type, int index)
{
auto all_choices=get_camera_choices_for_platform(platform_type,m_camera_index!=0);
QList<int> ret;
if(index>=all_choices.size())index=0;
for(auto& choice: all_choices[index].cameras){
ret.push_back(choice.type);
}
return ret;
}

QStringList CameraStreamModel::get_manufacturer_cameras_names(int platform_type, int index)
{
auto all_choices=get_camera_choices_for_platform(platform_type,m_camera_index!=0);
QStringList ret;
if(index>=all_choices.size())index=0;
for(auto& choice: all_choices[index].cameras){
ret.push_back(choice.name.c_str());
}
return ret;
}
17 changes: 17 additions & 0 deletions app/telemetry/models/camerastreammodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@
#define AIRCAMERAMODEL_H

#include <QObject>
#include <QVariant>

#include "../tutil/mavlink_include.h"

#include "util/lqutils_include.h"

struct QCameraNameAndType{
QString name;
int type;
};
struct QManufacturerForPlatform{
QString manufacturer_name;
QList<QCameraNameAndType> cameras;
};
Q_DECLARE_METATYPE(QCameraNameAndType);
Q_DECLARE_METATYPE(QManufacturerForPlatform);

// NOTE1: This class exists to avoid duplicated code for primary and secondary camera(stream)-stats displayed in the HUD
// NOTE2: Here we have only stats for one camera / camera stream that are transmitted via lossy
// telemetry messages, aka in regular intervalls.
Expand Down Expand Up @@ -114,6 +126,11 @@ class CameraStreamModel : public QObject
private:
std::chrono::steady_clock::time_point m_last_tx_frame_drop_calculation=std::chrono::steady_clock::now();
int m_last_tx_frame_drop_calculation_count=-1;
public:
Q_INVOKABLE QVariantList get_camera_choices(int platform_type);
Q_INVOKABLE QStringList get_manufacturer_choices(int platform_type);
Q_INVOKABLE QList<int> get_manufacturer_cameras_type(int platform_type,int index);
Q_INVOKABLE QStringList get_manufacturer_cameras_names(int platform_type,int index);
};

#endif // AIRCAMERAMODEL_H
128 changes: 128 additions & 0 deletions app/telemetry/models/openhd_core/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <string>
#include <vector>

#include "platform.hpp"

/**
* NOTE: This file is copied into QOpenHD to populate the UI.
*/
Expand Down Expand Up @@ -79,6 +81,8 @@ static constexpr int X_CAM_TYPE_X20_RUNCAM_NANO = 70;
//
static constexpr int X_CAM_TYPE_ROCK_HDMI_IN = 80;
static constexpr int X_CAM_TYPE_ROCK_IMX219 = 81;
static constexpr int X_CAM_TYPE_ROCK_RK3566_PLACEHOLDER1 = 82;
static constexpr int X_CAM_TYPE_ROCK_RK3566_PLACEHOLDER2 = 83;
//
// OpenIPC specific starts here
static constexpr int X_CAM_TYPE_OPENIPC_SOMETHING = 90;
Expand Down Expand Up @@ -146,6 +150,10 @@ static std::string x_cam_type_to_string(int camera_type) {
return "ROCK_HDMI_IN";
case X_CAM_TYPE_ROCK_IMX219:
return "ROCK_IMX219";
case X_CAM_TYPE_ROCK_RK3566_PLACEHOLDER1:
return "ROCK_PLACEHOLDER1";
case X_CAM_TYPE_ROCK_RK3566_PLACEHOLDER2:
return "ROCK_PLACEHOLDER2";
case X_CAM_TYPE_DISABLED:
return "DISABLED";
case X_CAM_TYPE_OPENIPC_SOMETHING:
Expand Down Expand Up @@ -297,6 +305,19 @@ struct XCamera {
ret.push_back(ResolutionFramerate{1280, 720, 60});
ret.push_back(ResolutionFramerate{1920, 1080, 60});
return ret;
} else if (camera_type == X_CAM_TYPE_ROCK_IMX219) {
std::vector<ResolutionFramerate> ret;
ret.push_back(ResolutionFramerate{640, 480, 30});
ret.push_back(ResolutionFramerate{848, 480, 30});
ret.push_back(ResolutionFramerate{1280, 720, 30});
ret.push_back(ResolutionFramerate{1920, 1080, 30});
return ret;
} else if (camera_type == X_CAM_TYPE_ROCK_HDMI_IN) {
// Standard hdmi in resolutions for now
std::vector<ResolutionFramerate> ret;
ret.push_back(ResolutionFramerate{1280, 720, 60});
ret.push_back(ResolutionFramerate{1920, 1080, 60});
return ret;
}
// Not mapped yet
// return something that might work or might not work
Expand Down Expand Up @@ -399,4 +420,111 @@ static std::string get_v4l2_device_name_string(int value) {
return ss.str();
}

/**
* On platforms with many cameras (e.g. rpi) we need a differentiation by
* manufacturer to make a nice UI - otherwise, the choices are overwhelming.
* Manufacturer is not really the right name for all categories that result
* here, but it is 'okay' for the UI in qopenhd.
*/
struct CameraNameAndType {
std::string name;
int type;
};
struct ManufacturerForPlatform {
std::string manufacturer_name;
std::vector<CameraNameAndType> cameras;
};
/**
* Return: a list of categories for this platform.
* Each category has a list of valid camera types (for this platform).
* @param platform_type unique platform type
* @param is_secondary selection is different for secondary cam,most notably, we
* only support usb, develop and a 'disabled' type.
*/
static std::vector<ManufacturerForPlatform> get_camera_choices_for_platform(
int platform_type, bool is_secondary) {
std::vector<CameraNameAndType> usb_cameras{
CameraNameAndType{"INFIRAY USB", X_CAM_TYPE_USB_INFIRAY},
CameraNameAndType{"INFIRAY USB T2", X_CAM_TYPE_USB_INFIRAY_T2},
CameraNameAndType{"EXP USB GENERIC", X_CAM_TYPE_USB_GENERIC}};
ManufacturerForPlatform MANUFACTURER_USB{"USB", usb_cameras};
std::vector<CameraNameAndType> debug_cameras{
CameraNameAndType{"Dummy (debug)", 0},
CameraNameAndType{"External (DEV)", 2},
// CameraNameAndType{"External IP (DEV)",3},
CameraNameAndType{"DEV Filecamera", 4},
};
ManufacturerForPlatform MANUFACTURER_DEBUG{"DEV/DEBUG", debug_cameras};
// Secondary can only be used with USB and / or the debug cameras. CSI is not
// usable for secondary.
if (is_secondary) {
// Not really a manufacturer, but ui looks okay with this
std::vector<CameraNameAndType> disable_camera{
CameraNameAndType{"DISABLE", X_CAM_TYPE_DISABLED},
};
ManufacturerForPlatform MANUFACTURER_DISABLE{"DISABLE", disable_camera};
return std::vector<ManufacturerForPlatform>{
MANUFACTURER_DISABLE, MANUFACTURER_USB, MANUFACTURER_DEBUG};
}
if (platform_type == X_PLATFORM_TYPE_RPI_OLD ||
platform_type == X_PLATFORM_TYPE_RPI_4 ||
platform_type == X_PLATFORM_TYPE_RPI_CM4) {
std::vector<CameraNameAndType> arducam_cameras{
CameraNameAndType{"SKYMASTERHDR", 40},
CameraNameAndType{"SKYVISIONPRO", 41},
CameraNameAndType{"IMX477m", 42},
CameraNameAndType{"IMX462", 43},
CameraNameAndType{"IMX327", 44},
CameraNameAndType{"IMX290", 45},
CameraNameAndType{"IMX462_LOWLIGHT_MINI", 46}};
std::vector<CameraNameAndType> veye_cameras{
CameraNameAndType{"2MP", 60},
CameraNameAndType{"CSIMX307", 61},
CameraNameAndType{"CSSC132", 62},
CameraNameAndType{"MVCAM", 63},
};
std::vector<CameraNameAndType> rpif_cameras{
CameraNameAndType{"V1 OV5647", 30},
CameraNameAndType{"V2 IMX219", 31},
CameraNameAndType{"V3 IMX708", 32},
CameraNameAndType{"HQ IMX477", 33},
};
std::vector<CameraNameAndType> hdmi_to_csi_cameras{
CameraNameAndType{"GENERIC HDMI to CSI", 20}};
return std::vector<ManufacturerForPlatform>{
ManufacturerForPlatform{"ARDUCAM", arducam_cameras},
ManufacturerForPlatform{"VEYE", veye_cameras},
ManufacturerForPlatform{"RPI FOUNDATION", rpif_cameras},
ManufacturerForPlatform{"HDMI TO CSI", hdmi_to_csi_cameras},
MANUFACTURER_USB,
MANUFACTURER_DEBUG};
} else if (platform_type == X_PLATFORM_TYPE_ALWINNER_X20) {
std::vector<CameraNameAndType> runcam_cameras{
CameraNameAndType{"RUNCAM NANO", X_CAM_TYPE_X20_RUNCAM_NANO},
};
return std::vector<ManufacturerForPlatform>{
ManufacturerForPlatform{"RUNCAM", runcam_cameras}};
} else if (platform_type == X_PLATFORM_TYPE_ROCKCHIP_RK3566_RADXA_ZERO3W) {
std::vector<CameraNameAndType> arducam_cameras{
CameraNameAndType{"IMX219", X_CAM_TYPE_ROCK_IMX219},
CameraNameAndType{"PLACEHOLDER1", X_CAM_TYPE_ROCK_RK3566_PLACEHOLDER1},
CameraNameAndType{"PLACEHOLDER2", X_CAM_TYPE_ROCK_RK3566_PLACEHOLDER2},
};
return std::vector<ManufacturerForPlatform>{
ManufacturerForPlatform{"ARDUCAM", arducam_cameras}, MANUFACTURER_USB,
MANUFACTURER_DEBUG};
} else if (platform_type == X_PLATFORM_TYPE_ROCKCHIP_RK3588_RADXA_ROCK5) {
std::vector<CameraNameAndType> hdmi_cameras{
CameraNameAndType{"HDMI IN", X_CAM_TYPE_ROCK_HDMI_IN},
};
return std::vector<ManufacturerForPlatform>{
ManufacturerForPlatform{"HDMI IN", hdmi_cameras}, MANUFACTURER_USB,
MANUFACTURER_DEBUG};
} else if (platform_type == X_PLATFORM_TYPE_X86) {
return std::vector<ManufacturerForPlatform>{MANUFACTURER_USB,
MANUFACTURER_DEBUG};
}
return std::vector<ManufacturerForPlatform>{MANUFACTURER_DEBUG};
}

#endif // OPENHD_CAMERA_HPP
6 changes: 3 additions & 3 deletions app/telemetry/models/openhd_core/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <string>

namespace openhd{


// When this one shows up a bit more work has to be done to run openhd on the platform (probably) ;)
static constexpr int X_PLATFORM_TYPE_UNKNOWN=0;
Expand All @@ -30,7 +30,7 @@ static constexpr int X_PLATFORM_TYPE_ALWINNER_X20=30;
// @Buldo is working on openipc / sigmastar, 36..40
static constexpr int X_PLATFORM_TYPE_SIGMASTAR_UNDEFINED=36;

std::string x_platform_type_to_string(int platform_type) {
static std::string x_platform_type_to_string(int platform_type) {
switch (platform_type) {
case X_PLATFORM_TYPE_UNKNOWN:return "UNKNOWN";
case X_PLATFORM_TYPE_X86:return "X86";
Expand All @@ -49,7 +49,7 @@ std::string x_platform_type_to_string(int platform_type) {
}
return "ERR-UNDEFINED";
}
}




Expand Down
Loading

0 comments on commit 4a1a31a

Please sign in to comment.