diff --git a/coincellhell.c b/coincellhell.c index 5b497f74047f6da19749765a5cd39cac6dc2aa13..62d61cfb57c4f373cbe9bf19ba6ef0742cb3f1f2 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)