/* Copyright 2025 by COG9 Enterprises LLC
 * All rights reserved.
 * Title: batv.h
 * Author: Jed Marti KI7NNP
 * Description: Constants and stuff for battery voltage.
 * Created: Wed Oct  8 19:44:45 2025
 * Revision History:
 */

#ifndef batv_h
#define batv_h

// The battery voltage monitor - analog input.
#define BATMON A0

// Low battery indication. Happens at 10 volts. Times in milliseconds.
#define LOWBAT 10.0f
#define LOWON  25
#define LOWOFF 250

// Time to quit (i.e. no more recording) voltage.
#define BADBAT 5.0f
#define BADON  25
#define BADOFF 500

// Overvoltage.
#define BATOVER 14.5f
#define OVERON  25
#define OVEROFF 175

// Normal blink.
#define NORMALON 25
#define NORMALOFF 1975

// LLSQ constants default.
#define cM 0.01464f
#define cB -0.06962f

enum {
      batNoSample,
      batOverVoltage,
      batGood,
      batLow,
      batDead};


void initBatv(void);
uint16_t batRaw(void);
uint16_t raw2Volt(uint16_t raw);
float    raw2Voltf(uint16_t raw);
void volt2string(uint16_t v100, char *str);

void calibrateBatMon(void);

void checkBatState(void);
#endif

