
#ifndef SensorController_h
#define SensorController_h

#include <Arduino.h>
#include "CamaSM30Commands.h"
#include "MyTools.h"
#define MAX_TEMPLATES 3000

class SensorSM30Controller
{

public:
    SensorSM30Controller(HardwareSerial *hwSerial);
    String getCommand(uint16_t cmd); // Total length of the command packet is 24 Bytes
    String getCommand(uint16_t cmd, uint16_t len, uint16_t slot);
    String getCommand(uint16_t cmd, uint16_t len, String data);
    String getData(uint16_t cmd, uint16_t len, String data);
    String getDataTemplate(uint16_t cmd, uint16_t len, uint16_t slot, String templ);

    uint8_t detectFinger();
    uint16_t identify();
    uint16_t getFingerTimeout();
    bool setFingerTimeout(uint8_t timeout);
    bool isGoodCRC(uint8_t *buffer, uint16_t len);
    void readSensor(uint8_t *buffer, uint16_t len);
    bool readSerialPort();
    void cancel();
    bool enroll(uint16_t slot);
    uint16_t getTemplatesCount();

    // bool detectFinger();
    bool camaTest();
    void setDuplicationCheck(bool check);
    void setSecurityLevel(uint8_t securityLevel);
    bool deleteAllTemplates();
    bool deleteTemplate(uint16_t slot);
    bool saveTemplate(uint16_t slot, String template_chars, uint16_t template_len);
    bool ledON();
    bool ledOFF();
    void begin();

private:
    MyTools tools;
    uint16_t calculateCKS(String cmd);
    bool sendCommand(String cmd);
    uint8_t outbuffer[SM30_REGULAR_PACKET_LENGTH];
    uint8_t inbuffer[SM30_REGULAR_PACKET_LENGTH];
    uint8_t template_buffer[SM30_TEMPLATE_BUFFER_LENGHT]; // String template_buffer;
    Stream *sensorSerial;
    HardwareSerial *hwSerial;
};
#endif