/*
  Copyright (c) 2025-2026 Kay Kasper
  under the MIT License (MIT)
*/

#ifndef COMMON_TESTSWITCH
#define COMMON_TESTSWITCH

#include "Classes.h"

#define POTI_MAX_VALUE 1023           // in this example the max value of analogRead()
#define ID_SWITCHTEST 1
#define ID_SWITCHMAPPINGTEST 2
#define ID_PUSHBUTTONTEST 3
#define ID_PUSHBUTTONTEST2 4
#define ID_ENCODERTEST 5
#define ID_ENCODERSTRICTTEST 6
#define ID_ENCODER2TEST 7
#define INPUT_PIN 2                   // must be digital pin, for normal switch and pin A of rotary encoder
#define INPUT_PIN_B 3                 // must be digital pin, pin B for rotary encoder
#define READ_WAIT_MILLIS 0            // minimum difference between two actual read of analog raw value


// do the checking and print hint in case of and error
void check(int value, int ref, int id, int seq){
  if(value != ref){
    Serial.print("ID: ");
    Serial.print(id);
    Serial.print("/");
    Serial.print(seq);
    Serial.print(": '");
    Serial.print(value) ;
    Serial.print("' != reference '");
    Serial.print(ref);
    Serial.println("'");
  }
}

// for showing state information
void printStates(Switch* sw, bool newLine){
  Serial.print("curState=");
  if(sw->getState() == SW_STATE_UNDEFINED){
    Serial.print("SW_STATE_UNDEFINED");
  }
  else{
    Serial.print(sw->getState());
  }

  Serial.print(", prevState=");
  if(sw->getPrevState() == SW_STATE_UNDEFINED){
    Serial.print("SW_STATE_UNDEFINED");
  }
  else{
    Serial.print(sw->getPrevState());
  }

  if(newLine){
    Serial.print("\n");
  }
  else{
    Serial.print(", ");
  }
}

// for showing mapping information
void printMappings(Switch* sw, bool newLine){
  Serial.print("curMap=");
  if(sw->getMappedState() == SW_STATE_UNDEFINED){
    Serial.print("SW_STATE_UNDEFINED");
  }
  else{
    Serial.print(sw->getMappedState());
  }

  Serial.print(", prevMap=");
  if(sw->getPrevMappedState() == SW_STATE_UNDEFINED){
    Serial.print("SW_STATE_UNDEFINED");
  }
  else{
    Serial.print(sw->getPrevMappedState());
  }

  if(newLine){
    Serial.print("\n");
  }
  else{
    Serial.print(", ");
  }
}

#endif
