Skip to content
Snippets Groups Projects
Commit 8d489866 authored by Carl Philipp Klemm's avatar Carl Philipp Klemm
Browse files

add reset function

parent 4b0196b1
No related branches found
No related tags found
No related merge requests found
......@@ -235,6 +235,18 @@ const uint8_t* coincellhell_get_fw_git_revision(struct coincellhell* hell)
return gitrev;
}
int coincellhell_reset(struct coincellhell* hell)
{
usbshm_reopen(hell->priv);
for(int i = 0; i < 4; ++i)
{
int ret = coincellhell_set_enabled(hell, 0, false);
if(ret != 0)
return ret;
}
return 0;
}
void coincellhell_disconnect(struct coincellhell* hell)
{
usbshm_distroy(hell->priv);
......
......@@ -117,7 +117,7 @@ int coincellhell_get_state(struct coincellhell* hell, uint8_t heater, struct hea
/**
* @brief Sets the enabled state for a give heater
* @param heater heater for which to set the temperature
* @param heater heater for which to set the enabled state
* @param state A struct where the state will be stored
* @return 0 on sucess and < 0 on failure
*/
......@@ -153,6 +153,12 @@ int coincellhell_cancle_ramp(struct coincellhell* hell, uint8_t heater);
*/
int coincellhell_set_led(struct coincellhell* hell, bool on);
/**
* @brief resets the device
* @param hell pointer to a coincellhell struct
*/
int coincellhell_reset(struct coincellhell* hell);
/**
* @brief Disconnects from the coincellhell
*/
......
......@@ -60,6 +60,8 @@ void usbshm_distroy(struct usbshm* instance)
libusb_close(instance->priv->handle);
free(instance->priv->buffer);
free(instance->priv);
if(instance->serial)
free(instance->serial);
if(--objectCounter == 0)
{
threadStop = true;
......@@ -92,6 +94,7 @@ int usbshm_init(struct usbshm* instance, void (*dataCallback)(uint8_t request, u
instance->priv->buffer = NULL;
instance->vendorID = 0;
instance->productID = 0;
instance->serial = NULL;
instance->dataCallback = dataCallback;
instance->user_data = user_data;
if(objectCounter == 0)
......@@ -156,6 +159,11 @@ int usbshm_open(struct usbshm* instance, int vendorID, int productID, const unsi
{
instance->vendorID = vendorID;
instance->productID = productID;
if(serial)
{
instance->serial = calloc(strlen((char*)serial), 1);
memcpy(instance->serial, serial, strlen((char*)serial));
}
libusb_set_auto_detach_kernel_driver(instance->priv->handle, true);
}
else
......@@ -176,14 +184,14 @@ bool usbshm_usbshm_isOpen(struct usbshm* instance)
void usbshm_reset(struct usbshm* instance)
{
printf("Usb transfer failed with %u\n", instance->priv->transfer->status);
libusb_reset_device(instance->priv->handle);
}
void usbshm_reopen(struct usbshm* instance)
{
usbshm_reset(instance);
libusb_close(instance->priv->handle);
usbshm_open(instance, instance->vendorID, instance->productID, NULL);
usbshm_open(instance, instance->vendorID, instance->productID, instance->serial);
}
int usbshm_writeControlTransfer(struct usbshm* instance, const uint8_t request,
......
......@@ -45,6 +45,7 @@ struct usbshm {
struct usbshm_priv* priv;
int vendorID;
int productID;
unsigned char* serial;
void* user_data;
void (*dataCallback)(uint8_t request, unsigned char* data, size_t length, void* user_data);
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment