Ejemplo n.º 1
0
static int boot_main(int argc, char *argv[] ) {
	neko_vm *vm;
	value args[2];
	value mload, exc = NULL;

	char* root = getSwitch(argc,argv,"swroot");
	char* rootFromBundle = root ? NULL : getSwitchFromBundle("swroot");

	char* index = getSwitch(argc,argv,"swindex");
	if(!index) index = getSwitchFromBundle("swindex");

#if OSX
	char* tmpRootBuffer = NULL;
	if (rootFromBundle) {
		if (stricmp("SW_BUNDLE_PARENT",rootFromBundle)==0) {
			// folder containing bundle is path:
			root = getBundleRoot();
			strcat(root,"/..");
		} else {
			// path is relative to bundle:
			root = tmpRootBuffer = malloc(FILENAME_MAX);
			sprintf(root,"%s/%s",getBundleRoot(),rootFromBundle);
		}
	}
#endif

	// if root folder is specified, change the current directory:
	if( root ) {
		chdir(root);
#		if OSX
 		if (tmpRootBuffer)
 			free(tmpRootBuffer);
#		endif
	}

	// printf("boot-loader computed working folder: %s\n",root);
	// printf("boot-loader set working folder: %s\n",getcwd(NULL));

	// initialize Neko Virtual Machine
	neko_global_init(&vm);
	vm = neko_vm_alloc(NULL);
	neko_vm_jit(vm,1);
	neko_vm_select(vm);
	mload = neko_default_loader(argv, argc);

	args[0] = alloc_string(index ? index : DEFAULT_INDEX);
	args[1] = mload;
	val_callEx(mload,val_field(mload,val_id("loadmodule")),args,2,&exc);
	if( exc != NULL )
		report(vm,exc);
	vm = NULL;
	neko_global_free();

	while(switches_count--) {
		free(switches[switches_count]);
	}
	if (switches) free(switches);

	return( exc != NULL );
}
Ejemplo n.º 2
0
void displayInfo() {
    Switch_t *swtch;
    unsigned int i, count, lines;

    SENSORS_PER_LINE = RIGHT_HALF / 10;
    lines = SENSORS_PER_LINE;
    lines = (TRAIN_SWITCH_COUNT / lines) + (TRAIN_SWITCH_COUNT % lines);
    count = TRAIN_SWITCH_COUNT;
    kdebug("Debugging Enabled...\r\nNumber of Debug Lines: %d", lines);
    kprintf("====Switches===" MOVE_TO_COL CHANGE_COLOR "Train Calibration:" CHANGE_COLOR "\r\n" MOVE_TO_COL
            "| Train | Velocity | Landmark | Distance (mm) | Next Landmark | ETA (ticks) | ATA (ticks) | Resv          | "
            MOVE_TO_COL, RIGHT_HALF + 5, YELLOW, 0, RIGHT_HALF + 5, 0);
    while (count > 0) {
        for (i = 0; i < MIN(count, SENSORS_PER_LINE); ++i) {
            if (count <= 4) {
                swtch = getSwitch(MULTI_SWITCH_OFFSET + (TRAIN_SWITCH_COUNT - count + i + 1));
            } else {
                swtch = getSwitch(TRAIN_SWITCH_COUNT - count + i + 1);
                if (swtch->id < 10) {
                    kputstr("00");
                } else if (swtch->id < 100) {
                    kputstr("0");
                }
            }
            kprintf("%d: %c    ", swtch->id, SWITCH_CHAR(swtch->state));
        }
        count -= MIN(SENSORS_PER_LINE, count);
        kputstr(NEW_LINE);
    }
    kputstr("\r\n====Sensors====\r\n\r\n\r\n");
    kprintf(SAVE_CURSOR SET_SCROLL RESTORE_CURSOR, TERM_OFFSET + lines + 4, TERMINAL_HEIGHT);
    TERM_BOTTOM = TERM_OFFSET + lines + 4;
}
Ejemplo n.º 3
0
TEST(getSwitch, circularCSW)
{
  MODEL_RESET();
  MIXER_RESET();
  g_model.logicalSw[0] = { SWSRC_SW1, SWSRC_SW1, LS_FUNC_OR };
  g_model.logicalSw[1] = { SWSRC_SW1, SWSRC_SW1, LS_FUNC_AND };

  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);
  EXPECT_EQ(getSwitch(-SWSRC_SW1), true);
  EXPECT_EQ(getSwitch(SWSRC_SW2), false);
  EXPECT_EQ(getSwitch(-SWSRC_SW2), true);
}
Ejemplo n.º 4
0
TEST(getSwitch, OldTypeStickyCSW)
{
  RADIO_RESET();
  MODEL_RESET();
  MIXER_RESET();

  SET_LOGICAL_SWITCH(0, LS_FUNC_AND, SWSRC_SA0, SWSRC_NONE);
  SET_LOGICAL_SWITCH(1, LS_FUNC_OR, SWSRC_SW1, SWSRC_SW2);

  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);
  EXPECT_EQ(getSwitch(SWSRC_SW2), false);

  // now trigger SA0, both switches should become true
  simuSetSwitch(0, -1);
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), true);
  EXPECT_EQ(getSwitch(SWSRC_SW2), true);

  // now release SA0 and SW2 should stay true
  simuSetSwitch(0, 0);
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);
  EXPECT_EQ(getSwitch(SWSRC_SW2), true);

  // now reset logical switches
  logicalSwitchesReset();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);
  EXPECT_EQ(getSwitch(SWSRC_SW2), false);
}
Ejemplo n.º 5
0
TEST(getSwitch, recursiveSW)
{
  MODEL_RESET();
  MIXER_RESET();

  g_model.logicalSw[0] = { SWSRC_RUD, -SWSRC_SW2, LS_FUNC_OR };
  g_model.logicalSw[1] = { SWSRC_ELE, -SWSRC_SW1, LS_FUNC_OR };

  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);
  EXPECT_EQ(getSwitch(SWSRC_SW2), true);

  LS_RECURSIVE_EVALUATION_RESET();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);
  EXPECT_EQ(getSwitch(SWSRC_SW2), true);

  simuSetSwitch(1, 1);
  LS_RECURSIVE_EVALUATION_RESET();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), true);
  EXPECT_EQ(getSwitch(SWSRC_SW2), true);

  LS_RECURSIVE_EVALUATION_RESET();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), true);
  EXPECT_EQ(getSwitch(SWSRC_SW2), false);
}
Ejemplo n.º 6
0
TEST(getSwitch, OldTypeStickyCSW)
{
  MODEL_RESET();
  MIXER_RESET();
  g_model.logicalSw[0] = { SWSRC_SA0, 0, 0, LS_FUNC_AND };
  g_model.logicalSw[1] = { SWSRC_SW1, SWSRC_SW2, 0, LS_FUNC_OR };

  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);
  EXPECT_EQ(getSwitch(SWSRC_SW2), false);

  // now trigger SA0, both switches should become true
  simuSetSwitch(0, -1);
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), true);
  EXPECT_EQ(getSwitch(SWSRC_SW2), true);

  // now release SA0 and SW2 should stay true
  simuSetSwitch(0, 0);
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);
  EXPECT_EQ(getSwitch(SWSRC_SW2), true);

  // now reset logical switches
  logicalSwitchesReset();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);
  EXPECT_EQ(getSwitch(SWSRC_SW2), false);
}
Ejemplo n.º 7
0
void main(void)
{
	unsigned char light=0;
	unsigned char lastkey=0;			// Mark key to be off

	P0=~0x00;			// Light off

	for (;;)
	{
		if (getSwitch() == 1)
		{
			if (lastkey == 0)			// Switch is from Off to On
			{
				lastkey = 1;			// Mark switch is on now
				if (light == 0)			// Light is Off
				{
					setLight(1);		// Turn on the light now
					light = 1; 			// Mark light to On
				}
				else					// Light is on
				{
					setLight(0);  		// Turn off the light now
					light = 0;			// Mark light to Off
				}
			}	
		}
		else
		{
			lastkey = 0;				// Switch is off
		}
//		delay(30000);   				// for debug use
	}
} /* main */ 
Ejemplo n.º 8
0
int trainSwitch(unsigned int sw, char ch) {
    char buf[2];
    unsigned int ss;
    Switch_t *swtch;

    buf[0] = 0;
    switch (ch) {
    case 'C':
    case 'c':
        buf[0] = TRAIN_AUX_CURVE;
        ss = DIR_CURVED;
        break;
    case 'S':
    case 's':
        buf[0] = TRAIN_AUX_STRAIGHT;
        ss = DIR_STRAIGHT;
        break;
    default:
        kerror("Invalid switch character: %c", ch);
        return INVALID_SWITCH_STATE;
    }

    swtch = getSwitch(sw);
    if (buf[0] != 0  && sw >= 0 && sw <= 255) {
        buf[1] = sw;
        trnputs(buf, 2);
        swtch->state = ss;
        printSwitch(swtch->id, (toUpperCase(ch)));
        return 0;
    }
    return INVALID_SWITCH_ID;
}
Ejemplo n.º 9
0
void CSwitchMgr::delSwitch(INT4 sockfd)
{
    LOG_INFO_FMT("before delete switch with sockfd[%d], switch map size[%lu] ...", 
        sockfd, m_sws.size());

    m_rwlock.wlock();

    CSmartPtr<CSwitch> sw = getSwitch(sockfd);
    if (sw.isNotNull())
    {
        sw->setState(SW_STATE_CLOSED);

        CControl::getInstance()->getTopoMgr().deleteSwitch(sw->getDpid());

		CHostMgr::getInstance()->delHostBySw(sw);

        delTagMap(sw->getTag());
		CControl::getInstance()->getTagMgr().release(sw->getTag());

        if (isValidMac(sw->getSwMac()))
        {
            delMacMap(sw->getSwMac());
            delIpMap(sw->getSwIp());
        }
        delDpidMap(sw->getDpid());
        delSwitchMap(sockfd);
    }

    m_rwlock.unlock();

    LOG_INFO_FMT("after delete switch with sockfd[%d], switch map size[%lu] ...", 
        sockfd, m_sws.size());
}
Ejemplo n.º 10
0
TEST(getSwitch, inputWithTrim)
{
  MODEL_RESET();
  modelDefault(0);
  MIXER_RESET();

  g_model.logicalSw[0] = { LS_FUNC_VPOS, MIXSRC_FIRST_INPUT, 0, 0 };

  doMixerCalculations();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);

  setTrimValue(0, 0, 32);
  doMixerCalculations();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), true);
}
Ejemplo n.º 11
0
bool QikFlat::Disconnect()
{
    sf->closePort();
    delete sf;	
    DEBUG(INDI::Logger::DBG_SESSION, "ARDUINO BOARD DISCONNECTED.");
    IDSetSwitch (getSwitch("CONNECTION"),"DISCONNECTED\n");
    return true;
}
Ejemplo n.º 12
0
void LapsusDaemon::emitSwitch()
{
	while(switchesToEmit.size() > 0)
	{
		QValueList<QDBusData> params;
		QString name = switchesToEmit.first();
		switchesToEmit.pop_front();

		params.append(QDBusData::fromString(name));
		params.append(QDBusData::fromBool(getSwitch(name)));

		sendSignal("switchChanged", params);
	}
}
Ejemplo n.º 13
0
/*
 * *	Fonction de decodage d un appui sur un interrupteur
 **	Si la nouvelle valeur est differente de l ancienne, elle est mise a jour, et celle-ci est reporte dans un fichier de log.
 **	Renvoie 0 si un changement de valeur a eu lieu, 1 sinon.
 */
