Skip to content

Commit

Permalink
Add cooler control API method
Browse files Browse the repository at this point in the history
  • Loading branch information
daleghent committed Nov 1, 2024
1 parent d0ade43 commit ec11bfa
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/event_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2087,6 +2087,47 @@ static void get_calibration_data(JObj& response, const json_value *params)
response << jrpc_result(rslt);
}

static void set_cooler_state(JObj& response, const json_value *params)
{
bool ret;
Params p("enabled", params);
const json_value *val = p.param("enabled");
bool enable;
if (!val || !bool_param(val, &enable))
{
response << jrpc_error(JSONRPC_INVALID_PARAMS, "expected enabled boolean param");
return;
}

if (!pCamera || !pCamera->Connected)
{
response << jrpc_error(1, "camera not connected");
return;
}

if (!pCamera->HasCooler)
{
response << jrpc_error(1, "camera lacks a cooler");
return;
}

if (enable)
{
double setpt = pConfig->Profile.GetDouble("/camera/CoolerSetpt", 10.0);
ret = pCamera->SetCoolerSetpoint(setpt);
if (!ret)
{
response << jrpc_error(1, "failed to set cooler setpoint");
return;
}
}

if (pCamera->SetCoolerOn(enable))
response << jrpc_result(0);
else
response << jrpc_error(1, "failed to set cooler state");
}

static void get_cooler_status(JObj& response, const json_value *params)
{
if (!pCamera || !pCamera->Connected)
Expand Down Expand Up @@ -2403,6 +2444,10 @@ static bool handle_request(JRpcCall& call)
"get_cooler_status",
&get_cooler_status,
},
{
"set_cooler_state",
&set_cooler_state,
},
{
"get_ccd_temperature",
&get_sensor_temperature,
Expand Down

0 comments on commit ec11bfa

Please sign in to comment.