From be64dbc8cc5d5b8f27bee43ab613bab98cc39f55 Mon Sep 17 00:00:00 2001 From: Carl Philipp Klemm <philipp@uvos.xyz> Date: Mon, 11 Sep 2023 15:10:42 +0200 Subject: [PATCH] Implement ramps --- coincellhell.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/coincellhell.c b/coincellhell.c index 5b497f7..62d61cf 100644 --- a/coincellhell.c +++ b/coincellhell.c @@ -161,12 +161,33 @@ int coincellhell_check_ready(struct coincellhell* hell, bool* ready) int coincellhell_set_temperature_ramp(struct coincellhell* hell, uint8_t heater, time_t end_time, float temperature) { - return -1; + time_t currentTime = time(NULL); + time_t timeDelta = end_time - currentTime; + if(timeDelta < 0) + return -1; + + char buffer[7]; + buffer[0] = heater; + + uint32_t microTime = coincellhell_get_seconds(hell); + uint32_t* endTime = (uint32_t*)(buffer+3); + int16_t* setpoint = (int16_t*)(buffer+1); + *endTime = microTime + timeDelta; + *setpoint = temperature/10.0f; + + int ret; + while((ret = usbshm_writeControlTransfer(hell->priv, COMMAND_HEATER_SETUP_RAMP, buffer, 7, 0, 0)) == USBSHM_ERROR_AGAIN) + usleep(100000); + + return ret; } int coincellhell_cancle_ramp(struct coincellhell* hell, uint8_t heater) { - return -1; + int ret; + while((ret = usbshm_writeControlTransfer(hell->priv, COMMAND_HEATER_RAMP_CANCLE, NULL, 0, 0, heater)) == USBSHM_ERROR_AGAIN) + usleep(100000); + return ret; } int coincellhell_set_led(struct coincellhell* hell, bool on) -- GitLab