Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
59 changes: 38 additions & 21 deletions Drivers/CameraDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
namespace NINA.RetroKiwi.Plugin.SonyCamera.Drivers {
public class CameraDriver : BaseINPC, ICamera {
// Some camera settings we are interested in
private const uint PROPID_BATTERY = 53784;
private const uint PROPID_ISO = 53790; // Actual ISO currently set
private const uint PROPID_ISOS = 65534; // List of learnt ISOs this camera supports
private const uint PROPID_BATTERY = 53784;
private const uint PROPID_ISO = 0xD21E; // Actual ISO currently set
private const uint PROPID_ISOS = PROPID_ISO; // List of learnt ISOs this camera supports

// Capture Status
private const uint CAPTURE_CREATED = 0x0000;
Expand Down Expand Up @@ -232,9 +232,14 @@ public bool CanGetGain {
public int GainMax {
get {
if (_camera != null) {
PropertyInfo gainInfo = _camera.GetPropertyInfo(PROPID_ISOS);
try {
PropertyInfo gainInfo = _camera.GetPropertyInfo(PROPID_ISOS);

return (int)gainInfo.Options().Last().Value;
return (int)gainInfo.Options().Where(o => o.Value <= 0x00FFFFFF).Last().Value;
} catch (Exception ex) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function is getGainMax, shouldn't the error reflect the name?
Same goes for the getGainMin where the error states it was a problem getting max

Logger.Error("Problem getting gain min", ex);
return -1;
}
} else {
return 0;
}
Expand All @@ -244,9 +249,14 @@ public int GainMax {
public int GainMin {
get {
if (_camera != null) {
PropertyInfo gainInfo = _camera.GetPropertyInfo(PROPID_ISOS);
try {
PropertyInfo gainInfo = _camera.GetPropertyInfo(PROPID_ISOS);

return (int)gainInfo.Options().Min(o => o.Value);
return (int)gainInfo.Options().Where(o => o.Value <= 0x00FFFFFF).Min(o => o.Value);
} catch (Exception ex) {
Logger.Error("Problem getting gain max", ex);
return -1;
}
} else {
return -1;
}
Expand All @@ -258,7 +268,6 @@ public int Gain {
if (_camera != null) {
try {
PropertyValue value = GetPropertyValue(PROPID_ISO);
PropertyInfo gainInfo = _camera.GetPropertyInfo(PROPID_ISOS);

return (int)(value.Value == 0xffffff ? 0 : value.Value);
} catch (Exception ex) {
Expand Down Expand Up @@ -288,7 +297,7 @@ public IList<int> Gains {
if (_camera != null) {
PropertyInfo gainInfo = _camera.GetPropertyInfo(PROPID_ISOS);

foreach (var iso in gainInfo.Options()) {
foreach (var iso in gainInfo.Options().Where(o => o.Value <= 0x00FFFFFF)) {
if (iso.Value == 0xffffff) {
// AUTO
gains.Add(0);
Expand Down Expand Up @@ -343,6 +352,7 @@ public double TemperatureSetPoint {
set {
}
}

public bool CanSubSample => false;

public bool EnableSubSample { get; set; }
Expand Down Expand Up @@ -441,8 +451,7 @@ public Task<bool> Connect(CancellationToken token) {
return Task.Run<bool>(() => {
try {
_camera = SonyDriver.GetInstance().OpenCamera(_device.Id);
}
catch (Exception ex) {
} catch (Exception ex) {
Logger.Error(ex);
_camera = null;
}
Expand All @@ -468,7 +477,8 @@ public Task<IExposureData> DownloadLiveView(CancellationToken token) {
using (var memStream = new MemoryStream(SonyDriver.GetInstance().GetLiveView(_camera.Handle))) {
memStream.Position = 0;

JpegBitmapDecoder decoder = new JpegBitmapDecoder(memStream, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.OnLoad);
JpegBitmapDecoder decoder =
new JpegBitmapDecoder(memStream, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.OnLoad);

FormatConvertedBitmap bitmap = new FormatConvertedBitmap();
bitmap.BeginInit();
Expand All @@ -482,15 +492,16 @@ public Task<IExposureData> DownloadLiveView(CancellationToken token) {
var metaData = new ImageMetaData();

return _exposureDataFactory.CreateImageArrayExposureData(
input: outArray,
width: bitmap.PixelWidth,
height: bitmap.PixelHeight,
bitDepth: 16,
isBayered: false,
metaData: metaData);
input: outArray,
width: bitmap.PixelWidth,
height: bitmap.PixelHeight,
bitDepth: 16,
isBayered: false,
metaData: metaData);
}
});
}

public void SetupDialog() {
throw new NotImplementedException();
}
Expand All @@ -500,15 +511,16 @@ public void StartExposure(CaptureSequence sequence) {
SonyDriver driver = SonyDriver.GetInstance();
uint captureStatus = driver.GetCaptureStatus(_camera.Handle);

if (captureStatus == CAPTURE_CAPTURING || captureStatus == CAPTURE_PROCESSING || captureStatus == CAPTURE_STARTING || captureStatus == CAPTURE_READING || captureStatus == CAPTURE_PROCESSING) {
if (captureStatus == CAPTURE_CAPTURING || captureStatus == CAPTURE_PROCESSING || captureStatus == CAPTURE_STARTING ||
captureStatus == CAPTURE_READING || captureStatus == CAPTURE_PROCESSING) {
Notification.ShowWarning("Another exposure still in progress. Cancelling it to start another.");
}

// Tell the camera to cancel capture, we do this every time regardless - this will reset the status to be non-complete
driver.CancelCapture(_camera.Handle);

double exposureTime = sequence.ExposureTime;
driver.StartCapture(_camera.Handle, (float)exposureTime);//);
driver.StartCapture(_camera.Handle, (float)exposureTime); //);
}
}

Expand All @@ -530,7 +542,8 @@ public async Task WaitUntilExposureIsReady(CancellationToken token) {

try {
uint captureStatus = driver.GetCaptureStatus(_camera.Handle);
Logger.Info($"Waiting for image to be ready, current state is {captureStatus}, completion states are {String.Join(", ", completionStates)}");
Logger.Info(
$"Waiting for image to be ready, current state is {captureStatus}, completion states are {String.Join(", ", completionStates)}");

while (!completionStates.Contains(captureStatus)) {
await CoreUtil.Wait(TimeSpan.FromMilliseconds(100), token);
Expand Down Expand Up @@ -583,6 +596,10 @@ public string SendCommandString(string command, bool raw = true) {
public void SetBinning(short x, short y) {
// Ignore
}

public void UpdateSubSampleArea() {
throw new NotImplementedException();
}

#endregion

Expand Down
25 changes: 4 additions & 21 deletions NINASonyCameraPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Reference Include="ReachFramework" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NINA.Plugin" Version="3.0.0.3001-rc" />
<PackageReference Include="NINA.Plugin" Version="3.2.0.3001-rc" />
<PackageReference Include="System.ComponentModel.Composition" Version="8.0.0" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.6.0-preview3.19128.7" />
<PackageReference Include="EntityFramework" Version="6.4.4" />
Expand All @@ -21,29 +21,17 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Accord" Version="3.8.2-alpha" />
<PackageReference Include="Accord.Imaging" Version="3.8.2-alpha" />
<PackageReference Include="Accord.Math" Version="3.8.2-alpha" />
<PackageReference Include="Accord.Statistics" Version="3.8.2-alpha" />
<PackageReference Include="AsyncEnumerator" Version="4.0.2" />
<PackageReference Include="Castle.Core" Version="5.1.1" />
<PackageReference Include="Castle.Core.AsyncInterceptor" Version="2.1.0" />
<PackageReference Include="CommonServiceLocator" Version="2.0.7" />
<PackageReference Include="CSharpFITS" Version="1.1.0" />
<PackageReference Include="CsvHelper" Version="30.0.1" />
<PackageReference Include="Dirkster.AvalonDock" Version="4.72.1" />
<PackageReference Include="DotNetProjects.Extended.Wpf.Toolkit" Version="5.0.113" />
<PackageReference Include="Fastenshtein" Version="1.0.0.8" />
<PackageReference Include="Google.Protobuf" Version="3.25.1" />
<PackageReference Include="Google.Protobuf.Tools" Version="3.25.1" />
<PackageReference Include="Grpc.Core.Api" Version="2.60.0" />
<PackageReference Include="GrpcDotNetNamedPipes" Version="3.0.0" />
<PackageReference Include="K4os.Compression.LZ4" Version="1.3.7-beta" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.77" />
<PackageReference Include="Namotion.Reflection" Version="3.1.1" />
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
<PackageReference Include="Nito.AsyncEx.Context" Version="5.1.2" />
<PackageReference Include="Nito.AsyncEx.Coordination" Version="5.1.2" />
Expand All @@ -55,17 +43,12 @@
<PackageReference Include="Nito.Disposables" Version="2.5.0" />
<PackageReference Include="Nito.Mvvm.Async" Version="1.0.0-pre-04" />
<PackageReference Include="Nito.Mvvm.Core" Version="1.3.1" />
<PackageReference Include="NJsonSchema" Version="11.0.0" />
<PackageReference Include="OxyPlot.Core" Version="2.1.2" />
<PackageReference Include="OxyPlot.Wpf" Version="2.1.2" />


<PackageReference Include="SHA3" Version="1.0.0" />
<PackageReference Include="SharpGIS.NmeaParser" Version="2.2.2" />
<PackageReference Include="System.Data.SQLite" Version="1.0.118" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.118" />
<PackageReference Include="System.Data.SQLite.EF6" Version="1.0.118" />
<PackageReference Include="System.Windows.Interactivity.WPF" Version="2.0.20525" />
<PackageReference Include="ToggleSwitch" Version="1.2.0" />
<PackageReference Include="Trinet.Core.IO.Ntfs" Version="4.1.1" />
<PackageReference Include="VVVV.FreeImage" Version="3.15.1.1" />
<PackageReference Include="Zlib.Portable.Signed" Version="1.11.0" />
</ItemGroup>
Expand Down Expand Up @@ -99,6 +82,6 @@
</ItemGroup>
<PropertyGroup />
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="if not exist &quot;%25localappdata%25\NINA\Plugins&quot; (&#xD;&#xA; echo &quot;Creating $(PlatformName) Plugins folder&quot;&#xD;&#xA; mkdir &quot;%25localappdata%25\NINA\Plugins&quot;&#xD;&#xA;)&#xD;&#xA;if not exist &quot;%25localappdata%25\NINA\Plugin\3.0.0\$(TargetName)&quot; (&#xD;&#xA; echo &quot;Creating $(PlatformName) Plugins\3.0.0\$(TargetName) folder&quot;&#xD;&#xA; mkdir &quot;%25localappdata%25\NINA\Plugins\$(TargetName)&quot;&#xD;&#xA;)&#xD;&#xA;&#xD;&#xA;echo &quot;Copying $(PlatformName) $(TargetFileName)&quot;&#xD;&#xA;xcopy &quot;$(TargetPath)&quot; &quot;%25localappdata%25\NINA\Plugins\3.0.0\$(TargetName)&quot; /h/i/c/k/e/r/y" />
<Exec Command="if not exist &quot;%25localappdata%25\NINA\Plugins\3.0.0&quot; (&#xA; echo &quot;Creating $(PlatformName) Plugins folder&quot;&#xA; mkdir &quot;%25localappdata%25\NINA\Plugins\3.0.0&quot;&#xA;)&#xA;if not exist &quot;%25localappdata%25\NINA\Plugins\3.0.0\$(TargetName)&quot; (&#xA; echo &quot;Creating $(PlatformName) Plugins $(TargetName) folder&quot;&#xA; mkdir &quot;%25localappdata%25\NINA\Plugins\3.0.0\$(TargetName)&quot;&#xA;)&#xA;&#xA;echo &quot;Copying $(PlatformName) $(TargetFileName)&quot;&#xA;xcopy &quot;$(TargetPath)&quot; &quot;%25localappdata%25\NINA\Plugins\3.0.0\$(TargetName)&quot; /h/i/c/k/e/r/y" />
</Target>
</Project>