Esempio n. 1
0
void Move::changeMoveState(MoveState newState) {
  if (newState != state) {
#ifdef MOVE_DEBUG
    Serial.print(P("Changing move state from ")); Serial.print(STATE_NAME(state));
    Serial.print(P(" to ")); Serial.println(STATE_NAME(newState));
#endif
    state = newState;
  } 
}
Esempio n. 2
0
void Remote::changeCmdState(int newState) {
  if(newState != commandState) {
#ifdef REMOTE_DEBUG
    Serial.print(P("Changing Cmd state from ")); Serial.print(STATE_NAME(commandState));
    Serial.print(P(" to ")); Serial.println(STATE_NAME(newState));
#endif
    commandState = newState;
  } 
}
Esempio n. 3
0
File: dialer.c Progetto: sashakh/ma
static int dialer_process(struct modem *m, int16_t * in, int16_t * out,
			  unsigned int count)
{
	struct dialer_struct *s = (struct dialer_struct *)m->datapump.dp;
	enum dialer_states new_state;
	const char *p;
	int ret = 0;

	switch (s->state) {
	case STATE_WAIT:
		ret = detector_process(&s->detector, in, count);
		memset(out, 0, ret * sizeof(int16_t));
		break;
	case STATE_DIAL:
		ret = dtmfgen_process(&s->dtmfgen, out, count);
		break;
	default:
		return -1;
	}
	if (ret == count)
		return count;
	if (ret < 0)
		return ret;

	memset(out + ret, 0, (count - ret) * sizeof(int16_t));
	if (s->state == STATE_DIAL)
		p = s->d_ptr = s->dtmfgen.p;
	else
		p = s->d_ptr++;
	if (*p == '\0') {
		dbg("dialer finished\n");
		m->next_dp_id = DP_DETECTOR;
		new_state = STATE_FINISHED;
	} else if (tolower(*p) == 'w' || *p == ',') {
		unsigned int pause_time = m->sregs[8] > 0 ? m->sregs[8] : 2;
		new_state = STATE_WAIT;
		detector_init(&s->detector, samples_in_sec(pause_time));
	} else {
		new_state = STATE_DIAL;
		dtmfgen_init(&s->dtmfgen, p);
	}
	dbg("dialer state: %s -> %s\n",
	    STATE_NAME(s->state), STATE_NAME(new_state));
	s->state = new_state;
	return count;
}
Esempio n. 4
0
void test1() {
    std::cout << "FrontPanelTest test 1" << std::endl;
       
    int frontPanelI2Cport = (SETTINGS.GetInt(HARDWARE_REV) == 0) ? 
                                                         I2C2_PORT : I2C1_PORT;
        
    FrontPanel fp(FP_SLAVE_ADDRESS, frontPanelI2Cport);
    
    PrinterStatus ps;
    ps._numLayers = 100;
    ps._currentLayer  = 30;;
    ps._estimatedSecondsRemaining = 4380;
    ps._errorCode = NoImageForLayer;
    ps._change = NoChange;
    ps._UISubState = NoUISubState;
    
    PrintEngineState pes =  PrinterOnState;  
    int iter = 1;
    
    srand (time(NULL)); // seed the random number generator

    // do forever
    for(;;)
    {
        ps._state = pes;  
        ps._errno = iter;
        
        ((ICallback*)&fp)->Callback(PrinterStatusUpdate, EventData(ps));
        
        // read the front panel buttons while screen is being drawn
        // wait 10 to 500 ms first
        int delayMs = rand() % 490 + 10;
        usleep(delayMs * 1000);
   
        unsigned char btns = fp.Read(BTN_STATUS);
        if (btns == 0xFF)
        {
            std::cout << "Error reading buttons when state =  " <<
                      STATE_NAME(pes) << " delay = " << delayMs << std::endl;
        }
        else
        {
            btns &= 0xF;
            if (btns != 0)
                std::cout << "Buttons pressed: " << (int)btns << std::endl;
        }
        
        
        pes = (PrintEngineState)(1 + (int) pes);
        if (pes >= MaxPrintEngineState)
        {
            pes = PrinterOnState;
            ++iter;
        }
    }
}
Esempio n. 5
0
// Handle the events we wish to log
// Increases priority of messages, if this is a debug build.
// Note: in /etc/rsyslog.conf, if this default line:
//     *.*;auth,authpriv.none               -/var/log/syslog
// is changed to 
//     *.info;auth,authpriv.none            -/var/log/syslog
// then messages with priority of LOG_DEBUG will not be stored
// that line would need to be restored to its default
// in order to see items logged by this method in a release build
void Logger::Callback(EventType eventType, const EventData& data)
{
    int priority = LOG_DEBUG; 
#ifdef DEBUG
    priority = LOG_INFO;
#endif    
    
    PrinterStatus ps;

    switch(eventType)
    {
        case PrinterStatusUpdate:
            ps = data.Get<PrinterStatus>();
            // only log state entering and leaving
            if (ps._change == Entering ||
               ps._change == Leaving)
            {
                const char* substate = ps._UISubState == NoUISubState ?
                                       "" : SUBSTATE_NAME(ps._UISubState);
                syslog(priority, LOG_STATUS_FORMAT, 
                                 ps._change == Entering ? ENTERING : LEAVING,
                                 STATE_NAME(ps._state), substate);
            }
            break;
            
        case MotorInterrupt:
            syslog(priority, LOG_MOTOR_EVENT, data.Get<unsigned char>());
            break;
            
        case ButtonInterrupt:
            syslog(priority, LOG_BUTTON_EVENT, data.Get<unsigned char>());           
            break;

        case DoorInterrupt:
            syslog(priority, LOG_DOOR_EVENT, data.Get<char>());            
            break;

        case Keyboard:
            syslog(priority, LOG_KEYBOARD_INPUT, 
                                            data.Get<std::string>().c_str());
            break;
            
        case UICommand:
            syslog(priority, LOG_UI_COMMAND, data.Get<std::string>().c_str());
            break;            

        default:
            LOGGER.LogError(LOG_WARNING, errno, ERR_MSG(UnexpectedEvent), 
                                                                    eventType);
            break;
    }
}
Esempio n. 6
0
File: cli.c Progetto: modul/iris
static void do_info()
{
	char c;
	int i, tmp;
	struct chan *channel;

	input_stop();
	if ((c = getchar()) == 'V') {
		tmp = AD7793_voltmon();
		printf("%u.%uV\n", tmp/1000000, tmp%1000000);
	}
	else if (c == 'T') {
		tmp = AD7793_temperature();
		printf("%u.%uC\n", tmp/10000, tmp%10000);
	}
	else {
		if ((i = CHANNEL_ID(c)) < CHANNELS) // print only one channel
			tmp = i+1;
		else { // print all channels and state information
			i = 0;
			tmp = CHANNELS;
			printf("%s\n", STATE_NAME(state_getState()));
		}
		
		while (i < tmp) {
			channel = conf_get(i);
			printf("%c %s ch%u %ux %i ... %i %iuV\n", 
				CHANNEL_NAME(i), ERROR_NAME(state_getError(i)), 
				channel->num, 1<<channel->gain,
				channel->min, channel->max,
				input_latest(i));
			i++;
		}
	}
	input_start();
}
Esempio n. 7
0
// Updates the front panel displays, based on printer status
void FrontPanel::ShowStatus(const PrinterStatus& ps)
{
    if (ps._change != Leaving)
    {
        // display the screen for this state and sub-state
        PrinterStatusKey key = PS_KEY(ps._state, ps._UISubState);

        if (ps._state == PrintingLayerState)
        {
            // force the display of the remaining print time 
            // whenever we enter or re-enter the PrintingLayer state
            // e.g. after door closed or resuming from pause
            _forceDisplay = true;   
        }
        
        if (_screens.count(key) < 1)
        {            
            std::cout << "Unknown screen for state: " << STATE_NAME(ps._state) 
                      << ", substate: " << SUBSTATE_NAME(ps._UISubState) 
                      << std::endl;
            
            key = UNKNOWN_SCREEN_KEY;
        }
        Screen* pScreen = _screens[key];
        if (pScreen != NULL)
        {
            // make sure a display thread isn't already running
            AwaitThreadComplete();
            
            // display the selected screen in a separate thread, to
            // avoid blocking here
            FrontPanelScreen* pFPS = new FrontPanelScreen(this, ps, pScreen);
            pthread_create(&_showScreenThread, NULL, &ThreadHelper, pFPS);  
        }
    }
}
Esempio n. 8
0
void test1() {
    std::cout << "NetworkIFUT test 1" << std::endl;
    
    // delete the named pipe used for Web status, if it exists
    if (access(STATUS_TO_WEB_PIPE, F_OK) != -1)
        remove(STATUS_TO_WEB_PIPE);
        
    // create the named pipe used for Web status _before_ constructing 
    // the NetworkINterface
    mkfifo(STATUS_TO_WEB_PIPE, 0666);

    NetworkInterface net;
    
    // open the named pipes used for pushed status 
    _pPushedStatusPipe = fopen(STATUS_TO_WEB_PIPE, "r+");
    // open the file used to pull printer status
    _pPrinterStatusFile = fopen(PRINTER_STATUS_FILE, "w+");
    
    // set some printer status
    PrinterStatus ps;
    ps._state  = PrintingLayerState;
    ps._temperature = 3.14159;

    // send it in an update event to a NetworkInterface
    ((ICallback*)&net)->Callback(PrinterStatusUpdate, EventData(ps));
    
    // check the automatically pushed status
    if (!ExpectedStatus(STATE_NAME(PrintingLayerState), "3.14159", _pPushedStatusPipe))
    {
        std::cout << "%TEST_FAILED% time=0 testname=test1 (NetworkIFUT) message=failed to find first expected printer state and temperature" << std::endl;
        mainReturnValue = EXIT_FAILURE;
    }
       
    // and the pullable status
    if (!ExpectedStatus(STATE_NAME(PrintingLayerState), "3.14159", _pPrinterStatusFile))
    {
        std::cout << "%TEST_FAILED% time=0 testname=test1 (NetworkIFUT) message=failed to find first expected printer state and temperature again" << std::endl;
        mainReturnValue = EXIT_FAILURE;
    }
     
    ps._state  = HomingState;
    ps._temperature = 42;
    
    // check status again (should not have changed)
    if (!ExpectedStatus(STATE_NAME(PrintingLayerState), "3.14159", _pPrinterStatusFile))
    {
        std::cout << "%TEST_FAILED% time=0 testname=test1 (NetworkIFUT) message=failed to find unchanged printer state and temperature" << std::endl;
        mainReturnValue = EXIT_FAILURE;
    }
    
    // send an update event with the new status
    ((ICallback*)&net)->Callback(PrinterStatusUpdate, EventData(ps));
    
    // check the automatically pushed status
    if (!ExpectedStatus(STATE_NAME(HomingState), "42", _pPushedStatusPipe))
    {
        std::cout << "%TEST_FAILED% time=0 testname=test1 (NetworkIFUT) message=failed to find new printer state and temperature" << std::endl;
        mainReturnValue = EXIT_FAILURE;
    }
    
    // and the pullable status
    if (!ExpectedStatus(STATE_NAME(HomingState), "42", _pPrinterStatusFile))
    {
        std::cout << "%TEST_FAILED% time=0 testname=test1 (NetworkIFUT) message=failed to find new printer state and temperature again" << std::endl;
        mainReturnValue = EXIT_FAILURE;
    }
}