/*
 * kline_operations.h
 *
 *  Created on: 1 abr 2026
 *      Author: herli
 */

#ifndef KLINE_MASTER_LIBS_KLINE_OPERATIONS_H_
#define KLINE_MASTER_LIBS_KLINE_OPERATIONS_H_

#include <stdint.h>

/* ------------------------------------------------------------------ */
/*  Operation result status                                             */
/* ------------------------------------------------------------------ */

typedef enum {
    KLOP_IDLE    = 0,   /* no operation pending                         */
    KLOP_BUSY    = 1,   /* operation in progress — keep polling         */
    KLOP_OK      = 2,   /* completed successfully                       */
    KLOP_FAIL    = 3,   /* completed with failure (NAK, timeout, etc.)  */
} KLineOp_Status;

/* ------------------------------------------------------------------ */
/*  Start functions — return 0 on success, -1 if already busy          */
/* ------------------------------------------------------------------ */

int KLineOp_Start_ReadDfi(void);
int KLineOp_Start_WriteDfi(float dfi, int version);
int KLineOp_Start_ReadVoltage(void);
int KLineOp_Start_ReadAudiPin(void);
int KLineOp_Start_ClearFaultCodes(void);

/* ------------------------------------------------------------------ */
/*  Poll — call every main-loop iteration                               */
/* ------------------------------------------------------------------ */

KLineOp_Status KLineOp_Poll(void);

/* ------------------------------------------------------------------ */
/*  Result accessors (valid only after KLineOp_Poll() returns KLOP_OK) */
/* ------------------------------------------------------------------ */

float    KLineOp_Result_Dfi(void);
uint16_t KLineOp_Result_Voltage(void);
uint16_t KLineOp_Result_AudiPin(void);
int      KLineOp_Result_WriteDfi(void);        /* 1=success, 0=fail    */
int      KLineOp_Result_ClearFaultCodes(void); /* 1=success, 0=fail    */


#endif /* KLINE_MASTER_LIBS_KLINE_OPERATIONS_H_ */
