#pragma config(Sensor, S1, HTSMUX, sensorI2CCustom)
#include "drivers/hitechnic-sensormux.h"
#include "drivers/hitechnic-irseeker-v2.h"
const tMUXSensor HTIRS2 = msensor_S1_1;
string sTextLines[8];
void displayText(int nLineNumber, const string cChar, int nValueDC, int nValueAC);
void displayText3(int nLineNumber, const string cChar, int nValueDC, int nValueAC, int nValueEnh);
void displayInstructions();
task main ()
{
int _dirDC = 0;
int _dirAC = 0;
int dcS1, dcS2, dcS3, dcS4, dcS5 = 0;
int acS1, acS2, acS3, acS4, acS5 = 0;
int _dirEnh, _strEnh;
displayInstructions();
eraseDisplay();
for (int i = 0; i < 8; ++i)
sTextLines[i] = "";
nxtDisplayTextLine(0, " DC 1200 Enh");
while (true)
{
_dirDC = HTIRS2readDCDir(HTIRS2);
if (_dirDC < 0)
break;
_dirAC = HTIRS2readACDir(HTIRS2);
if (_dirAC < 0)
break;
if (!HTIRS2readAllDCStrength(HTIRS2, dcS1, dcS2, dcS3, dcS4, dcS5))
break;
if (!HTIRS2readAllACStrength(HTIRS2, acS1, acS2, acS3, acS4, acS5 ))
break;
if (!HTIRS2readEnhanced(HTIRS2, _dirEnh, _strEnh))
break;
displayText3(1, "D", _dirDC, _dirAC, _dirEnh);
displayText(2, "0", dcS1, acS1);
displayText(3, "1", dcS2, acS2);
displayText3(4, "2", dcS3, acS3, _strEnh);
displayText(5, "3", dcS4, acS4);
displayText(6, "4", dcS5, acS5);
if (HTSMUXreadPowerStatus(HTSMUX))
nxtDisplayTextLine(7, "Batt: bad");
else
nxtDisplayTextLine(7, "Batt: good");
}
}
void displayInstructions()
{
nxtDisplayCenteredTextLine(0, "HiTechnic");
nxtDisplayCenteredBigTextLine(1, "IRSeekr2");
nxtDisplayCenteredTextLine(3, "SMUX Test");
nxtDisplayCenteredTextLine(5, "Connect SMUX to");
nxtDisplayCenteredTextLine(6, "S1 and sensor to");
nxtDisplayCenteredTextLine(7, "SMUX Port 1");
wait1Msec(2000);
}
void displayText(int nLineNumber, const string cChar, int nValueDC, int nValueAC)
{
string sTemp;
StringFormat(sTemp, "%4d %4d", nValueDC, nValueAC);
if (sTemp != sTextLines[nLineNumber])
{
string sTemp2;
sTextLines[nLineNumber] = sTemp;
StringFormat(sTemp2, "%s:%s", cChar, sTemp);
nxtDisplayTextLine(nLineNumber, sTemp2);
}
}
void displayText3(int nLineNumber, const string cChar, int nValueDC, int nValueAC, int nValueEnh)
{
string sTemp;
StringFormat(sTemp, "%4d %4d %3d", nValueDC, nValueAC, nValueEnh);
if (sTemp != sTextLines[nLineNumber])
{
string sTemp2;
sTextLines[nLineNumber] = sTemp;
StringFormat(sTemp2, "%s:%s", cChar, sTemp);
nxtDisplayTextLine(nLineNumber, sTemp2);
}
}