Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Pentax Driver #66

Merged
merged 37 commits into from
Mar 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
399767a
Added Bayer filter support for color cameras
karlrees Nov 3, 2019
57af7c5
Update changelog
karlrees Nov 4, 2019
8a2cd95
Merge branch 'master' of https://github.com/karlrees/indi-3rdparty
karlrees Dec 19, 2019
59f867a
Adding Pentax SDK support
karlrees Jan 8, 2020
27f250d
Merge remote-tracking branch 'upstream/master'
karlrees Jan 8, 2020
40e679c
First stab at Pentax SDK support, more to come...
karlrees Jan 8, 2020
308c07d
Latest iteration
karlrees Jan 9, 2020
db8718c
Initial working version.
karlrees Jan 15, 2020
fb27cbd
Refactoring to prep for pktriggercord.
karlrees Jan 15, 2020
262bfe9
Added shared library wrapper for pktriggercord
karlrees Jan 19, 2020
e7fb4d8
Renamed libpentax to libricohcamerasdk
karlrees Jan 19, 2020
e64d00a
Basic support for MSC mode (to support Bulb capture) via libpktrigger…
karlrees Jan 19, 2020
b26e852
Add missing .so files for libricohcamerasdk.
karlrees Jan 19, 2020
738c7ea
Added README for libpktriggercord
karlrees Jan 19, 2020
8a55199
remove generated files
karlrees Jan 20, 2020
b67858b
Convert pktriggercord capture to fits.
karlrees Jan 20, 2020
bf999d4
Got pktriggercord working.
karlrees Jan 22, 2020
4dbdc6e
updated git ignore to no longer exclude certain dependencies for libmtp
karlrees Jan 22, 2020
0993279
Fix libpktriggercord issue with stack smashing when thousands of loop…
karlrees Jan 24, 2020
235a0e0
Update README.md
karlrees Jan 25, 2020
a5e3e26
Status check before exposure just in case exposure mode has changed
karlrees Jan 25, 2020
8642406
Merge branch 'master' of https://github.com/karlrees/indi-3rdparty
karlrees Jan 25, 2020
7ac6e4d
Updated how the libraries were being installed / linked to avoid conf…
karlrees Jan 27, 2020
d8a8014
Fixed problems with disconnecting and reconnecting, particularly when…
karlrees Jan 28, 2020
cceca12
Added comment
karlrees Jan 28, 2020
477bd06
Create README.md
karlrees Jan 28, 2020
5b15f0a
Update README.md
karlrees Jan 28, 2020
fd58aea
Update README.md
karlrees Jan 28, 2020
9f9a9f2
Update README.md
karlrees Jan 28, 2020
2bb8cc7
Update README.md
karlrees Jan 28, 2020
91e3bbc
Update README.md
karlrees Jan 28, 2020
22fe1e9
Update README.md
karlrees Jan 28, 2020
523ad3c
Update README.md
karlrees Jan 28, 2020
9f3bde8
Fixed naming problem that kept MSC driver from appearing in KStars/Ek…
karlrees Jan 29, 2020
a5a532b
Merge upstream
karlrees Mar 6, 2020
b33fb00
Merge remote-tracking branch 'upstream/master'
karlrees Mar 10, 2020
45816ac
Removed unnecessary files from libpktriggercord; fixed error in re/co…
karlrees Mar 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ option(WITH_BEEFOCUS "Install Bee Focuser Driver" On)
option(WITH_SHELYAK "Install Shelyak Spectrograph Driver" On)
option(WITH_SKYWALKER "Install AOK SkyWalker Mount Driver" On)
option(WITH_TALON6 "Install Talon6 Mount Driver" On)
option(WITH_PENTAX "Install Pentax Driver" On)

find_package(FFmpeg)

Expand Down Expand Up @@ -184,6 +185,12 @@ if (WITH_SBIG)
add_subdirectory(libsbig)
endif (WITH_SBIG)

#libpentax
if (WITH_PENTAX)
add_subdirectory(libricohcamerasdk)
add_subdirectory(libpktriggercord)
endif (WITH_PENTAX)

#toupbase dependencies
if (WITH_TOUPBASE)
add_subdirectory(libtoupcam)
Expand Down Expand Up @@ -482,6 +489,19 @@ if (WITH_AVALON)
add_subdirectory(indi-avalon)
endif(WITH_AVALON)

# Pentax
if (WITH_PENTAX)
find_package(PENTAX)
if (PENTAX_FOUND)
add_subdirectory(indi-pentax)
else (PENTAX_FOUND)
add_subdirectory(libpentax)
add_subdirectory(libpktriggercord)
SET(LIBRARIES_FOUND FALSE)
endif (PENTAX_FOUND)
endif(WITH_PENTAX)



# Check if libraries are found. If not, we must build them, install them, THEN run CMake again to build and instal the drivers. If all the libraraies are installed, then we build and install the drivers only now.
if (LIBRARIES_FOUND)
Expand Down Expand Up @@ -548,6 +568,10 @@ if (WITH_RTLSDR AND NOT RTLSDR)
message(STATUS "librtlsdr was not found. Please install librtlsdr first before running cmake again to install indi-rtlsdr.")
endif (WITH_RTLSDR AND NOT RTLSDR)

if (WITH_PENTAX AND NOT PENTAX_FOUND)
message(STATUS "libpktriggercord and/or libricohcamerasdk were not found and will now be built. Please install these libraries first before running cmake again to install indi-pentax.")
endif (WITH_PENTAX AND NOT PENTAX_FOUND)

message(STATUS "####################################################################################################################################")
endif (LIBRARIES_FOUND)

Expand Down
79 changes: 79 additions & 0 deletions cmake_modules/FindPENTAX.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# - Try to find PENTAX Universal Libraries
# Once done this will define
#
# PENTAX_FOUND - system has PENTAX
# PENTAX_INCLUDE_DIR - the PENTAX include directory
# PENTAX_LIBRARIES - Link these to use PENTAX

# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

if (PENTAX_INCLUDE_DIR AND PENTAX_LIBRARIES)

# in cache already
set(PENTAX_FOUND TRUE)
message(STATUS "Found PENTAX libraries: ${PENTAX_LIBRARIES}")

else (PENTAX_INCLUDE_DIR AND PENTAX_LIBRARIES)

find_path(RICOH_INCLUDE_DIR ricoh_camera_sdk.hpp
PATH_SUFFIXES libpentax libricohcamerasdk
${_obIncDir}
${GNUWIN32_DIR}/include
)

find_path(PKTRIGGERCORD_INCLUDE_DIR libpktriggercord.h
PATH_SUFFIXES libpktriggercord
${_obIncDir}
${GNUWIN32_DIR}/include
)

if (RICOH_INCLUDE_DIR AND PKTRIGGERCORD_INCLUDE_DIR)
set(PENTAX_INCLUDE_DIR ${RICOH_INCLUDE_DIR} ${PKTRIGGERCORD_INCLUDE_DIR})
endif (RICOH_INCLUDE_DIR AND PKTRIGGERCORD_INCLUDE_DIR)

find_library(RICOH_LIBRARIES NAMES RicohCameraSDKCpp
PATHS
${_obLinkDir}
${GNUWIN32_DIR}/lib
PATH_SUFFIXES indipentax
)

find_library(RICOHMTP_LIBRARIES NAMES libmtp.so.9.3.0
PATHS
${_obLinkDir}
${GNUWIN32_DIR}/lib
PATH_SUFFIXES indipentax
)

find_library(PKTRIGGERCORD_LIBRARIES NAMES pktriggercord
PATHS
${_obLinkDir}
${GNUWIN32_DIR}/lib
PATH_SUFFIXES indipentax
)

if (RICOH_LIBRARIES AND RICOHMTP_LIBRARIES AND PKTRIGGERCORD_LIBRARIES)
set(PENTAX_LIBRARIES ${RICOH_LIBRARIES} ${RICOHMTP_LIBRARIES} ${PKTRIGGERCORD_LIBRARIES})
endif (RICOH_LIBRARIES AND RICOHMTP_LIBRARIES AND PKTRIGGERCORD_LIBRARIES)

