From 3c074a95821081044feda1733a66f991291f014c Mon Sep 17 00:00:00 2001 From: "[CST] Focus" Date: Tue, 23 Jul 2013 15:36:33 +0400 Subject: [PATCH] gui/motorcontrol.cpp: cleanup/rework, add simple network info --- src/gui/motorcontrol.cpp | 663 ++++++++++++++++----------------------- src/gui/motorcontrol.h | 7 +- 2 files changed, 281 insertions(+), 389 deletions(-) diff --git a/src/gui/motorcontrol.cpp b/src/gui/motorcontrol.cpp index 8a6750c94..245a04382 100644 --- a/src/gui/motorcontrol.cpp +++ b/src/gui/motorcontrol.cpp @@ -46,15 +46,7 @@ #include #include - -static int g_sig; -static int g_snr; -static int last_snr = 0; -static int moving = 0; - -#define RED_BAR 40 -#define YELLOW_BAR 70 -#define GREEN_BAR 100 +#include #define BAR_BORDER 2 #define BAR_WIDTH 100 @@ -88,7 +80,7 @@ void CMotorControl::Init(void) width = w_max(470, 0); mheight = mheight - 2; - height = hheight + (20 * mheight) - 5; + height = hheight + (22 * mheight) - 5; height = h_max(height, 0); x = frameBuffer->getScreenX() + (frameBuffer->getScreenWidth() - width) / 2; @@ -114,55 +106,35 @@ int CMotorControl::exec(CMenuTarget* parent, const std::string &) int wasgrow = 0; uint8_t origPosition; - last_snr = 0; - moving = 0; + last_snr = moving = g_sig = g_snr = 0; + network = "unknown"; - CZapitClient::ScanSatelliteList satList; - CZapitClient::commandSetScanSatelliteList sat; - sat_iterator_t sit; - - sigscale->reset(); - snrscale->reset(); - lastsnr = lastsig = -1; - - bool istheend = false; int lim_cmd; - if (!frameBuffer->getActive()) - return menu_return::RETURN_EXIT_ALL; + int retval = menu_return::RETURN_REPAINT; if (parent) parent->hide(); - x = frameBuffer->getScreenX() + (frameBuffer->getScreenWidth() - width) / 2; - y = frameBuffer->getScreenY() + (frameBuffer->getScreenHeight() - height) / 2; + x = frameBuffer->getScreenX() + (frameBuffer->getScreenWidth() - width) / 2; + y = frameBuffer->getScreenY() + (frameBuffer->getScreenHeight() - height) / 2; + + /* send satellite list to zapit */ + CZapitClient::ScanSatelliteList satList; + CZapitClient::commandSetScanSatelliteList sat; -#if 0 - /* send satellite list to zapit */ - for(sit = satellitePositions.begin(); sit != satellitePositions.end(); sit++) { - if(!strcmp(sit->second.name.c_str(),scansettings.satName)) { - sat.position = sit->first; - strncpy(sat.satName, scansettings.satName, 49); - satList.push_back(sat); - if(sit->second.motor_position) - motorPosition = sit->second.motor_position; - break; - } - } -#endif - /* send satellite list to zapit */ sat.position = CServiceManager::getInstance()->GetSatellitePosition(scansettings.satName); strncpy(sat.satName, scansettings.satName, 49); satList.push_back(sat); satellite_map_t & satmap = frontend->getSatellites(); - sit = satmap.find(sat.position); + sat_iterator_t sit = satmap.find(sat.position); if(sit != satmap.end() && sit->second.motor_position) motorPosition = sit->second.motor_position; origPosition = motorPosition; //FIXME change cZapit live fe g_Zapit->stopPlayBack(); - g_Zapit->setScanSatelliteList( satList); + g_Zapit->setScanSatelliteList(satList); CZapit::getInstance()->SetLiveFrontend(frontend); TP.feparams.dvb_feparams.frequency = atoi(scansettings.sat_TP_freq); @@ -176,289 +148,200 @@ int CMotorControl::exec(CMenuTarget* parent, const std::string &) paintMenu(); paintStatus(); - while (!istheend) + msg = CRCInput::RC_nokey; + while (!(msg == CRCInput::RC_setup) && (!(msg == CRCInput::RC_home))) { - uint64_t timeoutEnd = CRCInput::calcTimeoutEnd_MS(100 /*250*/); - msg = CRCInput::RC_nokey; - - while (!(msg == CRCInput::RC_timeout) && (!(msg == CRCInput::RC_home))) - { - g_RCInput->getMsgAbsoluteTimeout(&msg, &data, &timeoutEnd); - showSNR(); -//printf("SIG: %d SNR %d last %d\n", g_sig, g_snr, last_snr); - if(moving && (stepMode == STEP_MODE_AUTO)) { - if(last_snr < g_snr) { - wasgrow = 1; - } - //if((last_snr > g_snr) && last_snr > 37000) - if(wasgrow && (last_snr > g_snr) /* && last_snr > 50*/) { -//printf("Must stop rotor!!!\n"); - g_Zapit->sendMotorCommand(0xE0, 0x31, 0x60, 0, 0, 0); - moving = 0; - paintStatus(); - last_snr = 0; - //g_Zapit->tune_TP(TP); - } else - last_snr = g_snr; - } else - wasgrow = 0; - - if (installerMenue) - { - switch(msg) - { - case CRCInput::RC_ok: - case CRCInput::RC_0: - printf("[motorcontrol] 0 key received... goto userMenue\n"); - installerMenue = false; - paintMenu(); - paintStatus(); - break; - - case CRCInput::RC_1: - case CRCInput::RC_right: - printf("[motorcontrol] left/1 key received... drive/Step motor west, stepMode: %d\n", stepMode); - motorStepWest(); - paintStatus(); - //g_Zapit->tune_TP(TP); - break; - - case CRCInput::RC_red: - case CRCInput::RC_2: - printf("[motorcontrol] 2 key received... halt motor\n"); - g_Zapit->sendMotorCommand(0xE0, 0x31, 0x60, 0, 0, 0); - moving = 0; - paintStatus(); - //g_Zapit->tune_TP(TP); - break; - - case CRCInput::RC_3: - case CRCInput::RC_left: - printf("[motorcontrol] right/3 key received... drive/Step motor east, stepMode: %d\n", stepMode); - motorStepEast(); - paintStatus(); - //g_Zapit->tune_TP(TP); - break; - - case CRCInput::RC_4: - printf("[motorcontrol] 4 key received... set west (soft) limit\n"); - if(g_settings.rotor_swap) lim_cmd = 0x66; - else lim_cmd = 0x67; - g_Zapit->sendMotorCommand(0xE1, 0x31, lim_cmd, 0, 0, 0); - //g_Zapit->tune_TP(TP); - break; - - case CRCInput::RC_5: - printf("[motorcontrol] 5 key received... disable (soft) limits\n"); - g_Zapit->sendMotorCommand(0xE0, 0x31, 0x63, 0, 0, 0); - //g_Zapit->tune_TP(TP); - break; - - case CRCInput::RC_6: - printf("[motorcontrol] 6 key received... set east (soft) limit\n"); - if(g_settings.rotor_swap) lim_cmd = 0x67; - else lim_cmd = 0x66; - g_Zapit->sendMotorCommand(0xE1, 0x31, lim_cmd, 0, 0, 0); - //g_Zapit->tune_TP(TP); - break; - - case CRCInput::RC_7: - printf("[motorcontrol] 7 key received... goto reference position\n"); - g_Zapit->sendMotorCommand(0xE0, 0x31, 0x6B, 1, 0, 0); - satellitePosition = 0; - paintStatus(); - //g_Zapit->tune_TP(TP); - break; - - case CRCInput::RC_8: - printf("[motorcontrol] 8 key received... enable (soft) limits\n"); - g_Zapit->sendMotorCommand(0xE0, 0x31, 0x6A, 1, 0, 0); - //g_Zapit->tune_TP(TP); - break; - - case CRCInput::RC_9: - printf("[motorcontrol] 9 key received... (re)-calculate positions\n"); - g_Zapit->sendMotorCommand(0xE0, 0x31, 0x6F, 1, 0, 0); - //g_Zapit->tune_TP(TP); - break; - - case CRCInput::RC_plus: - case CRCInput::RC_up: - printf("[motorcontrol] up key received... increase satellite position: %d\n", ++motorPosition); - satellitePosition = 0; - paintStatus(); - break; - - case CRCInput::RC_minus: - case CRCInput::RC_down: - if (motorPosition > 1) motorPosition--; - printf("[motorcontrol] down key received... decrease satellite position: %d\n", motorPosition); - satellitePosition = 0; - paintStatus(); - break; - - case CRCInput::RC_blue: - if (++stepMode > 3) - stepMode = 0; - if (stepMode == STEP_MODE_OFF) - satellitePosition = 0; - last_snr = 0; - printf("[motorcontrol] red key received... toggle stepmode on/off: %d\n", stepMode); - paintStatus(); - break; - - default: - //printf("[motorcontrol] message received...\n"); - if ((msg >= CRCInput::RC_WithData) && (msg < CRCInput::RC_WithData + 0x10000000)) - delete[] (unsigned char*) data; - break; - } + g_RCInput->getMsgAbsoluteTimeout(&msg, &data, &timeoutEnd); + showSNR(); + //printf("SIG: %d SNR %d last %d\n", g_sig, g_snr, last_snr); + if(moving && (stepMode == STEP_MODE_AUTO)) { + if(last_snr < g_snr) { + wasgrow = 1; } + //if((last_snr > g_snr) && last_snr > 37000) + if(wasgrow && (last_snr > g_snr) /* && last_snr > 50*/) { + //printf("Must stop rotor!!!\n"); + g_Zapit->sendMotorCommand(0xE0, 0x31, 0x60, 0, 0, 0); + moving = 0; + paintStatus(); + last_snr = 0; + //g_Zapit->tune_TP(TP); + } else + last_snr = g_snr; + } else + wasgrow = 0; + + if (msg == CRCInput::RC_ok || msg == CRCInput::RC_0) { + printf("[motorcontrol] 0 key received... goto %s\n", installerMenue ? "userMenue" : "installerMenue"); + if (installerMenue) + installerMenue = false; else - { - switch(msg) - { - case CRCInput::RC_ok: - case CRCInput::RC_0: - printf("[motorcontrol] 0 key received... goto installerMenue\n"); - installerMenue = true; - paintMenu(); - paintStatus(); - break; - - case CRCInput::RC_1: - case CRCInput::RC_right: - printf("[motorcontrol] left/1 key received... drive/Step motor west, stepMode: %d\n", stepMode); - motorStepWest(); - paintStatus(); - //g_Zapit->tune_TP(TP); - break; - - case CRCInput::RC_red: - case CRCInput::RC_2: - printf("[motorcontrol] 2 key received... halt motor\n"); - g_Zapit->sendMotorCommand(0xE0, 0x31, 0x60, 0, 0, 0); - //g_Zapit->tune_TP(TP); - break; - - case CRCInput::RC_3: - case CRCInput::RC_left: - printf("[motorcontrol] right/3 key received... drive/Step motor east, stepMode: %d\n", stepMode); - motorStepEast(); - paintStatus(); - //g_Zapit->tune_TP(TP); - break; - - case CRCInput::RC_green: - case CRCInput::RC_5: - { - bool store = true; - printf("[motorcontrol] 5 key received... store present satellite number: %d\n", motorPosition); - if(motorPosition != origPosition) { - printf("[motorcontrol] position changed %d -> %d\n", origPosition, motorPosition); - for(sit = satmap.begin(); sit != satmap.end(); sit++) { - if(sit->second.motor_position == motorPosition) - break; - } - if(sit != satmap.end()) { - std::string satname = CServiceManager::getInstance()->GetSatelliteName(sit->first); - printf("[motorcontrol] new positions configured for %s\n", satname.c_str()); - std::string buf = g_Locale->getText(LOCALE_MOTORCONTROL_OVERRIDE); - buf += " "; - buf += satname; - buf += " ?"; - store = (ShowMsgUTF(LOCALE_MESSAGEBOX_INFO, buf,CMessageBox::mbrNo,CMessageBox::mbNo|CMessageBox::mbYes) == CMessageBox::mbrYes); - } - } - if(store) - g_Zapit->sendMotorCommand(0xE0, 0x31, 0x6A, 1, motorPosition, 0); - //g_Zapit->tune_TP(TP); - } - break; - - case CRCInput::RC_6: - if (stepSize < 0x7F) stepSize++; - printf("[motorcontrol] 6 key received... increase Step size: %d\n", stepSize); - paintStatus(); - break; - - case CRCInput::RC_yellow: - case CRCInput::RC_7: - printf("[motorcontrol] 7 key received... goto satellite number: %d\n", motorPosition); - g_Zapit->sendMotorCommand(0xE0, 0x31, 0x6B, 1, motorPosition, 0); - satellitePosition = 0; - paintStatus(); - //g_Zapit->tune_TP(TP); - break; - - case CRCInput::RC_9: - if (stepSize > 1) stepSize--; - printf("[motorcontrol] 9 key received... decrease Step size: %d\n", stepSize); - paintStatus(); - break; - - case CRCInput::RC_plus: - case CRCInput::RC_up: - printf("[motorcontrol] up key received... increase satellite position: %d\n", ++motorPosition); - satellitePosition = 0; - paintStatus(); - //g_Zapit->tune_TP(TP); - break; - - case CRCInput::RC_minus: - case CRCInput::RC_down: - if (motorPosition > 1) motorPosition--; - printf("[motorcontrol] down key received... decrease satellite position: %d\n", motorPosition); - satellitePosition = 0; - paintStatus(); - //g_Zapit->tune_TP(TP); - break; - - case CRCInput::RC_blue: - if (++stepMode > 2) - stepMode = 0; - if (stepMode == STEP_MODE_OFF) - satellitePosition = 0; - printf("[motorcontrol] red key received... toggle stepmode on/off: %d\n", stepMode); - paintStatus(); - break; - - default: - //printf("[motorcontrol] message received...\n"); - if ((msg >= CRCInput::RC_WithData) && (msg < CRCInput::RC_WithData + 0x10000000)) - delete[] (unsigned char*) data; - break; - } + installerMenue = true; + paintMenu(); + paintStatus(); + } + else if (msg == CRCInput::RC_1 || msg == CRCInput::RC_left) { + printf("[motorcontrol] left/1 key received... drive/Step motor west, stepMode: %d\n", stepMode); + motorStep(true); + paintStatus(); + //g_Zapit->tune_TP(TP); + } + else if (msg == CRCInput::RC_red || msg == CRCInput::RC_2) { + printf("[motorcontrol] 2 key received... halt motor\n"); + g_Zapit->sendMotorCommand(0xE0, 0x31, 0x60, 0, 0, 0); + moving = 0; + paintStatus(); + //g_Zapit->tune_TP(TP); + } + else if (msg == CRCInput::RC_3 || msg == CRCInput::RC_right) { + printf("[motorcontrol] right/3 key received... drive/Step motor east, stepMode: %d\n", stepMode); + motorStep(false); + paintStatus(); + //g_Zapit->tune_TP(TP); + } + else if (msg == CRCInput::RC_4) { + if (installerMenue) { + printf("[motorcontrol] 4 key received... set west (soft) limit\n"); + if(g_settings.rotor_swap) lim_cmd = 0x66; + else lim_cmd = 0x67; + g_Zapit->sendMotorCommand(0xE1, 0x31, lim_cmd, 0, 0, 0); + //g_Zapit->tune_TP(TP); } } - - istheend = (msg == CRCInput::RC_home); + else if (msg == CRCInput::RC_5 || msg == CRCInput::RC_green) { + if (installerMenue) { + printf("[motorcontrol] 5 key received... disable (soft) limits\n"); + g_Zapit->sendMotorCommand(0xE0, 0x31, 0x63, 0, 0, 0); + } else { + bool store = true; + printf("[motorcontrol] 5 key received... store present satellite number: %d\n", motorPosition); + if(motorPosition != origPosition) { + printf("[motorcontrol] position changed %d -> %d\n", origPosition, motorPosition); + for(sit = satmap.begin(); sit != satmap.end(); sit++) { + if(sit->second.motor_position == motorPosition) + break; + } + if(sit != satmap.end()) { + std::string satname = CServiceManager::getInstance()->GetSatelliteName(sit->first); + printf("[motorcontrol] new positions configured for %s\n", satname.c_str()); + std::string buf = g_Locale->getText(LOCALE_MOTORCONTROL_OVERRIDE); + buf += " "; + buf += satname; + buf += " ?"; + store = (ShowMsgUTF(LOCALE_MESSAGEBOX_INFO, buf,CMessageBox::mbrNo,CMessageBox::mbNo|CMessageBox::mbYes) == CMessageBox::mbrYes); + } + } + if(store) + g_Zapit->sendMotorCommand(0xE0, 0x31, 0x6A, 1, motorPosition, 0); + } + } + else if (msg == CRCInput::RC_6) { + if (installerMenue) { + printf("[motorcontrol] 6 key received... set east (soft) limit\n"); + if(g_settings.rotor_swap) lim_cmd = 0x67; + else lim_cmd = 0x66; + g_Zapit->sendMotorCommand(0xE1, 0x31, lim_cmd, 0, 0, 0); + //g_Zapit->tune_TP(TP); + } else { + if (stepSize < 0x7F) stepSize++; + printf("[motorcontrol] 6 key received... increase Step size: %d\n", stepSize); + paintStatus(); + } + } + else if (msg == CRCInput::RC_7) { + if (installerMenue) { + printf("[motorcontrol] 7 key received... goto reference position\n"); + g_Zapit->sendMotorCommand(0xE0, 0x31, 0x6B, 1, 0, 0); + satellitePosition = 0; + paintStatus(); + } else { + printf("[motorcontrol] 7 key received... goto satellite number: %d\n", motorPosition); + g_Zapit->sendMotorCommand(0xE0, 0x31, 0x6B, 1, motorPosition, 0); + satellitePosition = 0; + paintStatus(); + } + //g_Zapit->tune_TP(TP); + } + else if (msg == CRCInput::RC_8) { + if (installerMenue) { + printf("[motorcontrol] 8 key received... enable (soft) limits\n"); + g_Zapit->sendMotorCommand(0xE0, 0x31, 0x6A, 1, 0, 0); + } + } + else if (msg == CRCInput::RC_9) { + if (installerMenue) { + printf("[motorcontrol] 9 key received... (re)-calculate positions\n"); + g_Zapit->sendMotorCommand(0xE0, 0x31, 0x6F, 1, 0, 0); + } else { + if (stepSize > 1) stepSize--; + printf("[motorcontrol] 9 key received... decrease Step size: %d\n", stepSize); + paintStatus(); + } + } + else if (msg == CRCInput::RC_plus || msg == CRCInput::RC_up) { + printf("[motorcontrol] up key received... increase satellite position: %d\n", ++motorPosition); + satellitePosition = 0; + paintStatus(); + } + else if (msg == CRCInput::RC_minus || msg == CRCInput::RC_down) { + if (motorPosition > 1) motorPosition--; + printf("[motorcontrol] down key received... decrease satellite position: %d\n", motorPosition); + satellitePosition = 0; + paintStatus(); + } + else if (msg == CRCInput::RC_blue) { + if (++stepMode > 3) + stepMode = 0; + if (stepMode == STEP_MODE_OFF) + satellitePosition = 0; + last_snr = 0; + printf("[motorcontrol] blue key received... toggle stepmode on/off: %d\n", stepMode); + paintStatus(); + } + else if (msg == CRCInput::RC_info) { + network = "waiting for NIT..."; + paintStatus(); + readNetwork(); + paintStatus(); + } + else if (msg == CRCInput::RC_setup) { + retval = menu_return::RETURN_EXIT_ALL; + } + else { + if ((msg >= CRCInput::RC_WithData) && (msg < CRCInput::RC_WithData + 0x10000000)) + delete[] (unsigned char*) data; + } } hide(); frontend->setTsidOnid(0); - return menu_return::RETURN_REPAINT; + return retval; } -void CMotorControl::motorStepWest(void) +void CMotorControl::motorStep(bool west) { int cmd; - printf("[motorcontrol] motorStepWest\n"); - if(g_settings.rotor_swap) cmd = 0x68; - else cmd = 0x69; + if (west) { + if(g_settings.rotor_swap) cmd = 0x68; + else cmd = 0x69; + } else { + if(g_settings.rotor_swap) cmd = 0x69; + else cmd = 0x68; + } + printf("[motorcontrol] motorStep: %s\n", west ? "West" : "East"); switch(stepMode) { case STEP_MODE_ON: g_Zapit->sendMotorCommand(0xE0, 0x31, cmd, 1, (-1 * stepSize), 0); - satellitePosition += stepSize; + satellitePosition += west ? stepSize : -stepSize; break; case STEP_MODE_TIMED: g_Zapit->sendMotorCommand(0xE0, 0x31, cmd, 1, 40, 0); usleep(stepSize * stepDelay * 1000); g_Zapit->sendMotorCommand(0xE0, 0x31, 0x60, 0, 0, 0); //halt motor - satellitePosition += stepSize; + satellitePosition += west ? stepSize : -stepSize; break; case STEP_MODE_AUTO: moving = 1; @@ -468,31 +351,6 @@ void CMotorControl::motorStepWest(void) } } -void CMotorControl::motorStepEast(void) -{ - int cmd; - if(g_settings.rotor_swap) cmd = 0x69; - else cmd = 0x68; - printf("[motorcontrol] motorStepEast\n"); - switch(stepMode) - { - case STEP_MODE_ON: - g_Zapit->sendMotorCommand(0xE0, 0x31, cmd, 1, (-1 * stepSize), 0); - satellitePosition -= stepSize; - break; - case STEP_MODE_TIMED: - g_Zapit->sendMotorCommand(0xE0, 0x31, cmd, 1, 40, 0); - usleep(stepSize * stepDelay * 1000); - g_Zapit->sendMotorCommand(0xE0, 0x31, 0x60, 0, 0, 0); //halt motor - satellitePosition -= stepSize; - break; - case STEP_MODE_AUTO: - moving = 1; - default: - g_Zapit->sendMotorCommand(0xE0, 0x31, cmd, 1, 40, 0); - } -} - void CMotorControl::hide() { frameBuffer->paintBackgroundBoxRel(x, y, width, height + 20); @@ -501,21 +359,25 @@ void CMotorControl::hide() void CMotorControl::paintLine(int px, int *py, int pwidth, const char *txt) { + frameBuffer->paintBoxRel(px, *py, pwidth, mheight, COL_MENUCONTENT_PLUS_0); *py += mheight; - frameBuffer->paintBoxRel(px, *py - mheight, pwidth, mheight, COL_MENUCONTENT_PLUS_0); g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(px, *py, pwidth, txt, COL_MENUCONTENT_TEXT, 0, true); } void CMotorControl::paintLine(int px, int py, int pwidth, const char *txt) { - //frameBuffer->paintBoxRel(px, py - mheight, pwidth, mheight, COL_MENUCONTENT_PLUS_0); g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(px, py, pwidth, txt, COL_MENUCONTENT_TEXT, 0, true); } +void CMotorControl::paintLine(int ix, int tx, int *py, int pwidth, const char *icon, const char *txt) +{ + frameBuffer->paintIcon(icon, ix, *py, mheight); + *py += mheight; + g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(tx, *py, pwidth, txt, COL_MENUCONTENT_TEXT, 0, true); +} + void CMotorControl::paintSeparator(int xpos, int *pypos, int pwidth, const char * /*txt*/) { - //int stringwidth = 0; - //int stringstartposX = 0; int th = 10; //*ypos += mheight; *pypos += th; @@ -523,8 +385,8 @@ void CMotorControl::paintSeparator(int xpos, int *pypos, int pwidth, const char frameBuffer->paintHLineRel(xpos, pwidth - 20, *pypos - (th >> 1) + 1, COL_MENUCONTENT_PLUS_1); #if 0 - stringwidth = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(txt); - stringstartposX = 0; + int stringwidth = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(txt); + int stringstartposX = 0; stringstartposX = (xpos + (pwidth >> 1)) - (stringwidth >> 1); frameBuffer->paintBoxRel(stringstartposX - 5, *pypos - mheight, stringwidth + 10, mheight, COL_MENUCONTENT_PLUS_0); g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(stringstartposX, *pypos, stringwidth, txt, COL_MENUCONTENT_TEXT); @@ -533,7 +395,7 @@ void CMotorControl::paintSeparator(int xpos, int *pypos, int pwidth, const char void CMotorControl::paintStatus() { - char buf[256]; + char buf1[256]; char buf2[256]; int xpos1 = x + 10; @@ -545,54 +407,45 @@ void CMotorControl::paintStatus() paintSeparator(xpos1, &ypos, width, g_Locale->getText(LOCALE_MOTORCONTROL_SETTINGS)); paintLine(xpos1, &ypos, width1, g_Locale->getText(LOCALE_MOTORCONTROL_MOTOR_POS)); - sprintf(buf, "%d", motorPosition); - paintLine(xpos2, ypos, width2 , buf); + sprintf(buf1, "%d", motorPosition); + paintLine(xpos2, ypos, width2 , buf1); paintLine(xpos1, &ypos, width1, g_Locale->getText(LOCALE_MOTORCONTROL_MOVEMENT)); switch(stepMode) { case STEP_MODE_ON: - strcpy(buf, g_Locale->getText(LOCALE_MOTORCONTROL_STEP_MODE)); - break; - case STEP_MODE_OFF: - strcpy(buf, g_Locale->getText(LOCALE_MOTORCONTROL_DRIVE_MODE)); + strcpy(buf1, g_Locale->getText(LOCALE_MOTORCONTROL_STEP_MODE)); + sprintf(buf2, "%d", stepSize); break; case STEP_MODE_AUTO: - strcpy(buf, g_Locale->getText(LOCALE_MOTORCONTROL_DRIVE_MODE_AUTO)); + strcpy(buf1, g_Locale->getText(LOCALE_MOTORCONTROL_DRIVE_MODE_AUTO)); + if(moving) + strcpy(buf2, g_Locale->getText(LOCALE_MOTORCONTROL_STOP_MOVING)); + else + strcpy(buf2, g_Locale->getText(LOCALE_MOTORCONTROL_STOP_STOPPED)); + break; + case STEP_MODE_OFF: + strcpy(buf1, g_Locale->getText(LOCALE_MOTORCONTROL_DRIVE_MODE)); + strcpy(buf2, g_Locale->getText(LOCALE_MOTORCONTROL_NO_MODE)); break; case STEP_MODE_TIMED: - strcpy(buf, g_Locale->getText(LOCALE_MOTORCONTROL_TIMED_MODE)); + strcpy(buf1, g_Locale->getText(LOCALE_MOTORCONTROL_TIMED_MODE)); + sprintf(buf2, "%d %s", stepSize * stepDelay, g_Locale->getText(LOCALE_MOTORCONTROL_MSEC)); break; } - paintLine(xpos2, ypos, width2, buf); + paintLine(xpos2, ypos, width2, buf1); paintLine(xpos1, &ypos, width1, g_Locale->getText(LOCALE_MOTORCONTROL_STEP_SIZE)); - switch(stepMode) - { - case STEP_MODE_ON: - sprintf(buf, "%d", stepSize); - break; - case STEP_MODE_AUTO: - if(moving) - strcpy(buf, g_Locale->getText(LOCALE_MOTORCONTROL_STOP_MOVING)); - else - strcpy(buf, g_Locale->getText(LOCALE_MOTORCONTROL_STOP_STOPPED)); - break; - case STEP_MODE_OFF: - strcpy(buf, g_Locale->getText(LOCALE_MOTORCONTROL_NO_MODE)); - break; - case STEP_MODE_TIMED: - sprintf(buf, "%d ", stepSize * stepDelay); - strcat(buf, g_Locale->getText(LOCALE_MOTORCONTROL_MSEC)); - break; - } - paintLine(xpos2, ypos, width2, buf); + paintLine(xpos2, ypos, width2, buf2); + + paintLine(xpos1, &ypos, width1, g_Locale->getText(LOCALE_MOTORCONTROL_NETWORK)); + paintLine(xpos2, ypos, width2, network.c_str()); paintSeparator(xpos1, &ypos, width, g_Locale->getText(LOCALE_MOTORCONTROL_STATUS)); - strcpy(buf, g_Locale->getText(LOCALE_MOTORCONTROL_SAT_POS)); - sprintf(buf2, "%d", satellitePosition); - strcat(buf, buf2); - paintLine(xpos1, &ypos, width1, buf); + + sprintf(buf1, "%s %d", g_Locale->getText(LOCALE_MOTORCONTROL_SAT_POS), satellitePosition); + paintLine(xpos1, &ypos, width1, buf1); + paintSeparator(xpos1, &ypos, width, g_Locale->getText(LOCALE_MOTORCONTROL_SETTINGS)); } @@ -604,6 +457,10 @@ void CMotorControl::paintHead() void CMotorControl::paintMenu() { + sigscale->reset(); + snrscale->reset(); + lastsnr = lastsig = -1; + frameBuffer->paintBoxRel(x, y + hheight, width, height - hheight, COL_MENUCONTENT_PLUS_0, RADIUS_LARGE, CORNER_BOTTOM); ypos = y + hheight + (mheight >> 1) - 10; @@ -611,8 +468,9 @@ void CMotorControl::paintMenu() int xpos1 = x + 10; int xpos2 = xpos1 + 10 + g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth("(7/yellow)"); int width2 = width - (xpos2 - xpos1) - 10; - int width1 = width - 10; +#if 1 + int width1 = width - 10; paintLine(xpos1, &ypos, width1, "(0/OK)"); if(installerMenue) paintLine(xpos2, ypos, width2, g_Locale->getText(LOCALE_MOTORCONTROL_USER_MENU)); @@ -630,22 +488,16 @@ void CMotorControl::paintMenu() { paintLine(xpos1, &ypos, width1, "(4)"); paintLine(xpos2, ypos, width2, g_Locale->getText(LOCALE_MOTORCONTROL_WEST_LIMIT)); - paintLine(xpos1, &ypos, width1, "(5)"); + paintLine(xpos1, &ypos, width1, "(5/green)"); paintLine(xpos2, ypos, width2, g_Locale->getText(LOCALE_MOTORCONTROL_DISABLE_LIMIT)); paintLine(xpos1, &ypos, width1, "(6)"); paintLine(xpos2, ypos, width2, g_Locale->getText(LOCALE_MOTORCONTROL_EAST_LIMIT)); - paintLine(xpos1, &ypos, width1, "(7)"); + paintLine(xpos1, &ypos, width1, "(7/yellow)"); paintLine(xpos2, ypos, width2, g_Locale->getText(LOCALE_MOTORCONTROL_REF_POSITION)); paintLine(xpos1, &ypos, width1, "(8)"); paintLine(xpos2, ypos, width2, g_Locale->getText(LOCALE_MOTORCONTROL_ENABLE_LIMIT)); paintLine(xpos1, &ypos, width1, "(9)"); paintLine(xpos2, ypos, width2, g_Locale->getText(LOCALE_MOTORCONTROL_CALC_POSITIONS)); - paintLine(xpos1, &ypos, width1, "(+/up)"); - paintLine(xpos2, ypos, width2, g_Locale->getText(LOCALE_MOTORCONTROL_POS_INCREASE)); - paintLine(xpos1, &ypos, width1, "(-/down)"); - paintLine(xpos2, ypos, width2, g_Locale->getText(LOCALE_MOTORCONTROL_POS_DECREASE)); - paintLine(xpos1, &ypos, width1, "(blue)"); - paintLine(xpos2, ypos, width2, g_Locale->getText(LOCALE_MOTORCONTROL_STEP_DRIVE)); } else { @@ -661,14 +513,41 @@ void CMotorControl::paintMenu() paintLine(xpos2, ypos, width2, g_Locale->getText(LOCALE_MOTORCONTROL_NOTDEF)); paintLine(xpos1, &ypos, width1, "(9)"); paintLine(xpos2, ypos, width2, g_Locale->getText(LOCALE_MOTORCONTROL_STEP_DECREASE)); - paintLine(xpos1, &ypos, width1, "(+/up)"); - paintLine(xpos2, ypos, width2, g_Locale->getText(LOCALE_MOTORCONTROL_POS_INCREASE)); - paintLine(xpos1, &ypos, width1, "(-/down)"); - paintLine(xpos2, ypos, width2, g_Locale->getText(LOCALE_MOTORCONTROL_POS_DECREASE)); - paintLine(xpos1, &ypos, width1, "(blue)"); - paintLine(xpos2, ypos, width2, g_Locale->getText(LOCALE_MOTORCONTROL_STEP_DRIVE)); } + paintLine(xpos1, &ypos, width1, "(+/up)"); + paintLine(xpos2, ypos, width2, g_Locale->getText(LOCALE_MOTORCONTROL_POS_INCREASE)); + paintLine(xpos1, &ypos, width1, "(-/down)"); + paintLine(xpos2, ypos, width2, g_Locale->getText(LOCALE_MOTORCONTROL_POS_DECREASE)); + paintLine(xpos1, &ypos, width1, "(blue)"); + paintLine(xpos2, ypos, width2, g_Locale->getText(LOCALE_MOTORCONTROL_STEP_DRIVE)); + paintLine(xpos1, &ypos, width1, "(info)"); + paintLine(xpos2, ypos, width2, g_Locale->getText(LOCALE_MOTORCONTROL_NETWORK)); +#else + paintLine(xpos1, xpos2, &ypos, width2, NEUTRINO_ICON_BUTTON_0, + installerMenue ? g_Locale->getText(LOCALE_MOTORCONTROL_USER_MENU) : g_Locale->getText(LOCALE_MOTORCONTROL_INSTALL_MENU)); + paintLine(xpos1, xpos2, &ypos, width2, NEUTRINO_ICON_BUTTON_1, g_Locale->getText(LOCALE_MOTORCONTROL_STEP_WEST)); + paintLine(xpos1, xpos2, &ypos, width2, NEUTRINO_ICON_BUTTON_2, g_Locale->getText(LOCALE_MOTORCONTROL_HALT)); + paintLine(xpos1, xpos2, &ypos, width2, NEUTRINO_ICON_BUTTON_3, g_Locale->getText(LOCALE_MOTORCONTROL_STEP_EAST)); + + paintLine(xpos1, xpos2, &ypos, width2, NEUTRINO_ICON_BUTTON_4, + installerMenue ? g_Locale->getText(LOCALE_MOTORCONTROL_WEST_LIMIT) : g_Locale->getText(LOCALE_MOTORCONTROL_NOTDEF)); + paintLine(xpos1, xpos2, &ypos, width2, NEUTRINO_ICON_BUTTON_5, + installerMenue ? g_Locale->getText(LOCALE_MOTORCONTROL_DISABLE_LIMIT) : g_Locale->getText(LOCALE_MOTORCONTROL_STORE)); + paintLine(xpos1, xpos2, &ypos, width2, NEUTRINO_ICON_BUTTON_6, + installerMenue ? g_Locale->getText(LOCALE_MOTORCONTROL_EAST_LIMIT) : g_Locale->getText(LOCALE_MOTORCONTROL_STEP_INCREASE)); + paintLine(xpos1, xpos2, &ypos, width2, NEUTRINO_ICON_BUTTON_7, + installerMenue ? g_Locale->getText(LOCALE_MOTORCONTROL_REF_POSITION) : g_Locale->getText(LOCALE_MOTORCONTROL_GOTO)); + paintLine(xpos1, xpos2, &ypos, width2, NEUTRINO_ICON_BUTTON_8, + installerMenue ? g_Locale->getText(LOCALE_MOTORCONTROL_ENABLE_LIMIT) : g_Locale->getText(LOCALE_MOTORCONTROL_NOTDEF)); + paintLine(xpos1, xpos2, &ypos, width2, NEUTRINO_ICON_BUTTON_9, + installerMenue ? g_Locale->getText(LOCALE_MOTORCONTROL_CALC_POSITIONS) : g_Locale->getText(LOCALE_MOTORCONTROL_STEP_DECREASE)); + + paintLine(xpos1, xpos2, &ypos, width2, NEUTRINO_ICON_BUTTON_TOP, g_Locale->getText(LOCALE_MOTORCONTROL_POS_INCREASE)); + paintLine(xpos1, xpos2, &ypos, width2, NEUTRINO_ICON_BUTTON_DOWN, g_Locale->getText(LOCALE_MOTORCONTROL_POS_DECREASE)); + paintLine(xpos1, xpos2, &ypos, width2, NEUTRINO_ICON_BUTTON_BLUE, g_Locale->getText(LOCALE_MOTORCONTROL_STEP_DRIVE)); + paintLine(xpos1, xpos2, &ypos, width2, NEUTRINO_ICON_BUTTON_INFO_SMALL, g_Locale->getText(LOCALE_MOTORCONTROL_NETWORK)); +#endif ypos_status = ypos; } @@ -696,24 +575,19 @@ void CMotorControl::startSatFind(void) void CMotorControl::stopSatFind(void) { - +#if 0 if (satfindpid != -1) { printf("[motorcontrol] killing satfind...\n"); kill(satfindpid, SIGKILL); waitpid(satfindpid, 0, 0); satfindpid = -1; } +#endif } -#define BARWT 10 -#define BAR_BL 2 -#define BARW (BARWT - BAR_BL) -#define BARWW (BARWT - BARW) - void CMotorControl::showSNR() { char percent[10]; - //char ber[20]; int barwidth = 100; uint16_t ssig, ssnr; int sig, snr; @@ -761,3 +635,18 @@ void CMotorControl::showSNR() g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString (posx_snr+2, posy + mheight, sw, percent, COL_MENUCONTENT_TEXT); } } + +void CMotorControl::readNetwork() +{ + CNit nit(0, 0, 0); + nit.Start(); + nit.Stop(); + network = nit.GetNetworkName(); + t_satellite_position pos = nit.getOrbitalPosition(); + if (network.empty()) + network = "unknown"; + + char net[100]; + snprintf(net, sizeof(net), "%03d.%d, %s", abs(pos)/10, abs(pos)%10, network.c_str()); + network = net; +} diff --git a/src/gui/motorcontrol.h b/src/gui/motorcontrol.h index 84ffae7ba..fb4b74dc4 100644 --- a/src/gui/motorcontrol.h +++ b/src/gui/motorcontrol.h @@ -67,18 +67,21 @@ class CMotorControl : public CMenuTarget int32_t satellitePosition; int satfindpid; int lastsnr, lastsig; + int g_sig, g_snr, last_snr, moving; + std::string network; CProgressBar *snrscale, *sigscale; void paintHead(void); void paintMenu(void); void paintStatus(void); void paintLine(int x, int *y, int width, const char *txt); void paintLine(int x, int y, int width, const char *txt); + void paintLine(int ix, int tx, int *y, int pwidth, const char *icon, const char *txt); void paintSeparator(int xpos, int * ypos, int width, const char *txt); - void motorStepEast(void); - void motorStepWest(void); + void motorStep(bool west); void startSatFind(void); void stopSatFind(void); void showSNR(void); + void readNetwork(void); public: