coincellhell 1.0.x
coincellhell.h
1/* * Copyright (c) 2023 Carl Klemm <carl@uvos.xyz>
2 * All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
6 *
7 * * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation and/or
11 * other materials provided with the distribution.
12 * * Neither the name of %ORGANIZATION% nor the names of its contributors may be
13 * used to endorse or promote products derived from this software without specific
14 * prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#pragma once
29
30#include <stdint.h>
31#include <semaphore.h>
32#include <stdbool.h>
33
34#include "usbcommands.h"
35
43#ifdef __cplusplus
44extern "C" {
45#endif
46
48{
49 struct usbshm* priv;
50};
51
53{
55 bool enabled;
57 bool ready;
59 bool ramp;
61 bool fault;
63 fault_t faultType;
65 uint8_t dacCommand;
67 float setpoint;
68
75};
76
83int coincellhell_connect(struct coincellhell* hell, uint16_t serial);
84
92int coincellhell_get_temperature(struct coincellhell* hell, uint8_t heater, temperature_sensor_location_t location, float* temperature);
93
100int coincellhell_set_temperature(struct coincellhell* hell, uint8_t heater, float temperature);
101
108int coincellhell_get_temperature_setpoint(struct coincellhell* hell, uint8_t heater, float* temperature);
109
116int coincellhell_get_state(struct coincellhell* hell, uint8_t heater, struct heater_state* state);
117
124int coincellhell_set_enabled(struct coincellhell* hell, uint8_t heater, bool enabled);
125
131int coincellhell_check_ready(struct coincellhell* hell, bool* ready);
132
139int coincellhell_set_temperature_ramp(struct coincellhell* hell, uint8_t heater, time_t end_time, float temperature);
140
146int coincellhell_cancle_ramp(struct coincellhell* hell, uint8_t heater);
147
154int coincellhell_set_led(struct coincellhell* hell, bool on);
155
161
166
172const char* coincellhell_string_for_fault(fault_t fault);
173
174int coincellhell_write_eeprom(struct coincellhell* hell, uint16_t addr, uint16_t value);
175uint16_t coincellhell_read_eeprom(struct coincellhell* hell, uint16_t addr);
176uint8_t coincellhell_read_oscal(struct coincellhell* hell);
177uint32_t coincellhell_get_seconds(struct coincellhell* hell);
178const uint8_t* coincellhell_get_fw_git_revision(struct coincellhell* hell);
179int coincellhell_enable_watchdog(struct coincellhell* hell);
180int coincellhell_set_periodic_recal(struct coincellhell* hell, bool recal);
181void coincellhell_reset_bus(struct coincellhell* hell);
182
183#ifdef __cplusplus
184}
185#endif
186
int coincellhell_cancle_ramp(struct coincellhell *hell, uint8_t heater)
Cancels any previously set ramp, the set points of the heater will hold the current temperature.
int coincellhell_set_led(struct coincellhell *hell, bool on)
Turns the led on the PCB on or off.
int coincellhell_reset(struct coincellhell *hell)
resets the device
int coincellhell_get_state(struct coincellhell *hell, uint8_t heater, struct heater_state *state)
Gets the state struct for the given heater.
const char * coincellhell_string_for_fault(fault_t fault)
Returns a human readable string for a given fault.
int coincellhell_set_temperature(struct coincellhell *hell, uint8_t heater, float temperature)
Sets the target temperature of the given heater.
int coincellhell_check_ready(struct coincellhell *hell, bool *ready)
Checks if all temperatures are close to their set points.
int coincellhell_set_enabled(struct coincellhell *hell, uint8_t heater, bool enabled)
Sets the enabled state for a give heater.
int coincellhell_get_temperature(struct coincellhell *hell, uint8_t heater, temperature_sensor_location_t location, float *temperature)
Reads the current temperature of the given heater at given location.
void coincellhell_disconnect(struct coincellhell *hell)
Disconnects from the coincellhell.
int coincellhell_set_temperature_ramp(struct coincellhell *hell, uint8_t heater, time_t end_time, float temperature)
Will linearly ramp the temperature to the one provided from now until end_time.
int coincellhell_connect(struct coincellhell *hell, uint16_t serial)
Attempts to connect to a EISmultiplexer device and initializes a coincellhell struct.
int coincellhell_get_temperature_setpoint(struct coincellhell *hell, uint8_t heater, float *temperature)
Gets the target temperature of the given heater.
Definition coincellhell.h:48
Definition coincellhell.h:53
time_t rampStartTime
if a ramp is currently being executed, the UNIX timestamp at which it was started
Definition coincellhell.h:72
float setpoint
current target temperature for this heater
Definition coincellhell.h:67
float rampTarget
if a ramp is currently being executed, its final temperature will be set here
Definition coincellhell.h:70
bool ramp
true if heater is currently executing a ramp
Definition coincellhell.h:59
fault_t faultType
the detected fault type as a fault_t enum
Definition coincellhell.h:63
bool fault
true if the system has detected a fault with this heater
Definition coincellhell.h:61
bool enabled
true if heater is enabled
Definition coincellhell.h:55
bool ready
true if heater is close to its set point
Definition coincellhell.h:57
uint8_t dacCommand
current command (0-255) that is being sent to the DAC for this heater
Definition coincellhell.h:65
time_t rampStopTime
if a ramp is currently being executed, the UNIX timestamp at it will complete
Definition coincellhell.h:74