Skip to content

Commit

Permalink
Updated linux to include getProperty handling
Browse files Browse the repository at this point in the history
  • Loading branch information
trcwm committed Sep 21, 2017
1 parent b5a2d1f commit c517f46
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 9 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ ELSEIF(UNIX)
# Note: We should be able to specify this on the command line, as well, so we don't have
# to hardcode the path here.
ADD_LIBRARY(turbojpeg SHARED IMPORTED)
SET_TARGET_PROPERTIES(turbojpeg PROPERTIES IMPORTED_LOCATION /usr/lib/x86_64-linux-gnu/libturbojpeg.so.0.0.0)
if(EXISTS "/usr/lib/x86_64-linux-gnu/libturbojpeg.so.0.1.0")
SET_TARGET_PROPERTIES(turbojpeg PROPERTIES IMPORTED_LOCATION /usr/lib/x86_64-linux-gnu/libturbojpeg.so.0.1.0)
else()
SET_TARGET_PROPERTIES(turbojpeg PROPERTIES IMPORTED_LOCATION /usr/lib/x86_64-linux-gnu/libturbojpeg.so.0.0.0)
endif()


target_link_libraries(openpnp-capture turbojpeg)

Expand Down
60 changes: 60 additions & 0 deletions linux/platformstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,4 +654,64 @@ bool PlatformStream::getPropertyLimits(uint32_t propID, int32_t *emin, int32_t *
return true;
}

bool PlatformStream::getProperty(uint32_t propID, int32_t &value)
{
v4l2_control ctrl;
CLEAR(ctrl);

switch(propID)
{
case CAPPROPID_EXPOSURE:
ctrl.id = V4L2_CID_EXPOSURE;
break;
case CAPPROPID_FOCUS:
ctrl.id = V4L2_CID_FOCUS_ABSOLUTE;
break;
case CAPPROPID_ZOOM:
ctrl.id = V4L2_CID_ZOOM_ABSOLUTE;
break;
default:
return false;
}

if (xioctl(m_deviceHandle, VIDIOC_G_CTRL, &ctrl)==-1)
{
LOG(LOG_ERR,"getProperty (ID=%d) failed on VIDIOC_G_CTRL (errno %d)\n", propID, errno);
return false;
}

value = ctrl.value;

return true;
}

bool PlatformStream::getAutoProperty(uint32_t propID, bool &enabled)
{
v4l2_control ctrl;
CLEAR(ctrl);

switch(propID)
{
case CAPPROPID_EXPOSURE:
ctrl.id = V4L2_CID_AUTOGAIN;
break;
case CAPPROPID_FOCUS:
ctrl.id = V4L2_CID_FOCUS_AUTO;
break;
case CAPPROPID_WHITEBALANCE:
ctrl.id = V4L2_CID_AUTO_WHITE_BALANCE;
break;
default:
return false;
}

//ctrl.value = enabled ? 1 : 0;
if (xioctl(m_deviceHandle, VIDIOC_G_CTRL, &ctrl)==-1)
{
LOG(LOG_ERR,"getAutoProperty (ID=%d) failed on VIDIOC_G_CTRL (errno %d)\n", propID, errno);
return false;
}

enabled = (ctrl.value != 0);
return true;
}
10 changes: 2 additions & 8 deletions linux/platformstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,8 @@ class PlatformStream : public Stream
virtual bool setAutoProperty(uint32_t propID, bool enabled) override;
virtual bool getPropertyLimits(uint32_t propID, int32_t *min, int32_t *max) override;

#if 0
virtual bool setExposure(int32_t value) override;

virtual bool setAutoExposure(bool enabled) override;

virtual bool getExposureLimits(int32_t *min, int32_t *max) override;
#endif

virtual bool getProperty(uint32_t propID, int32_t &value) override;
virtual bool getAutoProperty(uint32_t propID, bool &enabled) override;

/** called by the capture thread/function to query if it
should quit */
Expand Down
80 changes: 80 additions & 0 deletions linux/tests/gtkmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,75 @@ static void triggerSnapshot(GtkWidget *widget,
printf("Snapshot triggered!\n");
}

void showAutoProperty(CapContext ctx, int32_t streamID, uint32_t propertyID)
{
uint32_t bValue;
if (Cap_getAutoProperty(ctx, streamID, propertyID, &bValue)==CAPRESULT_OK)
{
if (bValue)
{
printf("Auto\n");
}
else
{
printf("Manual\n");
}
}
else
{
printf("Unsupported\n");
}
}

void showAutoProperties(CapContext ctx, int32_t streamID)
{
printf("White balance: ");
showAutoProperty(ctx, streamID, CAPPROPID_WHITEBALANCE);

printf("Exposure : ");
showAutoProperty(ctx, streamID, CAPPROPID_EXPOSURE);

printf("Focus : ");
showAutoProperty(ctx, streamID, CAPPROPID_FOCUS);

printf("Zoom : ");
showAutoProperty(ctx, streamID, CAPPROPID_ZOOM);

printf("Gain : ");
showAutoProperty(ctx, streamID, CAPPROPID_GAIN);
}

void showProperty(CapContext ctx, int32_t streamID, uint32_t propertyID)
{
int32_t value;
if (Cap_getProperty(ctx, streamID, propertyID, &value)==CAPRESULT_OK)
{
printf("%d\n", value);
}
else
{
printf("Unsupported\n");
}
}

void showProperties(CapContext ctx, int32_t streamID)
{
printf("White balance: ");
showProperty(ctx, streamID, CAPPROPID_WHITEBALANCE);

printf("Exposure : ");
showProperty(ctx, streamID, CAPPROPID_EXPOSURE);

printf("Focus : ");
showProperty(ctx, streamID, CAPPROPID_FOCUS);

printf("Zoom : ");
showProperty(ctx, streamID, CAPPROPID_ZOOM);

printf("Gain : ");
showProperty(ctx, streamID, CAPPROPID_GAIN);
}

bool writeBufferAsPPM(uint32_t frameNum, uint32_t width, uint32_t height, const uint8_t *bufferPtr, size_t bytes)
{
char fname[100];
Expand Down Expand Up @@ -205,6 +274,13 @@ gboolean on_key_press (GtkWidget *widget, GdkEventKey *event, gpointer data)
printf("gain = %d \r", ptr->gain);
fflush(stdout);
return TRUE;
case 'd':
printf("Camera configuration:\n");
showProperties(ctx, streamID);
showAutoProperties(ctx, streamID);
printf("\n");
fflush(stdout);
return TRUE;
case 'p':
printf("Estimating frame rate..\n");
estimateFrameRate(ctx, streamID);
Expand Down Expand Up @@ -476,10 +552,14 @@ int main (int argc, char *argv[])
printf("Press z or x to change the zoom.\n");
printf("Press a or s to change the gain.\n");
printf("Press [ or ] to change the white balance.\n");
printf("Press d to show camera configuration.\n");
printf("Press p to estimate the actual frame rate.\n");
printf("Press w to write the current frame to a PPM file.\n");
fflush(stdout);

showProperties(ctx, streamID);
showAutoProperties(ctx, streamID);

gtk_widget_show_all(window);
gtk_main();

Expand Down

0 comments on commit c517f46

Please sign in to comment.