#pragma config(Sensor, S1, HTIRS2, sensorI2CCustom)
#include "drivers/hitechnic-irseeker-v2.h"
long nNumbCyles;
long nInits = 0;
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;
tHTIRS2DSPMode _mode = DSP_1200;
displayInstructions();
while(true)
{
PlaySound(soundBeepBeep);
while(bSoundActive)
{}
eraseDisplay();
nNumbCyles = 0;
++nInits;
while (true)
{
if ((nNumbCyles & 0x04) == 0)
nxtDisplayTextLine(0, "Initializing...");
else
nxtDisplayTextLine(0, "");
nxtDisplayCenteredBigTextLine(1, "IR Seekr");
if (HTIRS2setDSPMode(HTIRS2, _mode))
break;
++nNumbCyles;
PlaySound(soundShortBlip);
nxtDisplayTextLine(4, "Inits: %d / %d", nInits, nNumbCyles);
nxtDisplayCenteredTextLine(6, "Connect Sensor");
nxtDisplayCenteredTextLine(7, "to Port S1");
wait1Msec(100);
}
eraseDisplay();
for (int i = 0; i < 8; ++i)
sTextLines[i] = "";
if (_mode == DSP_1200)
nxtDisplayTextLine(0, " DC 1200 Enh");
else
nxtDisplayTextLine(0, " DC 600 Enh");
while (true)
{
++nNumbCyles;
if (nNxtButtonPressed == kEnterButton)
{
_mode = (_mode == DSP_1200) ? DSP_600 : DSP_1200;
while(nNxtButtonPressed == kEnterButton)
{
}
break;
}
_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);
nxtDisplayTextLine(7, "Enter to switch");
}
}
}
void displayInstructions()
{
nxtDisplayCenteredTextLine(0, "HiTechnic");
nxtDisplayCenteredBigTextLine(1, "IR Seekr");
nxtDisplayCenteredTextLine(3, "Test 1");
nxtDisplayCenteredTextLine(5, "Press enter to");
nxtDisplayCenteredTextLine(6, "switch between");
nxtDisplayCenteredTextLine(7, "600 and 1200 Hz");
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);
}
}