128 lines
4.5 KiB
C++
128 lines
4.5 KiB
C++
//***************************************************************************************
|
|
//* Hermes Lite 2 Interface Box *
|
|
//* *
|
|
//* Reads I2C data from the Hermes Lite 2 and a) controls an antenna switch based *
|
|
//* on the selected band and b) sets the correct LPF of the Hardrock 50 Power Amp *
|
|
//* *
|
|
//* Based on HL2-PA70 by Cesc Gudayol (EA3IGT) Version 3.0.1 from 01/04/2021 *
|
|
//* More info: https://github.com/ea3igt/HL2-PA70 *
|
|
//* *
|
|
//* Adapted by Michael Clemens (DK1MI) *
|
|
//* More info: https://dk1mi.radio/hl2-hr50-interface *
|
|
//* *
|
|
//***************************************************************************************
|
|
//* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND *
|
|
//***************************************************************************************
|
|
//
|
|
// Pin Configuration:
|
|
// - PIN A04 INPUT: SDA for I2C Slave (Hermes Lite 2 Control bus)
|
|
// - PIN A05 INPUT: SCL for I2C Slave (Hermes Lite 2 Control bus)
|
|
// - PIN D10 OUTPUT: Antenna Switch
|
|
|
|
#include <Wire.h> //For I2C control
|
|
#include <EEPROM.h> //To store values from PA70-Controller
|
|
#include <util/delay.h> //Library to delay inside one Interrupt
|
|
|
|
//#define TEST //Uncomment if Testing (Serial Monitor traces)
|
|
|
|
// Declaration for the Hermes Lites v2 I2C (Listen to Adress 0x20)
|
|
// HW SDA pin A4
|
|
// HW SCL pin A5
|
|
|
|
|
|
#define Antenna 10 //Pin D10
|
|
|
|
// Other Configurations
|
|
byte previousI2CBand; //to store previously I2C Band decoded
|
|
int selected_antenna = 0;
|
|
|
|
// SetUp function initializations
|
|
void setup() {
|
|
Serial.begin(9600);
|
|
|
|
// I2C Slave Setup
|
|
Wire.begin(0x20); // join i2c bus with address to listen
|
|
Wire.onReceive(receiveEvent); // register event
|
|
|
|
// Antenna
|
|
pinMode(Antenna, OUTPUT);
|
|
|
|
delay(200);
|
|
|
|
//Get stored Band from EEPROM for initial filter selection
|
|
previousI2CBand=EEPROM.read(1); //Read I2C byte Band from EEPROM byte 1
|
|
|
|
decodeBand(previousI2CBand);
|
|
}
|
|
|
|
// Main loop program
|
|
void loop()
|
|
{
|
|
// do nothing
|
|
}
|
|
|
|
|
|
void receiveEvent(int howMany) { //Triggered when receive I2C information from HL2
|
|
byte c[10];
|
|
int i= 0;
|
|
while (0 < Wire.available()) { // loop through all but the last
|
|
c[i] = Wire.read(); // receive byte as a character
|
|
i++;
|
|
}
|
|
|
|
#ifdef TEST
|
|
Serial.print(F("I2C BUS DATA:"));
|
|
Serial.println(c[1]); // write to usb monitor
|
|
#endif
|
|
|
|
byte myC=c[1] & B00111111; //Get 6 least significative bits
|
|
|
|
decodeBand(myC); //Decode Band
|
|
|
|
// toggle Antenna
|
|
digitalWrite(Antenna,selected_antenna);
|
|
|
|
//Store Last Selected Band into EEPROM
|
|
EEPROM.write(1,myC); //Byte 1 for I2C decoded
|
|
|
|
|
|
#ifdef TEST
|
|
// write to usb monitor
|
|
Serial.print(F("LPF BAND CONTROL (Binary):"));
|
|
Serial.println(selectedBand);
|
|
Serial.print(F("PTT CONTROL:"));
|
|
Serial.println(PTTStatus);
|
|
#endif
|
|
}
|
|
|
|
//Function to decode HL2 band and select/map the filter
|
|
//**************** Change accordingly *****************
|
|
void decodeBand(byte c)
|
|
{
|
|
switch (c) {
|
|
case 0x1: //160m
|
|
selected_antenna = 0;
|
|
Serial.println("HRBN10;"); // sets the Hardrock-50 to 160m
|
|
break;
|
|
case 0x2: //80m
|
|
selected_antenna = 0;
|
|
Serial.println("HRBN9;"); // sets the Hardrock-50 to 80m
|
|
break;
|
|
case 0x4: //60m & 40m
|
|
selected_antenna = 0;
|
|
Serial.println("HRBN7;"); // sets the Hardrock-50 to 40m
|
|
break;
|
|
case 0x8: //30m & 20m
|
|
selected_antenna = 1;
|
|
Serial.println("HRBN5;"); // sets the Hardrock-50 to 20m
|
|
break;
|
|
case 0x10: //17m & 15m
|
|
selected_antenna = 1;
|
|
Serial.println("HRBN3;"); // sets the Hardrock-50 to 15m
|
|
break;
|
|
case 0x20: //12m & 10m
|
|
selected_antenna = 1;
|
|
Serial.println("HRBN1;"); // sets the Hardrock-50 to 10m
|
|
break;
|
|
}
|
|
} |