if(PENTAX_INCLUDE_DIR AND PENTAX_LIBRARIES)
set(PENTAX_FOUND TRUE)
else (PENTAX_INCLUDE_DIR AND PENTAX_LIBRARIES)
set(PENTAX_FOUND FALSE)
endif(PENTAX_INCLUDE_DIR AND PENTAX_LIBRARIES)


if (PENTAX_FOUND)
if (NOT PENTAX_FIND_QUIETLY)
message(STATUS "Found PENTAX libraries: ${PENTAX_LIBRARIES}")
endif (NOT PENTAX_FIND_QUIETLY)
else (PENTAX_FOUND)
if (PENTAX_FIND_REQUIRED)
message(FATAL_ERROR "One or both of libricohcamersdk and libpktriggercord are not found. Please install them. See http://www.indilib.org.")
endif (PENTAX_FIND_REQUIRED)
endif (PENTAX_FOUND)

mark_as_advanced(PENTAX_INCLUDE_DIR PENTAX_LIBRARIES)

endif (PENTAX_INCLUDE_DIR AND PENTAX_LIBRARIES)
2 changes: 1 addition & 1 deletion indi-gphoto/indi_gphoto.xml.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<driver name="Nikon DSLR">indi_nikon_ccd</driver>
<version>@INDI_GPHOTO_VERSION_MAJOR@.@INDI_GPHOTO_VERSION_MINOR@</version>
</device>
<device label="Pentax DSLR" mdpd="true">
<device label="Pentax DSLR (Gphoto)" mdpd="true">
<driver name="Pentax DSLR">indi_pentax_ccd</driver>
<version>@INDI_GPHOTO_VERSION_MAJOR@.@INDI_GPHOTO_VERSION_MINOR@</version>
</device>
Expand Down
1 change: 1 addition & 0 deletions indi-pentax/AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Karl Rees
54 changes: 54 additions & 0 deletions indi-pentax/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
cmake_minimum_required(VERSION 2.8)
PROJECT(indi_pentax CXX C)

LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake_modules/")

include(GNUInstallDirs)

set (INDI_PENTAX_VERSION_MAJOR 1)
set (INDI_PENTAX_VERSION_MINOR 0)

#libmtp needs the runpath, but is an indirect dependency and therefore will only get runpath if we set the following flags
set (CMAKE_EXE_LINKER_FLAGS "-Wl,--disable-new-dtags")

find_package(CFITSIO REQUIRED)
find_package(INDI REQUIRED)
find_package(ZLIB REQUIRED)
find_package(LibRaw REQUIRED)
find_package(JPEG REQUIRED)
find_package(GPHOTO2 REQUIRED)
find_package(PENTAX REQUIRED)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h )
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/indi_pentax.xml.cmake ${CMAKE_CURRENT_BINARY_DIR}/indi_pentax.xml )

include_directories( ${CMAKE_CURRENT_BINARY_DIR})
include_directories( ${CMAKE_CURRENT_SOURCE_DIR})
include_directories( ${INDI_INCLUDE_DIR})
include_directories( ${CFITSIO_INCLUDE_DIR})
include_directories( ${LibRaw_INCLUDE_DIR})
include_directories( ${PENTAX_INCLUDE_DIR})
include_directories( ${PKTRIGGERCORD_INCLUDE_DIR})
include_directories( ${GPHOTO2_INCLUDE_DIR})

include(CMakeCommon)

############# PENTAX CCD ###############
set(indipentax_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/indi_pentax.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pentax_ccd.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pentax_event_handler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pktriggercord_ccd.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../indi-gphoto/gphoto_readimage.cpp
)

#need to use rpath to find libraries, since they need to be in a subfolder to avoid conflicts with the standard version of libmtp
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

add_executable(indi_pentax ${indipentax_SRCS})

target_link_libraries(indi_pentax pthread ${PENTAX_LIBRARIES} ${INDI_LIBRARIES} ${JPEG_LIBRARIES} ${LibRaw_LIBRARIES} ${CFITSIO_LIBRARIES} ${ZLIB_LIBRARY})

install(TARGETS indi_pentax RUNTIME DESTINATION bin)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/indi_pentax.xml DESTINATION ${INDI_DATA_DIR})
14 changes: 14 additions & 0 deletions indi-pentax/INSTALL
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
INSTALL
============

Prerequisites:

libpktriggercord (install from indi-3rdparty repo)
libricohcamerasdk (install from indi-3rdparty repo)

Instructions:

1) $ cmake -DCMAKE_INSTALL_PREFIX=/usr .
2) $ make
3) $ sudo make install

159 changes: 159 additions & 0 deletions indi-pentax/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# Pentax Camera Driver for Indi

## Introduction

This driver supports various Pentax cameras in PTP and/or MSC mode.

## Installation

The driver requires two libraries: libRicohCameraSDKCpp and libPkTriggerCord. These are included with indi-pentax in the indi-3rdparty repository.

*TODO (once packages are generated): Add instructions for installing packages.*

To build/install everything manually, first clone the indi-3rdparty repository:

```
mkdir -p ~/Projects
cd ~/Projects
git clone https://github.com/karlrees/indi-3rdparty.git
```

*TODO (once pulled): update clone location to the main repository.*

Next install libRicohCameraSDK:

```
cd ~/Projects/indi-3rdparty/libricohcamerasdk
cmake -DCMAKE_INSTALL_PREFIX=/usr .
make
sudo make install
```

Next build/install libPkTriggerCord:

```
cd ~/Projects/indi-3rdparty/libpktriggercord
cmake -DCMAKE_INSTALL_PREFIX=/usr .
make
sudo make install
```

Finally, build/install indi-pentax:

```
cd ~/Projects/indi-3rdparty/indi-pentax
cmake -DCMAKE_INSTALL_PREFIX=/usr .
make
sudo make install
```

## Compatibility

In general, a greater number of cameras are supported in MSC mode. However, for more recent cameras, PTP mode will probably be more reliable.

Based on the documentation for the libraries that this driver relies upon, the following cameras *should* work. However, only cameras with an asterisk are actually confirmed. Please update this list if you verify support for any camera:

- Pentax K-01 (MSC - known bugs)
- PENTAX K-1 (PTP, MSC?)
- PENTAX K-1 Mark II (PTP, MSC?)
- Pentax K-3 / K-3 II (MSC)
- Pentax K-5 (MSC)
- Pentax K-5 II / K-5 IIs (MSC)
- Pentax K-7 (MSC)
- Pentax K10D / Samsung GX-10 (MSC - fw 1.20 or later)
- Pentax K20D / Samsung GX-20 (MSC)
- Pentax K-30 (MSC)
- Pentax K-50 (MSC - known bugs)
- PENTAX K-70 (PTP, MSC - with bugs) *
- Pentax K200D (MSC)
- Pentax K-500 (MSC)
- PENTAX 645Z (PTP, MSC?)
- Pentax K-r (MSC)
- Pentax K-m / K2000 (MSC)
- PENTAX KP (PTP, MSC?)

Cameras suspected to have limited MSC support include:

- Pentax istDS2
- Pentax istDL
- Pentax K100D Super

Cameras likely *not* to work include:

- Pentax istDS
- Pentax istD
- Samsung GX-1L
- Pentax K110D
- Pentax K100D
- Pentax K-S2

## Features

The exact set of features available will depend on the current USB mode and capture mode of the camera. Not all features will be available on all cameras. The following is a rough list of what to expect:

- Still image capture
- Live View (PTP mode only)
- Capture as FITS (processor intensive), Native, or both
- Change image format (JPEG, PEF, or DNG) (DNG is saved as a .raw file)
- Predefined capture mode support (e.g. Auto, Manual, etc.)
- Bulb mode support (MSC mode only)
- Set shutter speed to any supported by the capture mode to which the camera is currently set
- Change ISO (For certain cameras, such as K70, works in PTP mode only)
- Change Exposure (For certain cameras, such as K70, works in PTP mode only)
- Change White Balance
- Change JPEG image quality
- Change JPEG image resolution (PTP mode only)
- Toggle save to SD Card (PTP mode only)
- Monitor battery level

The driver *should* support multiple cameras at once, and the author is happy to verify that if anyone wants to donate another camera.

*If there's a feature that PkTriggerCord supports for your camera, but the driver currently does not, it should be possible to add support. Contact the author with requests.*

## Operation

1. First, be sure the camera is in the desired USB mode (PTP or MSC). Then connect the camera via a USB cable to the Indi host and power the camera on.
2. Set the camera to the appropriate capture mode. For PTP mode, Manual (M) is suggested for maximum flexibility. For MSC mode, Bulb (B) provides maximum flexibility.

*However, if your exposures are 30 seconds or less, other modes (e.g. Manual) are close to twice as fast at starting the exposure and returning the image.*

3. Start indiserver on the host with "Pentax DSLR (Native)" selected as a driver.

If you are starting indiserver from the command line, you can use:

```
indiserver indi_pentax
```

4. Launch your Indi client, if you are not already in the client, and click "Connect" if you are not already connected.
5. Once connected, you should see a device pane for your Pentax camera. The device pane will have a number of tabs. You may change most settings in the Image Settings tab of the Indi Control Panel, though FITs/Native settings are in the Options tab.
6. To capture an image using the Indi Control Panel, go to the Main Control tab and select an exposure duration. Then click "Set" to start the exposure.

*Note that unless you are in bulb mode, the exposure time you choose will not be the exact exposure time, but will be matched to the closest predefined exposure time of your current capture mode.*

7. For Live View, be sure you are in PTP mode, and select the Streaming tab.

Images and Live View are also supported through Ekos, as explained in the Ekos documentation.

### Switching operational modes

You may switch capture modes (e.g. switch from Auto to Manual or Manual to Bulb) at any time.

To switch between PTP and MSC, you will need to unplug the camera from the host and change to the desired USB mode using the on-camera menu. You may need to manually disconnect from the driver in the Indi client (e.g. using the "Disconnect" button) if you are in MSC mode. Then, plug the camera back into the host and click on "Connect" again. A separate device pane will be created for your new USB mode, if it does not already exist. Switch to the new device pane and cick "Connect" to continue in the new USB mode.

## Known Issues

- Bulb mode does not work in PTP mode.
- Changing ISO and exposure do not work on the K-70 in MSC mode (probably other cameras as well).
- When DNG format is selected, images are currently saved with a "raw" extension. This is because Indi seems to have a bug with .DNG files where it grabs the JPEG preview out of DNGs and discards the rest of the DNG file. The raw files may be safely renamed to ".DNG."
- When compiled on Ubuntu Mate 18.0.4 (Raspberry Pi 3B), PTP mode does not work. This appears to be because the indi_pentax binary generated by the compiler is for armv7, whereas the library files provided by Ricoh are for armv6. Yet, I currently cannot figure out how to get indi-pentax to compile if I force the compiler to armv6. A workaraound is to use a binary generated on Rasbian.
- The Ricoh Camera SDK uses a custom version of libmtp with a version number of 9.3.0. Not surprisingly, this can cause problems if the
standard version of libmtp is installed. To avoid these problems, the requisite libraries are configured to be installed in the "indipentax" subdirectory of CMAKE_INSTALL_LIBDIR. That subdirectory is then listed in the RPATH of the indi_pentax binary (not the RUNPATH, since libmtp is an indirect dependency). I'm sure this negatively affects the modularity of indi-pentax. I'm happy to take suggestions if there's a better way to deal with this issue.

## Author / Acknowledgments

This driver was developed by Karl Rees, copyright 2020.

Thanks to Andras Salamon for PkTrigercord, which is used for MSC mode. Specifically, this driver wraps PkTriggerCord into a shared library called libPkTriggerCord. More information about PkTriggerCord and source code available from: https://api.ricoh/products/camera-sdk/.

Thanks also to Ricoh Company, Ltd. for providing the Ricoh Camera SDK (libRicohCameraSDKCpp), which is used for PTP mode. The SDK is available from: https://api.ricoh/products/camera-sdk/.
10 changes: 10 additions & 0 deletions indi-pentax/config.h.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef CONFIG_H
#define CONFIG_H

/* Define INDI Data Dir */
#cmakedefine INDI_DATA_DIR "@INDI_DATA_DIR@"
/* Define Driver version */
#define INDI_PENTAX_VERSION_MAJOR @INDI_PENTAX_VERSION_MAJOR@
#define INDI_PENTAX_VERSION_MINOR @INDI_PENTAX_VERSION_MINOR@

#endif // CONFIG_H
Loading