int decodeMessageSwitch(char* message, struct Sensor * p_sensor) {
	int switch_button = getSwitch(message);
	if (switch_button != NO_BUTTON) {		
		/* Si la nouvelle valeur est differente de l ancienne */
		if (switch_button != p_sensor->value) {
			p_sensor->value = switch_button;
			printf("[ComponentInterface] Nouvelle valeur pour l'interrupteur, ID : %s; valeur : %f \n", p_sensor->id, p_sensor->value);
			gLogsLog(p_sensor->id, p_sensor->value);
			return VALUE_CHANGE;
		} else {
			return NO_CHANGE;
		}
	}
	return NO_BUTTON;
}
Ejemplo n.º 14
0
track_edge *getNextEdge(track_node *node) {
    Switch_t *swtch;
    switch (d(node).type) {
        case NODE_SENSOR:
        case NODE_MERGE:
        case NODE_ENTER:
            return &(d(node).edge[DIR_AHEAD]);
        case NODE_BRANCH:
            swtch = getSwitch(node->num);
            return &(d(node).edge[d(swtch).state]);
        case NODE_EXIT:
            return NULL;
        case NODE_NONE:
        default:
            return NULL;
    }
}
Ejemplo n.º 15
0
bool AAGCloudWatcher::isWetRain() {
  ISwitchVectorProperty *svpRC = getSwitch("rainConditions");

  for (int i = 0 ; i < svpRC->nsp ; i++) {
    if (strcmp("wet", svpRC->sp[i].name) == 0) {
      if (svpRC->sp[i].s == ISS_ON) {
        return true;
      }
    }

    if (strcmp("rain", svpRC->sp[i].name) == 0) {
      if (svpRC->sp[i].s == ISS_ON) {
        return true;
      }
    }
  }

  return false;
}
Ejemplo n.º 16
0
MainForm::MainForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MainForm)
{
    ui->setupUi(this);

    q = QApplication::clipboard();
    q->clear(QClipboard::Selection);

    st = new ShowText(0);
    //st->setWindowFlags(Qt::Dialog);
    trayIcon = new QSystemTrayIcon(QIcon("ScreenCatch64.png"),this);

    quitAction = new QAction("Quit",this);
    //connect(quitAction,SIGNAL(triggered()),qApp,SLOT(quit()));
    connect(quitAction,SIGNAL(triggered()),this,SLOT(aquit()));

    catchSwitch = new QAction("on/off",this);
    catchSwitch->setCheckable(true);
    catchSwitch->setChecked(true);
    connect(catchSwitch,SIGNAL(triggered()),this,SLOT(getSwitch()));

    tiMenu = new QMenu(this);
    tiMenu->addAction(catchSwitch);
    tiMenu->addAction(quitAction);
    trayIcon->setContextMenu(tiMenu);

    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()),this, SLOT(checkClipBoard()));
    timer->start(500);

    stimer = new QTimer(this);
    connect(stimer, SIGNAL(timeout()),this, SLOT(screenShot()));
    //stimer->start(5000);

    connect(this,SIGNAL(emitShow(QString)),st,SLOT(showMe(QString)));
    trayIcon->show();
}
Ejemplo n.º 17
0
int parse(const MyString& cmd, MyString* name, Vector<MyString>* pathes, Vector<MyString>* switches)
{
    if (name == nullptr || pathes == nullptr || switches == nullptr)
    {
        return -1;
    }

    pathes->clear();
    switches->clear();

    int i = getCmd(cmd, 0, name);
    if (i == cmd.size())
    {
        return 0;
    }
    if (*name == _T("mkdir"))
    {
        while (_istspace(cmd[i]))
            ++i;
        int j = cmd.size() - 1;
        while (_istspace(cmd[j]))
            --j;
        MyString path = cmd.substr(i, j - i + 1);
        pathes->append(path);
        return 0;
    }

    for (; i < cmd.size();)
    {
        if (_istspace(cmd[i]))
        {
            ++i;
        }
        else if (cmd[i] != _T('/'))
        {
            MyString path;
            i = getPath(cmd, i, &path);
            if (!isPath(path) && !hasWildcard(path))
            {
                printf("文件名、目录名或卷标语法不正确\n");
                *name = _T("");
                pathes->clear();
                switches->clear();
                return -1;
            }
            pathes->append(path);
        }
        else if (cmd[i] == _T('/'))
        {
            MyString s;
            i = getSwitch(cmd, i, &s);
            switches->append(s);
        }
        else
        {
            assert(0);
            return -1;
        }
    }
    return 0;
}
Ejemplo n.º 18
0
void menuModelLogicalSwitches(uint8_t event)
{
  INCDEC_DECLARE_VARS(EE_MODEL);

  MENU(STR_MENULOGICALSWITCHES, menuTabModel, e_LogicalSwitches, NUM_LOGICAL_SWITCH+1, {0, NAVIGATION_LINE_BY_LINE|LS_FIELD_LAST/*repeated...*/});

  uint8_t   k = 0;
  int8_t    sub = m_posVert - 1;
  horzpos_t horz = m_posHorz;

  for (uint8_t i=0; i<LCD_LINES-1; i++) {
    coord_t y = MENU_HEADER_HEIGHT + 1 + i*FH;
    k = i+s_pgOfs;
    uint8_t attr = (sub==k ? ((s_editMode>0) ? BLINK|INVERS : INVERS)  : 0);
    uint8_t attr1 = (horz==1 ? attr : 0);
    uint8_t attr2 = (horz==2 ? attr : 0);
    LogicalSwitchData * cs = lswAddress(k);

    // CSW name
    uint8_t sw = SWSRC_SW1+k;
    putsSwitches(0, y, sw, (getSwitch(sw) ? BOLD : 0) | ((sub==k && CURSOR_ON_LINE()) ? INVERS : 0));

    // CSW func
    lcd_putsiAtt(CSW_1ST_COLUMN, y, STR_VCSWFUNC, cs->func, horz==0 ? attr : 0);

    // CSW params
    uint8_t cstate = lswFamily(cs->func);
#if defined(CPUARM)
    int16_t v1_val=cs->v1, v1_min=0, v1_max=MIXSRC_LAST_TELEM, v2_min=0, v2_max=MIXSRC_LAST_TELEM;
    int16_t v3_min=-1, v3_max=100;
#else
    int8_t v1_min=0, v1_max=MIXSRC_LAST_TELEM, v2_min=0, v2_max=MIXSRC_LAST_TELEM;
    #define v1_val cs->v1
#endif

    if (cstate == LS_FAMILY_BOOL || cstate == LS_FAMILY_STICKY) {
      putsSwitches(CSW_2ND_COLUMN, y, cs->v1, attr1);
      putsSwitches(CSW_3RD_COLUMN, y, cs->v2, attr2);
      v1_min = SWSRC_FIRST_IN_LOGICAL_SWITCHES; v1_max = SWSRC_LAST_IN_LOGICAL_SWITCHES;
      v2_min = SWSRC_FIRST_IN_LOGICAL_SWITCHES; v2_max = SWSRC_LAST_IN_LOGICAL_SWITCHES;
      INCDEC_SET_FLAG(EE_MODEL | INCDEC_SWITCH);
      INCDEC_ENABLE_CHECK(isSwitchAvailableInLogicalSwitches);
    }
#if defined(CPUARM)
    else if (cstate == LS_FAMILY_EDGE) {
      putsSwitches(CSW_2ND_COLUMN, y, cs->v1, attr1);
      putsEdgeDelayParam(CSW_3RD_COLUMN, y, cs, attr2, horz==LS_FIELD_V3 ? attr : 0);
      v1_min = SWSRC_FIRST_IN_LOGICAL_SWITCHES; v1_max = SWSRC_LAST_IN_LOGICAL_SWITCHES;
      v2_min=-129; v2_max = 122;
      v3_max = 222 - cs->v2;
      if (horz == 1) {
        INCDEC_SET_FLAG(EE_MODEL | INCDEC_SWITCH);
        INCDEC_ENABLE_CHECK(isSwitchAvailableInLogicalSwitches);
      }
      else {
        INCDEC_SET_FLAG(EE_MODEL);
        INCDEC_ENABLE_CHECK(NULL);
      }
    }
#endif
    else if (cstate == LS_FAMILY_COMP) {
#if defined(CPUARM)
      v1_val = (uint8_t)cs->v1;
#endif
      putsMixerSource(CSW_2ND_COLUMN, y, v1_val, attr1);
      putsMixerSource(CSW_3RD_COLUMN, y, cs->v2, attr2);
      INCDEC_SET_FLAG(EE_MODEL | INCDEC_SOURCE);
      INCDEC_ENABLE_CHECK(isSourceAvailable);
    }
    else if (cstate == LS_FAMILY_TIMER) {
      lcd_outdezAtt(CSW_2ND_COLUMN, y, lswTimerValue(cs->v1), LEFT|PREC1|attr1);
      lcd_outdezAtt(CSW_3RD_COLUMN, y, lswTimerValue(cs->v2), LEFT|PREC1|attr2);
      v1_min = v2_min = -128;
      v1_max = v2_max = 122;
      INCDEC_SET_FLAG(EE_MODEL);
      INCDEC_ENABLE_CHECK(NULL);
    }
    else {
#if defined(CPUARM)
      v1_val = (uint8_t)cs->v1;
#endif
      putsMixerSource(CSW_2ND_COLUMN, y, v1_val, attr1);
      if (horz == 1) {
        INCDEC_SET_FLAG(EE_MODEL | INCDEC_SOURCE);
        INCDEC_ENABLE_CHECK(isSourceAvailableInCustomSwitches);
      }
      else {
        INCDEC_SET_FLAG(EE_MODEL);
        INCDEC_ENABLE_CHECK(NULL);
      }
#if defined(CPUARM)
      putsChannelValue(CSW_3RD_COLUMN, y, v1_val, calc100toRESX(cs->v2), LEFT|attr2);
      v2_min = -30000;
      v2_max = 30000;
#elif defined(FRSKY)
      if (v1_val >= MIXSRC_FIRST_TELEM) {
        putsTelemetryChannelValue(CSW_3RD_COLUMN, y, v1_val - MIXSRC_FIRST_TELEM, convertLswTelemValue(cs), LEFT|attr2);
        v2_max = maxTelemValue(v1_val - MIXSRC_FIRST_TELEM + 1);
#if defined(CPUARM)
        if (cs->func == LS_FUNC_DIFFEGREATER)
          v2_min = -v2_max;
        else if (cs->func == LS_FUNC_ADIFFEGREATER)
          v2_min = 0;
        else
          v2_min = minTelemValue(v1_val - MIXSRC_FIRST_TELEM + 1);
        if (horz == 2 && v2_max-v2_min > 1000)
          INCDEC_SET_FLAG(EE_MODEL | INCDEC_REP10 | NO_INCDEC_MARKS);
        if (cs->v2 < v2_min || cs->v2 > v2_max) {
          cs->v2 = 0;
          eeDirty(EE_MODEL);
        }
#else
        if (cstate == LS_FAMILY_OFS) {
          v2_min = -128;
          v2_max -= 128;
        }
        else {
          v2_max = min((uint8_t)127, (uint8_t)v2_max);
          v2_min = -v2_max;
        }
        if (cs->v2 > v2_max) {
          cs->v2 = v2_max;
          eeDirty(EE_MODEL);
        }
#endif
      }
      else {
        lcd_outdezAtt(CSW_3RD_COLUMN, y, cs->v2, LEFT|attr2);
#if defined(CPUARM) && defined(GVARS)
        if (v1_val >= MIXSRC_GVAR1) {
          v2_min = -1024; v2_max = +1024;
        }
        else
#endif
        {
          v2_min = -LIMIT_EXT_PERCENT; v2_max = +LIMIT_EXT_PERCENT;
        }
      }
#else
      if (v1_val >= MIXSRC_FIRST_TELEM) {
        putsTelemetryChannelValue(CSW_3RD_COLUMN, y, v1_val - MIXSRC_FIRST_TELEM, convertLswTelemValue(cs), LEFT|attr2);
        v2_min = -128; v2_max = 127;
      }
      else {
        lcd_outdezAtt(CSW_3RD_COLUMN, y, cs->v2, LEFT|attr2);
        v2_min = -LIMIT_EXT_PERCENT; v2_max = +LIMIT_EXT_PERCENT;
      }
#endif
    }

    // CSW AND switch
#if defined(CPUARM)
    putsSwitches(CSW_4TH_COLUMN, y, cs->andsw, horz==LS_FIELD_ANDSW ? attr : 0);
#else
    uint8_t andsw = cs->andsw;
    if (andsw > SWSRC_LAST_SWITCH) {
      andsw += SWSRC_SW1-SWSRC_LAST_SWITCH-1;
    }
    putsSwitches(CSW_4TH_COLUMN, y, andsw, horz==LS_FIELD_ANDSW ? attr : 0);
#endif

#if defined(CPUARM)
    // CSW duration
    if (cs->duration > 0)
      lcd_outdezAtt(CSW_5TH_COLUMN, y, cs->duration, (horz==LS_FIELD_DURATION ? attr : 0)|PREC1|LEFT);
    else
      lcd_putsiAtt(CSW_5TH_COLUMN, y, STR_MMMINV, 0, horz==LS_FIELD_DURATION ? attr : 0);

    // CSW delay
    if (cstate == LS_FAMILY_EDGE) {
      lcd_puts(CSW_6TH_COLUMN, y, STR_NA);
      if (attr && horz == LS_FIELD_DELAY) {
        REPEAT_LAST_CURSOR_MOVE();
      }
    }
    else if (cs->delay > 0) {
      lcd_outdezAtt(CSW_6TH_COLUMN, y, cs->delay, (horz==LS_FIELD_DELAY ? attr : 0)|PREC1|LEFT);
    }
    else {
      lcd_putsiAtt(CSW_6TH_COLUMN, y, STR_MMMINV, 0, horz==LS_FIELD_DELAY ? attr : 0);
    }

    if (attr && horz == LS_FIELD_V3 && cstate != LS_FAMILY_EDGE) {
      REPEAT_LAST_CURSOR_MOVE();
    }
#endif

    if ((s_editMode>0 || p1valdiff) && attr) {
      switch (horz) {
        case LS_FIELD_FUNCTION:
        {
#if defined(CPUARM)
          cs->func = checkIncDec(event, cs->func, 0, LS_FUNC_MAX, EE_MODEL, isLogicalSwitchFunctionAvailable);
#else
          CHECK_INCDEC_MODELVAR_ZERO(event, cs->func, LS_FUNC_MAX);
#endif
          uint8_t new_cstate = lswFamily(cs->func);
          if (cstate != new_cstate) {
#if defined(CPUARM)
            if (new_cstate == LS_FAMILY_TIMER) {
              cs->v1 = cs->v2 = -119;
            }
            else if (new_cstate == LS_FAMILY_EDGE) {
              cs->v1 = 0; cs->v2 = -129; cs->v3 = 0;
            }
            else {
              cs->v1 = cs->v2 = 0;
            }
#else
            cs->v1 = cs->v2 = (new_cstate==LS_FAMILY_TIMER ? -119/*1.0*/ : 0);
#endif
          }
          break;
        }
        case LS_FIELD_V1:
          cs->v1 = CHECK_INCDEC_PARAM(event, v1_val, v1_min, v1_max);
          break;
        case LS_FIELD_V2:
          cs->v2 = CHECK_INCDEC_PARAM(event, cs->v2, v2_min, v2_max);
          if (checkIncDec_Ret) TRACE("v2=%d", cs->v2);
          break;
#if defined(CPUARM)
        case LS_FIELD_V3:
          cs->v3 = CHECK_INCDEC_PARAM(event, cs->v3, v3_min, v3_max);
          break;
#endif
        case LS_FIELD_ANDSW:
#if defined(CPUARM)
          INCDEC_SET_FLAG(EE_MODEL | INCDEC_SWITCH);
          INCDEC_ENABLE_CHECK(isSwitchAvailableInLogicalSwitches);
          cs->andsw = CHECK_INCDEC_PARAM(event, cs->andsw, -MAX_LS_ANDSW, MAX_LS_ANDSW);
#else
          CHECK_INCDEC_MODELVAR_ZERO(event, cs->andsw, MAX_LS_ANDSW);
#endif
          break;
#if defined(CPUARM)
        case LS_FIELD_DURATION:
          CHECK_INCDEC_MODELVAR_ZERO(event, cs->duration, MAX_LS_DURATION);
          break;
        case LS_FIELD_DELAY:
          CHECK_INCDEC_MODELVAR_ZERO(event, cs->delay, MAX_LS_DELAY);
          break;
#endif
      }
    }
  }
}
Ejemplo n.º 19
0
void menuModelLogicalSwitches(uint8_t event)
{
  SIMPLE_MENU(STR_MENULOGICALSWITCHES, menuTabModel, e_LogicalSwitches, NUM_LOGICAL_SWITCH+1);

  coord_t y = 0;
  uint8_t k = 0;
  int8_t sub = m_posVert - 1;

  switch (event) {
#if defined(ROTARY_ENCODER_NAVIGATION)
    case EVT_ROTARY_BREAK:
#endif
    case EVT_KEY_FIRST(KEY_RIGHT):
    case EVT_KEY_FIRST(KEY_ENTER):
      if (sub >= 0) {
        s_currIdx = sub;
        pushMenu(menuModelLogicalSwitchOne);
      }
      break;
  }

  for (uint8_t i=0; i<LCD_LINES-1; i++) {
    y = 1 + (i+1)*FH;
    k = i+s_pgOfs;
    LogicalSwitchData * cs = lswAddress(k);

    // CSW name
    uint8_t sw = SWSRC_SW1+k;

    putsSwitches(0, y, sw, (sub==k ? INVERS : 0) | (getSwitch(sw) ? BOLD : 0));

    if (cs->func > 0) {
      // CSW func
      lcd_putsiAtt(CSW_1ST_COLUMN, y, STR_VCSWFUNC, cs->func, 0);

      // CSW params
      uint8_t cstate = lswFamily(cs->func);

      if (cstate == LS_FAMILY_BOOL || cstate == LS_FAMILY_STICKY) {
        putsSwitches(CSW_2ND_COLUMN, y, cs->v1, 0);
        putsSwitches(CSW_3RD_COLUMN, y, cs->v2, 0);
      }
      else if (cstate == LS_FAMILY_COMP) {
        putsMixerSource(CSW_2ND_COLUMN, y, cs->v1, 0);
        putsMixerSource(CSW_3RD_COLUMN, y, cs->v2, 0);
      }
      else if (cstate == LS_FAMILY_EDGE) {
        putsSwitches(CSW_2ND_COLUMN, y, cs->v1, 0);
        putsEdgeDelayParam(CSW_3RD_COLUMN, y, cs, 0, 0);
      }
      else if (cstate == LS_FAMILY_TIMER) {
        lcd_outdezAtt(CSW_2ND_COLUMN, y, cs->v1+1, LEFT);
        lcd_outdezAtt(CSW_3RD_COLUMN, y, cs->v2+1, LEFT);
      }
      else {
        uint8_t v1 = cs->v1;
        putsMixerSource(CSW_2ND_COLUMN, y, v1, 0);
        if (v1 >= MIXSRC_FIRST_TELEM) {
          putsTelemetryChannelValue(CSW_3RD_COLUMN, y, v1 - MIXSRC_FIRST_TELEM, convertLswTelemValue(cs), LEFT);
        }
        else {
          lcd_outdezAtt(CSW_3RD_COLUMN, y, cs->v2, LEFT);
        }
      }

      // CSW and switch
      putsSwitches(CSW_4TH_COLUMN, y, cs->andsw, 0);
    }
  }
}
Ejemplo n.º 20
0
void menuModelLogicalSwitchOne(uint8_t event)
{
  TITLE(STR_MENULOGICALSWITCH);

  LogicalSwitchData * cs = lswAddress(s_currIdx);
  uint8_t sw = SWSRC_SW1+s_currIdx;
  putsSwitches(14*FW, 0, sw, (getSwitch(sw) ? BOLD : 0));

  SUBMENU_NOTITLE(LS_FIELD_COUNT, {0, 0, 1, 0 /*, 0...*/});

  int8_t sub = m_posVert;

  INCDEC_DECLARE_VARS(EE_MODEL);

  int v1_val = cs->v1;

  for (uint8_t k=0; k<LCD_LINES-1; k++) {
    coord_t y = MENU_HEADER_HEIGHT + 1 + k*FH;
    uint8_t i = k + s_pgOfs;
    uint8_t attr = (sub==i ? (s_editMode>0 ? BLINK|INVERS : INVERS) : 0);
    uint8_t cstate = lswFamily(cs->func);
    switch(i) {
      case LS_FIELD_FUNCTION:
        lcd_putsLeft(y, STR_FUNC);
        lcd_putsiAtt(CSWONE_2ND_COLUMN, y, STR_VCSWFUNC, cs->func, attr);
        if (attr) {
          cs->func = checkIncDec(event, cs->func, 0, LS_FUNC_MAX, EE_MODEL, isLogicalSwitchFunctionAvailable);
          uint8_t new_cstate = lswFamily(cs->func);
          if (cstate != new_cstate) {
            if (new_cstate == LS_FAMILY_TIMER) {
              cs->v1 = cs->v2 = 0;
            }
            else if (new_cstate == LS_FAMILY_EDGE) {
              cs->v1 = 0; cs->v2 = -129; cs->v3 = 0;
            }
            else {
              cs->v1 = cs->v2 = 0;
            }
          }
        }
        break;
      case LS_FIELD_V1:
      {
        lcd_putsLeft(y, STR_V1);
        int v1_min=0, v1_max=MIXSRC_LAST_TELEM;
        if (cstate == LS_FAMILY_BOOL || cstate == LS_FAMILY_STICKY || cstate == LS_FAMILY_EDGE) {
          putsSwitches(CSWONE_2ND_COLUMN, y, v1_val, attr);
          v1_min = SWSRC_OFF+1; v1_max = SWSRC_ON-1;
        }
        else if (cstate == LS_FAMILY_TIMER) {
          lcd_outdezAtt(CSWONE_2ND_COLUMN, y, v1_val+1, LEFT|attr);
          v1_max = 99;
        }
        else {
          v1_val = (uint8_t)cs->v1;
          putsMixerSource(CSWONE_2ND_COLUMN, y, v1_val, attr);
          INCDEC_SET_FLAG(EE_MODEL | INCDEC_SOURCE);
          INCDEC_ENABLE_CHECK(isSourceAvailable);
        }
        if (attr) {
          cs->v1 = CHECK_INCDEC_PARAM(event, v1_val, v1_min, v1_max);
        }
        break;
      }
      case LS_FIELD_V2:
      {
        lcd_putsLeft(y, STR_V2);
        int v2_min=0, v2_max=MIXSRC_LAST_TELEM;
        if (cstate == LS_FAMILY_BOOL || cstate == LS_FAMILY_STICKY) {
          putsSwitches(CSWONE_2ND_COLUMN, y, cs->v2, attr);
          v2_min = SWSRC_OFF+1; v2_max = SWSRC_ON-1;
        }
        else if (cstate == LS_FAMILY_TIMER) {
          lcd_outdezAtt(CSWONE_2ND_COLUMN, y, cs->v2+1, LEFT|attr);
          v2_max = 99;
        }
        else if (cstate == LS_FAMILY_EDGE) {
          putsEdgeDelayParam(CSWONE_2ND_COLUMN, y, cs, m_posHorz==0 ? attr : 0, m_posHorz==1 ? attr : 0);
          if (s_editMode <= 0) continue;
          if (attr && m_posHorz==1) {
            CHECK_INCDEC_MODELVAR(event, cs->v3, -1, 222 - cs->v2);
            break;
          }
          v2_min = -129; v2_max = 122;
        }
        else if (cstate == LS_FAMILY_COMP) {
          putsMixerSource(CSWONE_2ND_COLUMN, y, cs->v2, attr);
          INCDEC_SET_FLAG(EE_MODEL | INCDEC_SOURCE);
          INCDEC_ENABLE_CHECK(isSourceAvailable);
        }
        else {
#if defined(FRSKY)
          if (v1_val >= MIXSRC_FIRST_TELEM) {
            putsTelemetryChannelValue(CSWONE_2ND_COLUMN, y, v1_val - MIXSRC_FIRST_TELEM, convertLswTelemValue(cs), attr|LEFT);
            v2_max = maxTelemValue(v1_val - MIXSRC_FIRST_TELEM + 1);
            if (cs->func == LS_FUNC_DIFFEGREATER)
              v2_min = -v2_max;
            else if (cs->func == LS_FUNC_ADIFFEGREATER)
              v2_min = 0;
            else
              v2_min = minTelemValue(v1_val - MIXSRC_FIRST_TELEM + 1);
            INCDEC_SET_FLAG(EE_MODEL | INCDEC_REP10 | NO_INCDEC_MARKS);
            if (cs->v2 < v2_min || cs->v2 > v2_max) {
              cs->v2 = 0;
              eeDirty(EE_MODEL);
            }
          }
          else
#endif
          {
            v2_min = -LIMIT_EXT_PERCENT; v2_max = +LIMIT_EXT_PERCENT;
            lcd_outdezAtt(CSWONE_2ND_COLUMN, y, cs->v2, LEFT|attr);
          }
        }

        if (attr) {
          CHECK_INCDEC_MODELVAR(event, cs->v2, v2_min, v2_max);
        }
        break;
      }
      case LS_FIELD_ANDSW:
        lcd_putsLeft(y, STR_AND_SWITCH);
        putsSwitches(CSWONE_2ND_COLUMN, y, cs->andsw, attr);
        if (attr) CHECK_INCDEC_MODELVAR(event, cs->andsw, -MAX_LS_ANDSW, MAX_LS_ANDSW);
        break;
      case LS_FIELD_DURATION:
        lcd_putsLeft(y, STR_DURATION);
        if (cs->duration > 0)
          lcd_outdezAtt(CSWONE_2ND_COLUMN, y, cs->duration, attr|PREC1|LEFT);
        else
          lcd_putsiAtt(CSWONE_2ND_COLUMN, y, STR_MMMINV, 0, attr);
        if (attr) CHECK_INCDEC_MODELVAR_ZERO(event, cs->duration, MAX_LS_DURATION);
        break;
      case LS_FIELD_DELAY:
        lcd_putsLeft(y, STR_DELAY);
        if (cs->delay > 0)
          lcd_outdezAtt(CSWONE_2ND_COLUMN, y, cs->delay, attr|PREC1|LEFT);
        else
          lcd_putsiAtt(CSWONE_2ND_COLUMN, y, STR_MMMINV, 0, attr);
        if (attr) CHECK_INCDEC_MODELVAR_ZERO(event, cs->delay, MAX_LS_DELAY);
        break;
    }
  }
}
Ejemplo n.º 21
0
TEST(getSwitch, undefCSW)
{
  MODEL_RESET();
  EXPECT_EQ(getSwitch(NUM_PSWITCH), false);
  EXPECT_EQ(getSwitch(-NUM_PSWITCH), true); // no good answer there!
}
Ejemplo n.º 22
0
TEST(getSwitch, VfasWithDelay)
{
  MODEL_RESET();
  MIXER_RESET();
  memclear(&frskyData, sizeof(frskyData));
  /*
  Test for logical switch:
      L1  Vfas < 9.6 Delay (0.5s)

  (gdb) print Open9xX9D::g_model.logicalSw[0] 
  $3 = {v1 = -40 '\330', v2 = 96, v3 = 0, func = 4 '\004', delay = 5 '\005', duration = 0 '\000', andsw = 0 '\000'}
  */
  g_model.logicalSw[0] = {-40, 96, 0, 4, 5, 0, 0};
  frskyData.hub.vfas = 150;   //unit is 100mV

  //telemetry streaming is FALSE, so L1 should be FALSE no matter what value Vfas has
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);

  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);

  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);

  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);

  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);

  //every logicalSwitchesTimerTick() represents 100ms
  //so now after 5 ticks we should still have a FALSE value
  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);

  //now turn on telemetry
  EXPECT_EQ(TELEMETRY_STREAMING(), false);
  frskyData.rssi[0].value = 50;
  EXPECT_EQ(TELEMETRY_STREAMING(), true);

  //vfas is 15.0V so L1 should still be FALSE
  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);
  logicalSwitchesTimerTick();
  logicalSwitchesTimerTick();
  logicalSwitchesTimerTick();
  logicalSwitchesTimerTick();
  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);

  //now reduce vfas to 9.5V and L1 should become TRUE after 0.5s
  frskyData.hub.vfas = 95;
  evalLogicalSwitches();

  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);

  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);

  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);

  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);

  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), true);

  logicalSwitchesTimerTick();
  logicalSwitchesTimerTick();
  logicalSwitchesTimerTick();
  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), true);


  //now stop telemetry, L1 should become FALSE immediatelly
  frskyData.rssi[0].value = 0;
  EXPECT_EQ(TELEMETRY_STREAMING(), false);
  evalLogicalSwitches();

  logicalSwitchesTimerTick();
  logicalSwitchesTimerTick();
  logicalSwitchesTimerTick();
  logicalSwitchesTimerTick();
  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);
}
Ejemplo n.º 23
0
TEST(getSwitch, RssiWithDuration)
{
  MODEL_RESET();
  MIXER_RESET();
  memclear(&frskyData, sizeof(frskyData));
  /*
  Test for logical switch:
      L1  RSSI > 10 Duration (0.5s)

  (gdb) print Open9xX9D::g_model.logicalSw[0] 
  $1 = {v1 = -56 '\310', v2 = 10, v3 = 0, func = 3 '\003', delay = 0 '\000', duration = 5 '\005', andsw = 0 '\000'}
  */
  g_model.logicalSw[0] = {-56, 10, 0, 3, 0, 5, 0};

  EXPECT_EQ(TELEMETRY_STREAMING(), false);

  evalLogicalSwitches();
  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);

  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);

  //now set RSSI to 5, L1 should still be FALSE
  frskyData.rssi[0].value = 5;
  evalLogicalSwitches();
  EXPECT_EQ(TELEMETRY_STREAMING(), true);

  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);

  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);

  //now set RSSI to 100, L1 should become TRUE for 0.5s
  frskyData.rssi[0].value = 100;
  evalLogicalSwitches();
  EXPECT_EQ(TELEMETRY_STREAMING(), true);

  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), true);

  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), true);

  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), true);

  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), true);

  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);

  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);

  //repeat  telemetry streaming OFF and ON to test for duration processing
  frskyData.rssi[0].value = 0;
  evalLogicalSwitches();
  EXPECT_EQ(TELEMETRY_STREAMING(), false);

  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);

  //now set RSSI to 100, L1 should become TRUE for 0.5s
  frskyData.rssi[0].value = 100;
  evalLogicalSwitches();
  EXPECT_EQ(TELEMETRY_STREAMING(), true);

  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), true);

  logicalSwitchesTimerTick();
  logicalSwitchesTimerTick();
  logicalSwitchesTimerTick();
  logicalSwitchesTimerTick();
  evalLogicalSwitches();
  EXPECT_EQ(getSwitch(SWSRC_SW1), false);
}
Ejemplo n.º 24
0
void menuMainView(uint8_t event)
{
  STICK_SCROLL_DISABLE();

  uint8_t view = g_eeGeneral.view;
  uint8_t view_base = view & 0x0f;

  switch(event) {

    case EVT_ENTRY:
      killEvents(KEY_EXIT);
      killEvents(KEY_UP);
      killEvents(KEY_DOWN);
      break;

    /* TODO if timer2 is OFF, it's possible to use this timer2 as in er9x...
    case EVT_KEY_BREAK(KEY_MENU):
      if (view_base == VIEW_TIMER2) {
        Timer2_running = !Timer2_running;
        AUDIO_KEYPAD_UP();
      }
    break;
    */

    case EVT_KEY_BREAK(KEY_RIGHT):
    case EVT_KEY_BREAK(KEY_LEFT):
      if (view_base <= VIEW_INPUTS) {
#if defined(PCBSKY9X)
        if (view_base == VIEW_INPUTS)
          g_eeGeneral.view ^= ALTERNATE_VIEW;
        else
          g_eeGeneral.view = (g_eeGeneral.view + (4*ALTERNATE_VIEW) + ((event==EVT_KEY_BREAK(KEY_LEFT)) ? -ALTERNATE_VIEW : ALTERNATE_VIEW)) % (4*ALTERNATE_VIEW);
#else
        g_eeGeneral.view ^= ALTERNATE_VIEW;
#endif
        eeDirty(EE_GENERAL);
        AUDIO_KEYPAD_UP();
      }
      break;

#if defined(NAVIGATION_MENUS)
    case EVT_KEY_CONTEXT_MENU:
      killEvents(event);

#if defined(CPUARM)
      if (modelHasNotes()) {
        MENU_ADD_ITEM(STR_VIEW_NOTES);
      }
#endif

#if defined(CPUARM)
      MENU_ADD_ITEM(STR_RESET_SUBMENU);
#else
      MENU_ADD_ITEM(STR_RESET_TIMER1);
      MENU_ADD_ITEM(STR_RESET_TIMER2);
#if defined(FRSKY)
      MENU_ADD_ITEM(STR_RESET_TELEMETRY);
#endif
      MENU_ADD_ITEM(STR_RESET_FLIGHT);
#endif

      MENU_ADD_ITEM(STR_STATISTICS);
#if defined(CPUARM)
      MENU_ADD_ITEM(STR_ABOUT_US);
#endif
      menuHandler = onMainViewMenu;
      break;
#endif

#if MENUS_LOCK != 2 /*no menus*/
    case EVT_KEY_LONG(KEY_MENU):// go to last menu
      pushMenu(lastPopMenu());
      killEvents(event);
      break;

    CASE_EVT_ROTARY_BREAK
    case EVT_KEY_MODEL_MENU:
      pushMenu(menuModelSelect);
      killEvents(event);
      break;

    CASE_EVT_ROTARY_LONG
    case EVT_KEY_GENERAL_MENU:
      pushMenu(menuGeneralSetup);
      killEvents(event);
      break;
#endif

    case EVT_KEY_BREAK(KEY_UP):
    case EVT_KEY_BREAK(KEY_DOWN):
      g_eeGeneral.view = (event == EVT_KEY_BREAK(KEY_UP) ? (view_base == VIEW_COUNT-1 ? 0 : view_base+1) : (view_base == 0 ? VIEW_COUNT-1 : view_base-1));
      eeDirty(EE_GENERAL);
      AUDIO_KEYPAD_UP();
      break;

    case EVT_KEY_STATISTICS:
      chainMenu(menuStatisticsView);
      killEvents(event);
      break;

    case EVT_KEY_TELEMETRY:
#if defined(FRSKY)
      if (!IS_FAI_ENABLED())
        chainMenu(menuTelemetryFrsky);
#elif defined(JETI)
      JETI_EnableRXD(); // enable JETI-Telemetry reception
      chainMenu(menuTelemetryJeti);
#elif defined(ARDUPILOT)
      ARDUPILOT_EnableRXD(); // enable ArduPilot-Telemetry reception
      chainMenu(menuTelemetryArduPilot);
#elif defined(NMEA)
      NMEA_EnableRXD(); // enable NMEA-Telemetry reception
      chainMenu(menuTelemetryNMEA);
#elif defined(MAVLINK)
      chainMenu(menuTelemetryMavlink);
#else
      chainMenu(menuStatisticsDebug);
#endif
      killEvents(event);
      break;

    case EVT_KEY_FIRST(KEY_EXIT):
#if defined(GVARS) && !defined(PCBSTD)
      if (s_gvar_timer > 0) {
        s_gvar_timer = 0;
      }
#endif
      if (view == VIEW_TIMER2) {
        timerReset(1);
      }
      AUDIO_KEYPAD_UP();
      break;

#if !defined(NAVIGATION_MENUS)
    case EVT_KEY_LONG(KEY_EXIT):
      flightReset();
      AUDIO_KEYPAD_UP();
      break;
#endif
  }

  {
    // Flight Mode Name
    uint8_t mode = mixerCurrentFlightMode;
    lcd_putsnAtt(PHASE_X, PHASE_Y, g_model.flightModeData[mode].name, sizeof(g_model.flightModeData[mode].name), ZCHAR|PHASE_FLAGS);

    // Model Name
    putsModelName(MODELNAME_X, MODELNAME_Y, g_model.header.name, g_eeGeneral.currModel, BIGSIZE);

    // Main Voltage (or alarm if any)
    displayVoltageOrAlarm();

    // Timers
    displayTimers();

    // Trims sliders
    displayTrims(mode);
  }

  if (view_base < VIEW_INPUTS) {
    // scroll bar
    lcd_hlineStip(38, 34, 54, DOTTED);
#if defined(PCBSKY9X)
    lcd_hline(38 + (g_eeGeneral.view / ALTERNATE_VIEW) * 13, 34, 13, SOLID);
#else
    lcd_hline((g_eeGeneral.view & ALTERNATE_VIEW) ? 64 : 38, 34, 26, SOLID);
#endif

    for (uint8_t i=0; i<8; i++) {
      uint8_t x0,y0;
#if defined(PCBSKY9X)
      uint8_t chan = 8*(g_eeGeneral.view / ALTERNATE_VIEW) + i;
#else
      uint8_t chan = (g_eeGeneral.view & ALTERNATE_VIEW) ? 8+i : i;
#endif

      int16_t val = channelOutputs[chan];

      switch(view_base)
      {
        case VIEW_OUTPUTS_VALUES:
          x0 = (i%4*9+3)*FW/2;
          y0 = i/4*FH+40;
#if defined(PPM_UNIT_US)
          lcd_outdezAtt(x0+4*FW , y0, PPM_CH_CENTER(chan)+val/2, 0);
#elif defined(PPM_UNIT_PERCENT_PREC1)
          lcd_outdezAtt(x0+4*FW , y0, calcRESXto1000(val), PREC1);
#else
          lcd_outdezAtt(x0+4*FW , y0, calcRESXto1000(val)/10, 0); // G: Don't like the decimal part*
#endif
          break;

        case VIEW_OUTPUTS_BARS:
#define WBAR2 (50/2)
          x0       = i<4 ? LCD_W/4+2 : LCD_W*3/4-2;
          y0       = 38+(i%4)*5;

          uint16_t lim = g_model.extendedLimits ? 640*2 : 512*2;
          int8_t len = (abs(val) * WBAR2 + lim/2) / lim;

          if(len>WBAR2)  len = WBAR2;  // prevent bars from going over the end - comment for debugging
          lcd_hlineStip(x0-WBAR2, y0, WBAR2*2+1, DOTTED);
          lcd_vline(x0,y0-2,5);
          if (val>0)
            x0+=1;
          else
            x0-=len;
          lcd_hline(x0,y0+1,len);
          lcd_hline(x0,y0-1,len);
          break;
      }
    }
  }
  else if (view_base == VIEW_INPUTS) {
    if (view == VIEW_INPUTS) {
      // Sticks + Pots
      doMainScreenGraphics();

      // Switches
      for (uint8_t i=SWSRC_THR; i<=SWSRC_TRN; i++) {
        int8_t sw = (i == SWSRC_TRN ? (switchState(SW_ID0) ? SWSRC_ID0 : (switchState(SW_ID1) ? SWSRC_ID1 : SWSRC_ID2)) : i);
        uint8_t x = 2*FW-2, y = i*FH+1;
        if (i>=SWSRC_AIL) {
          x = 17*FW-1;
          y -= 3*FH;
        }
        putsSwitches(x, y, sw, getSwitch(i) ? INVERS : 0);
      }
    }
    else {
#if defined(PCBMEGA2560) && defined(ROTARY_ENCODERS)
      for (uint8_t i=0; i<NUM_ROTARY_ENCODERS; i++) {
        int16_t val = getRotaryEncoder(i);
        int8_t len = limit((int16_t)0, (int16_t)(((val+1024) * BAR_HEIGHT) / 2048), (int16_t)BAR_HEIGHT);
#if ROTARY_ENCODERS > 2
#define V_BAR_W 5
        V_BAR(LCD_W/2-8+V_BAR_W*i, LCD_H-8, len);
#else
#define V_BAR_W 5
        V_BAR(LCD_W/2-3+V_BAR_W*i, LCD_H-8, len);
#endif
      }
#endif // PCBGRUVIN9X && ROTARY_ENCODERS

      // Logical Switches
#if defined(PCBSKY9X)
      for (uint8_t i=0; i<NUM_LOGICAL_SWITCH; i++) {
        int8_t len = getSwitch(SWSRC_SW1+i) ? BAR_HEIGHT : 1;
        uint8_t x = VSWITCH_X(i);
        lcd_vline(x-1, VSWITCH_Y-len, len);
        lcd_vline(x,   VSWITCH_Y-len, len);
      }
#elif defined(CPUM2560)
      for (uint8_t i=0; i<NUM_LOGICAL_SWITCH; i++)
        putsSwitches(2*FW-3 + (i/3)*(i/3>2 ? 3*FW+2 : (3*FW-1)) + (i/3>2 ? 2*FW : 0), 4*FH+1 + (i%3)*FH, SWSRC_SW1+i, getSwitch(SWSRC_SW1+i) ? INVERS : 0);
#elif !defined(PCBSTD)
      for (uint8_t i=0; i<NUM_LOGICAL_SWITCH; i++)
        putsSwitches(2*FW-2 + (i/3)*(4*FW-1), 4*FH+1 + (i%3)*FH, SWSRC_SW1+i, getSwitch(SWSRC_SW1+i) ? INVERS : 0);
#else
      for (uint8_t i=0; i<NUM_LOGICAL_SWITCH; i++)
        putsSwitches(2*FW-3 + (i/3)*(4*FW), 4*FH+1 + (i%3)*FH, SWSRC_SW1+i, getSwitch(SWSRC_SW1+i) ? INVERS : 0);
#endif
    }
  }
  else { // timer2
#if defined(TRANSLATIONS_CZ)
  #define TMR2_LBL_COL (20-FW/2+1)
#else
  #define TMR2_LBL_COL (20-FW/2+5)
#endif
    putsTimer(33+FW+2+10*FWNUM-4, FH*5, timersStates[1].val, DBLSIZE, DBLSIZE);
    putsTimerMode(timersStates[1].val >= 0 ? TMR2_LBL_COL : TMR2_LBL_COL-7, FH*6, g_model.timers[1].mode);
    // lcd_outdezNAtt(33+11*FW, FH*6, s_timerVal_10ms[1], LEADING0, 2); // 1/100s
  }

  // And ! in case of unexpected shutdown
  if (unexpectedShutdown) {
    lcd_putcAtt(REBOOT_X, 0*FH, '!', INVERS);
  }

#if defined(GVARS) && !defined(PCBSTD)
  if (s_gvar_timer > 0) {
    s_gvar_timer--;
    s_warning = STR_GLOBAL_VAR;
    displayBox();
    lcd_putsnAtt(16, 5*FH, g_model.gvars[s_gvar_last].name, LEN_GVAR_NAME, ZCHAR);
    lcd_putsAtt(16+7*FW, 5*FH, PSTR("[\010]"), BOLD);
    lcd_outdezAtt(16+7*FW+4*FW+FW/2, 5*FH, GVAR_VALUE(s_gvar_last, getGVarFlightPhase(mixerCurrentFlightMode, s_gvar_last)), BOLD);
    s_warning = NULL;
  }
#endif

#if defined(DSM2)
  if (moduleFlag[0] == MODULE_BIND) {
    // Issue 98
    lcd_putsAtt(15*FW, 0, PSTR("BIND"), 0);
  }
#endif
}
Ejemplo n.º 25
0
TEST(getSwitch, nullSW)
{
  MODEL_RESET();
  EXPECT_EQ(getSwitch(0), true);
}
Ejemplo n.º 26
0
void applyExpos(int16_t *anas, uint8_t mode APPLY_EXPOS_EXTRA_PARAMS)
{
#if defined(PCBTARANIS)
#if defined(HELI)
  int16_t heliAnasCopy[4];
  memcpy(heliAnasCopy, heliAnas, sizeof(heliAnasCopy));
#endif
#else
  int16_t anas2[NUM_INPUTS]; // values before expo, to ensure same expo base when multiple expo lines are used
  memcpy(anas2, anas, sizeof(anas2));
#endif

  int8_t cur_chn = -1;

  for (uint8_t i=0; i<MAX_EXPOS; i++) {
#if defined(BOLD_FONT)
    if (mode==e_perout_mode_normal) swOn[i].activeExpo = false;
#endif
    ExpoData * ed = expoAddress(i);
    if (!EXPO_VALID(ed)) break; // end of list
    if (ed->chn == cur_chn)
      continue;
    if (ed->flightModes & (1<<mixerCurrentFlightMode))
      continue;
    if (getSwitch(ed->swtch)) {
#if defined(PCBTARANIS)
      int v;
      if (ed->srcRaw == ovwrIdx)
        v = ovwrValue;
#if defined(HELI)
      else if (ed->srcRaw == MIXSRC_Ele)
        v = heliAnasCopy[ELE_STICK];
      else if (ed->srcRaw == MIXSRC_Ail)
        v = heliAnasCopy[AIL_STICK];
#endif
      else {
        v = getValue(ed->srcRaw);
        if (ed->srcRaw >= MIXSRC_FIRST_TELEM && ed->scale > 0) {
          v = (v * 1024) / convertTelemValue(ed->srcRaw-MIXSRC_FIRST_TELEM+1, ed->scale);
        }
        v = limit(-1024, v, 1024);
      }
#else
      int16_t v = anas2[ed->chn];
#endif
      if (EXPO_MODE_ENABLE(ed, v)) {
#if defined(BOLD_FONT)
        if (mode==e_perout_mode_normal) swOn[i].activeExpo = true;
#endif
        cur_chn = ed->chn;

        //========== CURVE=================
#if defined(PCBTARANIS)
        if (ed->curve.value) {
          v = applyCurve(v, ed->curve);
        }
#else
        int8_t curveParam = ed->curveParam;
        if (curveParam) {
          if (ed->curveMode == MODE_CURVE)
            v = applyCurve(v, curveParam);
          else
            v = expo(v, GET_GVAR(curveParam, -100, 100, mixerCurrentFlightMode));
        }
#endif

        //========== WEIGHT ===============
        int16_t weight = GET_GVAR(ed->weight, MIN_EXPO_WEIGHT, 100, mixerCurrentFlightMode);
        weight = calc100to256(weight);
        v = ((int32_t)v * weight) >> 8;

#if defined(PCBTARANIS)
        //========== OFFSET ===============
        int16_t offset = GET_GVAR(ed->offset, -100, 100, mixerCurrentFlightMode);
        if (offset) v += calc100toRESX(offset);

        //========== TRIMS ================
        if (ed->carryTrim < TRIM_ON)
          virtualInputsTrims[cur_chn] = -ed->carryTrim - 1;
        else if (ed->carryTrim == TRIM_ON && ed->srcRaw >= MIXSRC_Rud && ed->srcRaw <= MIXSRC_Ail)
          virtualInputsTrims[cur_chn] = ed->srcRaw - MIXSRC_Rud;
        else
          virtualInputsTrims[cur_chn] = -1;

#if defined(HELI)
        if (ed->srcRaw == MIXSRC_Ele) {
          heliAnas[ELE_STICK] = v;
          heliTrims[ELE_STICK] = virtualInputsTrims[cur_chn];
        }
        else if (ed->srcRaw == MIXSRC_Ail) {
          heliAnas[AIL_STICK] = v;
          heliTrims[AIL_STICK] = virtualInputsTrims[cur_chn];
        }
#endif
#endif

        anas[cur_chn] = v;
      }
    }
  }
Ejemplo n.º 27
0
// QT3 DBus message handler:
bool LapsusDaemon::handleMethodCall(const QDBusMessage& message)
{
	if (message.interface() != LAPSUS_INTERFACE) return false;

	if (message.type() != QDBusMessage::MethodCallMessage) return false;

	if (message.member() == "listFeatures"
		|| message.member() == "listSwitches"
		|| message.member() == "listDisplayTypes"
		|| message.member() == "getMaxBacklight"
		|| message.member() == "getBacklight")
	{
		if (message.count() != 0)
		{
			return returnDBusError("org.freedesktop.DBus.Error"
				".InvalidSignature", "Expected no arguments",
				message);
		}

		QDBusMessage reply = QDBusMessage::methodReply(message);

		if (message.member() == "listFeatures")
		{
			reply << QDBusData::fromList(listFeatures());
		}
		else if (message.member() == "listSwitches")
		{
			reply << QDBusData::fromList(listSwitches());
		}
		else if (message.member() == "listDisplayTypes")
		{
			reply << QDBusData::fromList(listDisplayTypes());
		}
		else if (message.member() == "getMaxBacklight")
		{
			reply << QDBusData::fromUInt32(getMaxBacklight());
		}
		else if (message.member() == "getBacklight")
		{
			reply << QDBusData::fromUInt32(getBacklight());
		}
		else
		{
			// Should not happen...
			// TODO - some kind of error? to syslog? using dbus?
			reply << QDBusData::fromUInt32(0);
		}

		myConnection->send(reply);

		return true;
	}
	else if (message.member() == "getSwitch"
		|| message.member() == "getDisplay")
	{
		if (message.count() != 1 || message[0].type() != QDBusData::String)
		{
			return returnDBusError("org.freedesktop.DBus.Error"
				".InvalidSignature",
				"Expected one string argument",
				message);
		}

		QDBusMessage reply = QDBusMessage::methodReply(message);

		if (message.member() == "getSwitch")
		{
			reply << QDBusData::fromBool(
					getSwitch(message[0].toString()));
		}
		else if (message.member() == "getDisplay")
		{
			reply << QDBusData::fromBool(
					getDisplay(message[0].toString()));
		}
		else
		{
			// Should not happen...
			// TODO - some kind of error? to syslog? using dbus?
			reply << QDBusData::fromBool(false);
		}

		myConnection->send(reply);

		return true;
	}
	else if (message.member() == "setSwitch"
		|| message.member() == "setDisplay")
	{
		if (message.count() != 2
			|| message[0].type() != QDBusData::String
			|| message[1].type() != QDBusData::Bool)
		{
			return returnDBusError("org.freedesktop.DBus.Error"
				".InvalidSignature",
				"Expected two arguments: string and bool",
				message);
		}

		QDBusMessage reply = QDBusMessage::methodReply(message);

		if (message.member() == "setSwitch")
		{
			reply << QDBusData::fromBool(
					setSwitch(message[0].toString(),
						message[1].toBool()));
		}
		else if (message.member() == "setDisplay")
		{
			reply << QDBusData::fromBool(
					setDisplay(message[0].toString(),
						message[1].toBool()));
		}
		else
		{
			// Should not happen...
			// TODO - some kind of error? to syslog? using dbus?
			reply << QDBusData::fromBool(false);
		}

		myConnection->send(reply);

		return true;
	}
	else if (message.member() == "setBacklight")
	{
		if (message.count() != 1
			|| message[0].type() != QDBusData::UInt32)
		{
			return returnDBusError("org.freedesktop.DBus.Error"
				".InvalidSignature",
				"Expected one uint32 argument",
				message);
		}

		QDBusMessage reply = QDBusMessage::methodReply(message);

		if (message.member() == "setBacklight")
		{
			reply << QDBusData::fromBool(
					setBacklight(message[0].toUInt32()));
		}
		else
		{
			// Should not happen...
			// TODO - some kind of error? to syslog? using dbus?
			reply << QDBusData::fromBool(false);
		}

		myConnection->send(reply);

		return true;
	}

	// TODO - cpufreq

	return false;
}
Ejemplo n.º 28
0
Archivo: tcfs.cpp Proyecto: djibb/indi
bool TCFS::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
{
//LOGF_DEBUG("%s %s",__FUNCTION__, me);
    if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
    {
        char response[TCFS_MAX_CMD] = { 0 };

        if (!strcmp(FocusPowerSP.name, name))
        {
            IUUpdateSwitch(&FocusPowerSP, states, names, n);
            bool sleep = false;

            ISwitch *sp = IUFindOnSwitch(&FocusPowerSP);

            // Sleep
            if (!strcmp(sp->name, "FOCUS_SLEEP"))
            {
                dispatch_command(FSLEEP);
                sleep = true;
            }
            // Wake Up
            else
                dispatch_command(FWAKUP);

            if (read_tcfs(response) == false)
            {
                IUResetSwitch(&FocusPowerSP);
                FocusPowerSP.s = IPS_ALERT;
                IDSetSwitch(&FocusPowerSP, "Error reading TCF-S reply.");
                return true;
            }

            if (sleep)
            {
                if (isSimulation())
                    strncpy(response, "ZZZ", TCFS_MAX_CMD);

                if (strcmp(response, "ZZZ") == 0)
                {
                    FocusPowerSP.s = IPS_OK;
                    IDSetSwitch(&FocusPowerSP, "Focuser is set into sleep mode.");
                    FocusAbsPosNP.s = IPS_IDLE;
                    IDSetNumber(&FocusAbsPosNP, nullptr);
//                    if (FocusTemperatureNP)
                    {
                        FocusTemperatureNP.s = IPS_IDLE;
                        IDSetNumber(&FocusTemperatureNP, nullptr);
                    }

                    return true;
                }
                else
                {
                    FocusPowerSP.s = IPS_ALERT;
                    IDSetSwitch(&FocusPowerSP, "Focuser sleep mode operation failed. Response: %s.", response);
                    return true;
                }
            }
            else
            {
                if (isSimulation())
                    strncpy(response, "WAKE", TCFS_MAX_CMD);

                if (strcmp(response, "WAKE") == 0)
                {
                    FocusPowerSP.s = IPS_OK;
                    IDSetSwitch(&FocusPowerSP, "Focuser is awake.");
                    FocusAbsPosNP.s = IPS_OK;
                    IDSetNumber(&FocusAbsPosNP, nullptr);
//                    if (FocusTemperatureNP)
                    {
                        FocusTemperatureNP.s = IPS_OK;
                        IDSetNumber(&FocusTemperatureNP, nullptr);
                    }

                    return true;
                }
                else
                {
                    FocusPowerSP.s = IPS_ALERT;
                    IDSetSwitch(&FocusPowerSP, "Focuser wake up operation failed. Response: %s", response);
                    return true;
                }
            }
        }

        // Do not process any command if focuser is asleep
        if (isConnected() && FocusPowerSP.sp[0].s == ISS_ON)
        {
            ISwitchVectorProperty *svp = getSwitch(name);
            if (svp)
            {
                svp->s = IPS_IDLE;
                LOG_WARN("Focuser is still in sleep mode. Wake up in order to issue commands.");
                IDSetSwitch(svp, nullptr);
            }
            return true;
        }

        if (!strcmp(FocusModeSP.name, name))
        {
            IUUpdateSwitch(&FocusModeSP, states, names, n);
            FocusModeSP.s = IPS_OK;

            ISwitch *sp = IUFindOnSwitch(&FocusModeSP);

            if (!strcmp(sp->name, "Manual"))
            {
                if (!isSimulation() && !SetManualMode())
                {
                    IUResetSwitch(&FocusModeSP);
                    FocusModeSP.s = IPS_ALERT;
                    IDSetSwitch(&FocusModeSP, "Error switching to manual mode. No reply from TCF-S. Try again.");
                    return true;
                }
            }
            else if (!strcmp(sp->name, "Auto A"))
            {
                dispatch_command(FAMODE);
                read_tcfs(response);
                if (!isSimulation() && strcmp(response, "A") != 0)
                {
                    IUResetSwitch(&FocusModeSP);
                    FocusModeSP.s = IPS_ALERT;
                    IDSetSwitch(&FocusModeSP, "Error switching to Auto Mode A. No reply from TCF-S. Try again.");
                    return true;
                }
                LOG_INFO("Entered Auto Mode A");
                currentMode = MODE_A;
            }
            else
            {
                dispatch_command(FBMODE);
                read_tcfs(response);
                if (!isSimulation() && strcmp(response, "B") != 0)
                {
                    IUResetSwitch(&FocusModeSP);
                    FocusModeSP.s = IPS_ALERT;
                    IDSetSwitch(&FocusModeSP, "Error switching to Auto Mode B. No reply from TCF-S. Try again.");
                    return true;
                }
                LOG_INFO("Entered Auto Mode B");
                currentMode = MODE_B;
            }

            IDSetSwitch(&FocusModeSP, nullptr);
            return true;
        }

        if (!strcmp(FocusGotoSP.name, name))
        {
            if (FocusModeSP.sp[0].s != ISS_ON)
            {
                FocusGotoSP.s = IPS_IDLE;
                IDSetSwitch(&FocusGotoSP, nullptr);
                LOG_WARN("The focuser can only be moved in Manual mode.");
                return false;
            }

            IUUpdateSwitch(&FocusGotoSP, states, names, n);
            FocusGotoSP.s = IPS_BUSY;

            ISwitch *sp = IUFindOnSwitch(&FocusGotoSP);

            // Min
            if (!strcmp(sp->name, "FOCUS_MIN"))
            {
                targetTicks = currentPosition;
                MoveRelFocuser(FOCUS_INWARD, currentPosition);
                IDSetSwitch(&FocusGotoSP, "Moving focuser to minimum position...");
            }
            // Center
            else if (!strcmp(sp->name, "FOCUS_CENTER"))
            {
                dispatch_command(FCENTR);
                FocusAbsPosNP.s = FocusRelPosNP.s = IPS_BUSY;
                IDSetNumber(&FocusAbsPosNP, nullptr);
                IDSetNumber(&FocusRelPosNP, nullptr);
                IDSetSwitch(&FocusGotoSP, "Moving focuser to center position %d...", isTCFS3 ? 5000 : 3500);
                return true;
            }
            // Max
            else if (!strcmp(sp->name, "FOCUS_MAX"))
            {
                unsigned int delta = 0;
                delta              = FocusAbsPosN[0].max - currentPosition;
                MoveRelFocuser(FOCUS_OUTWARD, delta);
                IDSetSwitch(&FocusGotoSP, "Moving focuser to maximum position %g...", FocusAbsPosN[0].max);
            }
            // Home
            else if (!strcmp(sp->name, "FOCUS_HOME"))
            {
                dispatch_command(FHOME);
                read_tcfs(response);

                if (isSimulation())
                    strncpy(response, "DONE", TCFS_MAX_CMD);

                if (strcmp(response, "DONE") == 0)
                {
                    IUResetSwitch(&FocusGotoSP);
                    FocusGotoSP.s = IPS_OK;
                    IDSetSwitch(&FocusGotoSP, "Moving focuser to new calculated position based on temperature...");
                    return true;
                }
                else
                {
                    IUResetSwitch(&FocusGotoSP);
                    FocusGotoSP.s = IPS_ALERT;
                    IDSetSwitch(&FocusGotoSP, "Failed to move focuser to home position!");
                    return true;
                }
            }

            IDSetSwitch(&FocusGotoSP, nullptr);
            return true;
        }
        // handle quiet mode on/off
        if (!strcmp(FocusTelemetrySP.name, name))
        {
            IUUpdateSwitch(&FocusTelemetrySP, states, names, n);


            bool quiet = false;

            ISwitch *sp = IUFindOnSwitch(&FocusTelemetrySP);

            // Telemetry off
            if (!strcmp(sp->name, "FOCUS_TELEMETRY_OFF"))
            {
                dispatch_command(FQUIET, 1);
                quiet = true;
            }
            // Telemetry On
            else
                dispatch_command(FQUIET, 0);

            if (read_tcfs(response) == false)
            {
                IUResetSwitch(&FocusTelemetrySP);
                FocusTelemetrySP.s = IPS_ALERT;
                IDSetSwitch(&FocusTelemetrySP, "Error reading TCF-S reply.");
                return true;
            }

            if (isSimulation())
                strncpy(response, "DONE", TCFS_MAX_CMD);

            if (strcmp(response, "DONE") == 0)
            {
                FocusTelemetrySP.s = IPS_OK;
                IDSetSwitch(&FocusTelemetrySP, 
                        quiet ? "Focuser Telemetry is off." : "Focuser Telemetry is on.");
//                if (FocusTemperatureNP)
                {
                    FocusTemperatureNP.s = quiet?IPS_IDLE:IPS_OK;
                    IDSetNumber(&FocusTemperatureNP, nullptr);
                }
                return true;
            }
            else
            {
                FocusTelemetrySP.s = IPS_ALERT;
                IDSetSwitch(&FocusTelemetrySP, "Focuser telemetry mode failed. Response: %s.", response);
                return true;
            }
        }
    }
    return INDI::Focuser::ISNewSwitch(dev, name, states, names, n);
}
Ejemplo n.º 29
0
int main(void) {
	LPC_GPIO2->DIR |= (1<<10);
	/* PLL is already setup */
	SystemCoreClockUpdate();
	/* Blue LED Set as output */
	/* Relay EN Set as output */
	LPC_GPIO1->DIR |= (1<<5);
	uartInit(115200);
	puts("Sys Initted\n");
	puts("uart Initted\n");
	initSwitch();
	puts("Switches Initted\n");
	SysTick_Config(SystemCoreClock/1000);
	puts("SysTick Initted\n");
	setup_pwm(1000,4092);
	puts("PWM Initted\n");
	setup_GPIO_INT();
	puts("GPIO INT Initted\n");
	filt_adc_init(450);
	delay_ms(500);
	puts("Filt ADC Initted\n");


	while(1)
	{
		while(next_run > msTicks)
			__WFI();
		next_run= msTicks + 10;
		if ((msTicks - last_motion ) > 
			(MAX(W_POWER_OFF_TIME_MS + RAMP_DOWN_TIME_MS,
				RGB_POWER_OFF_TIME_MS + RAMP_DOWN_TIME_MS ) + 2000))
		{
			shut_off_supply();
			transfer_to_sleep();
			turn_on_supply();
			/* Wait for the power to actually come on before starting the ramp up */
		}

		// WW_SWITCH_HANDLER
		// debounce for 20ms, since we check for the absolute val if the user
		// holds the switch forever it will only trigger the service once
		if(getSwitch(WW_SWITCH) == 0)
		{
			if(ww_sw_asserted == 5)
			{
				puts("WW SWITCH PRESSED\n");
				white_on = !white_on;
				white_scale = 0;
			}
			ww_sw_asserted += 1;
		}
		else
			ww_sw_asserted = 0;

		// OFF_SWITCH_HANDLER
		// debounce for 20ms, since we check for the absolute val if the user
		// holds the switch forever it will only trigger the service once
		if(getSwitch(OFF_SWITCH) == 0)
		{
			if(off_sw_asserted == 5)
			{
				puts("OFF SWITCH PRESSED\n");
				white_on = 0;
				white_scale = 0;
				rgb_on = 0;
				rgb_scale = 0;
			}
			off_sw_asserted += 1;
		}
		else
			off_sw_asserted = 0;
		
		// RGB_SWITCH_HANDLER
		// debounce for 20ms, since we check for the absolute val if the user
		// holds the switch forever it will only trigger the service once
		if(getSwitch(RGB_SWITCH) == 0)
		{
			if(rgb_sw_asserted == 5)
			{
				puts("RGB SWITCH PRESSED\n");
				rgb_on = !rgb_on;
				rgb_scale = 0;
			}
			if(rgb_sw_asserted == 100)
			{
				puts("RGB SWITCH HELD\n");
				rgb_on = 2;
			}
			if(rgb_sw_asserted == 500)
			{
				puts("RGB SWITCH LONG HELD\n");
				rgb_on = 3;
			}
			rgb_sw_asserted += 1;
		}
		else
			rgb_sw_asserted = 0;

/* This handles the WW LEDs */
		if (((msTicks - last_motion ) > W_POWER_OFF_TIME_MS) && white_on)
		{
			white_scale = RAMP_DOWN_TIME_MS - ((msTicks - last_motion) - W_POWER_OFF_TIME_MS);
			if ((msTicks - last_motion) > (W_POWER_OFF_TIME_MS + RAMP_DOWN_TIME_MS))
				white_scale = 0;
		}
		if ( white_scale < RAMP_DOWN_TIME_MS && white_on && ((msTicks - last_motion ) < W_POWER_OFF_TIME_MS))
		{
			white_scale = msTicks - last_motion;
			/* Check just in case we get held up and skip the 1000th ms after motion */
			if ( white_scale > RAMP_DOWN_TIME_MS)
				white_scale = RAMP_DOWN_TIME_MS;
		}
		if (white_scale != RAMP_DOWN_TIME_MS)
		{
			setWW( (white_scale * getADCVal(WW_POT)) / RAMP_DOWN_TIME_MS );
			setWW2( (white_scale * getADCVal(WW_POT)) / RAMP_DOWN_TIME_MS );
		}
		else
		{
			setWW(getADCVal(WW_POT));
			setWW2(getADCVal(WW_POT));
		}
		
			

		/* This handles the RGB LEDs */
		if (((msTicks - last_motion ) > RGB_POWER_OFF_TIME_MS) && rgb_on)
		{
			rgb_scale = RAMP_DOWN_TIME_MS - ((msTicks - last_motion) - RGB_POWER_OFF_TIME_MS);
			if ((msTicks - last_motion) > (RGB_POWER_OFF_TIME_MS + RAMP_DOWN_TIME_MS))
				rgb_scale = 0;
		}
		if ( rgb_scale < RAMP_DOWN_TIME_MS && rgb_on && ((msTicks - last_motion ) < RGB_POWER_OFF_TIME_MS))
		{
			rgb_scale = msTicks - last_motion;
			/* Check just in case we get held up and skip the 1000th ms after motion */
			if ( rgb_scale > RAMP_DOWN_TIME_MS)
				rgb_scale = RAMP_DOWN_TIME_MS;
		}

		if (rgb_on == 1 || rgb_on == 0)
		{
			if (rgb_scale != RAMP_DOWN_TIME_MS)
				setRGB((rgb_scale * getADCVal(RED_POT)) / RAMP_DOWN_TIME_MS,
						(rgb_scale * getADCVal(GREEN_POT)) / RAMP_DOWN_TIME_MS,
						(rgb_scale * getADCVal(BLUE_POT)) / RAMP_DOWN_TIME_MS );
			else
				setRGB(getADCVal(RED_POT), getADCVal(GREEN_POT), getADCVal(BLUE_POT));
		}
		else if (rgb_on == 2)
		{
			uint32_t R,G,B;
			h2rgb((msTicks)%(H2RGB_OUT_RANGE*6), &R, &G, &B);
			if (rgb_scale != RAMP_DOWN_TIME_MS)
				setRGB((rgb_scale * R) / RAMP_DOWN_TIME_MS,
						(rgb_scale * G) / RAMP_DOWN_TIME_MS,
						(rgb_scale * B) / RAMP_DOWN_TIME_MS );
			else
				setRGB(R, G, B);
		}
		else if (rgb_on == 3)
		{
			uint32_t R,G,B;
			if (rgb_mode_3_next_change < msTicks)
			{
				rgb_mode_3_next_change = msTicks + (getADCVal(RED_POT)/4);
				rgb_mode_3_color += 2;
				if(rgb_mode_3_color >=6)
					rgb_mode_3_color = 0;

			}
		
			h2rgb((H2RGB_OUT_RANGE * rgb_mode_3_color), &R, &G, &B);
			if (rgb_scale != RAMP_DOWN_TIME_MS)
				setRGB((rgb_scale * R) / RAMP_DOWN_TIME_MS,
						(rgb_scale * G) / RAMP_DOWN_TIME_MS,
						(rgb_scale * B) / RAMP_DOWN_TIME_MS );
			else
				setRGB(R, G, B);
		}




	}
}
Ejemplo n.º 30
0
bool AAGCloudWatcher::resetData() {
  CloudWatcherData data;

  int r = cwc->getAllData(&data);

  if (!r) {
    return false;
  }

  int N_DATA = 11;
  double values[N_DATA];
  char *names[N_DATA];

  names[0] = const_cast<char *>("supply");
  values[0] = 0;

  names[1] = const_cast<char *>("sky");
  values[1] = 0;

  names[2] = const_cast<char *>("sensor");
  values[2] = 0;

  names[3] = const_cast<char *>("ambient");
  values[3] = 0;

  names[4] = const_cast<char *>("rain");
  values[4] = 0;

  names[5] = const_cast<char *>("rainHeater");
  values[5] = 0;

  names[6] = const_cast<char *>("rainTemp");
  values[6] = 0;

  names[7] = const_cast<char *>("LDR");
  values[7] = 0;

  names[8] = const_cast<char *>("readCycle");
  values[8] = 0;
  
  names[9] = const_cast<char *>("windSpeed");
  values[9] = 0;

  names[10] = const_cast<char *>("totalReadings");
  values[10] = 0;
  
  INumberVectorProperty *nvp = getNumber("readings");
  IUUpdateNumber(nvp, values, names, N_DATA);
  nvp->s = IPS_IDLE;
  IDSetNumber(nvp, NULL);

  int N_ERRORS = 5;
  double valuesE[N_ERRORS];
  char *namesE[N_ERRORS];

  namesE[0] = const_cast<char *>("internalErrors");
  valuesE[0] = 0;

  namesE[1] = const_cast<char *>("firstAddressByteErrors");
  valuesE[1] = 0;

  namesE[2] = const_cast<char *>("commandByteErrors");
  valuesE[2] = 0;

  namesE[3] = const_cast<char *>("secondAddressByteErrors");
  valuesE[3] = 0;

  namesE[4] = const_cast<char *>("pecByteErrors");
  valuesE[4] = 0;

  INumberVectorProperty *nvpE = getNumber("unitErrors");
  IUUpdateNumber(nvpE, valuesE, namesE, N_ERRORS);
  nvpE->s = IPS_IDLE;
  IDSetNumber(nvpE, NULL);


  int N_SENS = 8;
  double valuesS[N_SENS];
  char *namesS[N_SENS];

  namesS[0] = const_cast<char *>("infraredSky");
  valuesS[0] = 0.0;

  namesS[1] = const_cast<char *>("infraredSensor");
  valuesS[1] = 0.0;

  namesS[2] = const_cast<char *>("rainSensor");
  valuesS[2] = 0.0;

  namesS[3] = const_cast<char *>("rainSensorTemperature");
  valuesS[3] = 0.0;

  namesS[4] = const_cast<char *>("rainSensorHeater");
  valuesS[4] = 0.0;

  namesS[5] = const_cast<char *>("brightnessSensor");
  valuesS[5] = 0.0;

  namesS[6] = const_cast<char *>("ambientTemperatureSensor");
  valuesS[6] = 0.0;

  namesS[7] = const_cast<char *>("correctedInfraredSky");
  valuesS[7] = 0.0;

  INumberVectorProperty *nvpS = getNumber("sensors");
  IUUpdateNumber(nvpS, valuesS, namesS, N_SENS);
  nvpS->s = IPS_IDLE;
  IDSetNumber(nvpS, NULL);

  ISwitchVectorProperty *svpSw = getSwitch("deviceSwitch");
  svpSw->s = IPS_IDLE;
  IDSetSwitch(svpSw, NULL);



  ISwitchVectorProperty *svpCC = getSwitch("cloudConditions");
  svpCC->s = IPS_IDLE;
  IDSetSwitch(svpCC, NULL);

  ISwitchVectorProperty *svpRC = getSwitch("rainConditions");
  svpRC->s = IPS_IDLE;
  IDSetSwitch(svpRC, NULL);

  ISwitchVectorProperty *svpBC = getSwitch("brightnessConditions");
  svpBC->s = IPS_IDLE;
  IDSetSwitch(svpBC, NULL);

  ISwitchVectorProperty *svp = getSwitch("heaterStatus");
  svp->s = IPS_IDLE;
  IDSetSwitch(svp, NULL);
}