Exemplo n.º 1
0
void WebServerTask::setup() {

    mdns.begin(domain, WiFi.localIP());

    SPIFFS.begin();

    server.serveStatic("/settings/", SPIFFS, "/settings/index.html", "max-age=86400");
    server.serveStatic("/settings/settings.js", SPIFFS, "/settings/settings.js", "max-age=86400");

    server.on("/", [this]() {
        server.sendHeader("Location", "/settings/");
        server.send(302);
    });

    server.on("/settings/save", [this]() {
        handleSettingsSave();
    });

    server.on("/settings/get", [this]() {
        handleSettingsGet();
    });

    server.on("/debug/reset", [this]() {
        handleReset();
    });

    server.on("/debug/resetSettings", [this]() {
        handleResetSettings();
    });

    server.begin();
    Serial.println("Web server is running at http://" + String(domain) + ".local");
}
Exemplo n.º 2
0
bool parseSchedulerMessage(int size, const byte *msg, CONTEXT *context)
    {
    switch (msg[0]) 
        {
        case SCHED_CMD_QUERY_ALL:
            return handleQueryAll(size, msg, context);
            break;
        case SCHED_CMD_CREATE_TASK:
            return handleCreateTask(size, msg, context);
            break;
        case SCHED_CMD_DELETE_TASK:
            return handleDeleteTask(size, msg, context);
            break;
        case SCHED_CMD_ADD_TO_TASK:
            return handleAddToTask(size, msg, context);
            break;
        case SCHED_CMD_SCHED_TASK:
            return handleScheduleTask(size, msg, context);
            break;
        case SCHED_CMD_QUERY:
            return handleQuery(size, msg, context);
            break;
        case SCHED_CMD_RESET:
            return handleReset(size, msg, context);
            break;
         case SCHED_CMD_BOOT_TASK:
            return handleBootTask(size, msg, context);
            break;
       }
    return false;
    }
Exemplo n.º 3
0
Arquivo: main.cpp Projeto: Neon22/pixy
int main(void) 
 {	
  	pixySimpleInit();
	flash_init();
	while(1)
	{
		g_chirpUsb->service();
		handleReset();
	}
}
Exemplo n.º 4
0
struct StateClass handleYellowBlinking(enum Event event)
{
	if (event == REPEAT)
	{
		handleRepeatYellow();
		return states[YELLOW_BLINKING];
	}
	else if (event == RESET)
	{
		handleReset();
		return states[RED];
	}
}
Exemplo n.º 5
0
PlayerCommand* PlayerDriver::DoProcessQueue(status_t& ret)
{
    PlayerCommand* ec = dequeueCommand();
	printf("HelixOverWebkit [%s] [%s] [%d] ec %p, ec->command() %d\n", __FILE__, __FUNCTION__, __LINE__, ec, (ec == NULL)?-1: ec->command());
    if (ec)
    {
        switch(ec->command())
        {
        case PlayerCommand::PLAYER_SET_DATA_SOURCE:
            ret = handleSetDataSource(static_cast<PlayerSetDataSource*>(ec));
            break;

        case PlayerCommand::PLAYER_PREPARE:
            ret = handlePrepare(static_cast<PlayerPrepare*>(ec));
            break;

        case PlayerCommand::PLAYER_START:
            ret = handleStart(static_cast<PlayerStart*>(ec));
            break;

        case PlayerCommand::PLAYER_STOP:
            ret = handleStop(static_cast<PlayerStop*>(ec));
            break;

        case PlayerCommand::PLAYER_PAUSE:
            ret = handlePause(static_cast<PlayerPause*>(ec));
            break;

        case PlayerCommand::PLAYER_SEEK:
            ret = handleSeek(static_cast<PlayerSeek*>(ec));
            break;

        case PlayerCommand::PLAYER_GET_POSITION:
            ret = handleGetPosition(static_cast<PlayerGetPosition*>(ec));
            break;

        case PlayerCommand::PLAYER_RESET:
            ret = handleReset(static_cast<PlayerReset*>(ec));
            break;

        case PlayerCommand::PLAYER_QUIT:
            ret = handleQuit(static_cast<PlayerQuit*>(ec));
            break;

        default:
            //cout << "Unexpected command %d" <<  ec->command();
            break;
        }
    }
    return ec;
}
Exemplo n.º 6
0
void PiLink::receive(void){
	while (piStream.available() > 0) {
		char inByte = piStream.read();              
		switch(inByte){
		case ' ':
		case '\n':
		case '\r':
			break;

#if BREWPI_SIMULATE==1
		case 'y':
			parseJson(HandleSimulatorConfig);
			break;
		case 'Y':
			printSimulatorSettings();
			break;		
#endif						
		case 'A': // alarm on
			soundAlarm(true);
			break;
		case 'a': // alarm off
			soundAlarm(false);
			break;
			
		case 't': // temperatures requested
			printTemperatures();      
			break;		
		case 'C': // Set default constants
			tempControl.loadDefaultConstants();
			display.printStationaryText(); // reprint stationary text to update to right degree unit
			sendControlConstants(); // update script with new settings
			logInfo(INFO_DEFAULT_CONSTANTS_LOADED);
			break;
		case 'S': // Set default settings
			tempControl.loadDefaultSettings();
			sendControlSettings(); // update script with new settings
			logInfo(INFO_DEFAULT_SETTINGS_LOADED);
			break;
		case 's': // Control settings requested
			sendControlSettings();
			break;
		case 'c': // Control constants requested
			sendControlConstants();
			break;

		case 'v': // Control variables requested, send Control Object as json
		    sendControlVariables();
			break;
		case 'n':
			// v version
			// s shield type
			// y: simulator			
			// b: board
			print_P(PSTR(   "N:{"
                            "\"v\":\"" PRINTF_PROGMEM "\","
                            "\"n\":\"" PRINTF_PROGMEM "\","
                            "\"s\":%d,"
                            "\"y\":%d,"
                            "\"b\":\"%c\","
                            "\"l\":\"%d\""
                            "}"), 
					PSTR(VERSION_STRING),               // v:
					PSTR(stringify(BUILD_NAME)),      // n:                 
					getShieldVersion(),               // s:
					BREWPI_SIMULATE,                    // y:
					BREWPI_BOARD,      // b:
					BREWPI_LOG_MESSAGES_VERSION);       // l:
			printNewLine();
			break;
		case 'l': // Display content requested
			printResponse('L');						
			piStream.print('[');
			char stringBuffer[21];
			for(uint8_t i=0;i<4;i++){
				display.getLine(i, stringBuffer);
				print_P(PSTR("\"%s\""), stringBuffer);
				char close = (i<3) ? ',':']';
				piStream.print(close);
			}							
			printNewLine();						
			break;
		case 'j': // Receive settings as json
			receiveJson();
			break;

#if BREWPI_EEPROM_HELPER_COMMANDS
		case 'e': // dump contents of eeprom						
			openListResponse('E');
			for (uint16_t i=0; i<1024;) {
				if (i>0) {
					piLink.printNewLine();
					piLink.print(',');
				}
				piLink.print('\"');
				for (uint8_t j=0; j<64; j++) {
					uint8_t d = eepromAccess.readByte(i++);
					printNibble(d>>4);
					printNibble(d);
				}				
				piLink.print('\"');
			}
			closeListResponse();
			break;
#endif
			
		case 'E': // initialize eeprom
			eepromManager.initializeEeprom();
			logInfo(INFO_EEPROM_INITIALIZED);
			settingsManager.loadSettings();
			break;

		case 'd': // list devices in eeprom order
			openListResponse('d');
			deviceManager.listDevices(piStream);
			closeListResponse();
			break;

		case 'U': // update device		
			deviceManager.parseDeviceDefinition(piStream);
			break;
			
		case 'h': // hardware query
			openListResponse('h');
			deviceManager.enumerateHardwareToStream(piStream);
			closeListResponse();
			break;

#if (BREWPI_DEBUG > 0)			
		case 'Z': // zap eeprom
			eepromManager.zapEeprom();
			logInfo(INFO_EEPROM_ZAPPED);
			break;
#endif

		case 'R': // reset 
            handleReset();
            break;
            
        case 'F': // flash firmware
            flashFirmware();
            break;
            
        default:
        logWarningInt(WARNING_INVALID_COMMAND, inByte);
        }
    }
}
Exemplo n.º 7
0
void setup()
{


#ifdef ESP8266_WiFi
	String mdns_id;

	mdns_id = eepromManager.fetchmDNSName();
	if(mdns_id.length()<=0)
		mdns_id = "ESP" + String(ESP.getChipId());


	// If we're going to set up WiFi, let's get to it
	WiFiManager wifiManager;
	wifiManager.setConfigPortalTimeout(5*60); // Time out after 5 minutes so that we can keep managing temps 
	wifiManager.setDebugOutput(false); // In case we have a serial connection to BrewPi
									   
	// The main purpose of this is to set a boolean value which will allow us to know we
	// just saved a new configuration (as opposed to rebooting normally)
	wifiManager.setSaveConfigCallback(saveConfigCallback);

	// The third parameter we're passing here (mdns_id.c_str()) is the default name that will appear on the form.
	// It's nice, but it means the user gets no actual prompt for what they're entering. 
	WiFiManagerParameter custom_mdns_name("mdns", "Device (mDNS) Name", mdns_id.c_str(), 20);
	wifiManager.addParameter(&custom_mdns_name);

	wifiManager.autoConnect(); // Launch captive portal with auto generated name ESP + ChipID

	// Alright. We're theoretically connected here (or we timed out).
	// If we connected, then let's save the mDNS name
	if (shouldSaveConfig) {
		// If the mDNS name is valid, save it.
		if (isValidmDNSName(custom_mdns_name.getValue())) {
			eepromManager.savemDNSName(custom_mdns_name.getValue());
		} else {
			// If the mDNS name is invalid, reset the WiFi configuration and restart the ESP8266
			WiFi.disconnect(true);
			delay(2000);
			handleReset();
		}
	}

	// Regardless of the above, we need to set the mDNS name and announce it
	if (!MDNS.begin(mdns_id.c_str())) {
		// TODO - Do something about it or log it or something
	}
#endif


#if BREWPI_BUZZER	
	buzzer.init();
	buzzer.beep(2, 500);
#endif	

	piLink.init();

#ifdef ESP8266_WiFi
	// If we're using WiFi, initialize the bridge
	server.begin();
	server.setNoDelay(true);
	// mDNS will stop responding after awhile unless we query the specific service we want
	MDNS.addService("brewpi", "tcp", 23);
	MDNS.addServiceTxt("brewpi", "tcp", "board", "ESP8266");
	MDNS.addServiceTxt("brewpi", "tcp", "branch", "legacy");
	MDNS.addServiceTxt("brewpi", "tcp", "version", VERSION_STRING);
	MDNS.addServiceTxt("brewpi", "tcp", "revision", FIRMWARE_REVISION);
#endif

    bool initialize = !eepromManager.hasSettings();
    if(initialize) {
        eepromManager.zapEeprom();  // Writes all the empty files to SPIFFS
        logInfo(INFO_EEPROM_INITIALIZED);
    }

	logDebug("started");
	tempControl.init();
	settingsManager.loadSettings();

#if BREWPI_SIMULATE
	simulator.step();
	// initialize the filters with the assigned initial temp value
	tempControl.beerSensor->init();
	tempControl.fridgeSensor->init();
#endif	

	display.init();
#ifdef ESP8266_WiFi
	display.printWiFi();  // Print the WiFi info (mDNS name & IP address)
	delay(8000);
	display.clear();
#endif
	display.printStationaryText();
	display.printState();

//	rotaryEncoder.init();

	logDebug("init complete");
}
Exemplo n.º 8
0
// Handle decoding incoming MIDI traffic a byte at a time -- remembers
//  what it needs to from one call to the next.
//
//  This is a private function & not meant to be called from outside this class.
//  It's used whenever data is available from the serial port.
//
void Midi::recvByte(int value)
{
    int tmp;
    int channel;
    int bigval;           /*  temp 14-bit value for pitch, song pos */


    if (recvMode_ & MODE_PROPRIETARY
      && value != STATUS_END_PROPRIETARY)
    {
        /* If proprietary handling compiled in, just pass all data received
         *  after a START_PROPRIETARY event to proprietary_decode
         *  until get an END_PROPRIETARY event
         */

#ifdef CONFIG_MIDI_PROPRIETARY
        proprietaryDecode(value);
#endif

        return;
    }

    if (value & 0x80) {
    
        /* All < 0xf0 events get at least 1 arg byte so
         *  it's ok to mask off the low 4 bits to figure
         *  out how to handle the event for < 0xf0 events.
         */

        tmp = value;

        if (tmp < 0xf0)
            tmp &= 0xf0;

        switch (tmp) {
            /* These status events take 2 bytes as arguments */
            case STATUS_EVENT_NOTE_OFF:
            case STATUS_EVENT_NOTE_ON:
            case STATUS_EVENT_VELOCITY_CHANGE:
            case STATUS_EVENT_CONTROL_CHANGE:
            case STATUS_PITCH_CHANGE:
            case STATUS_SONG_POSITION:
                recvBytesNeeded_ = 2;
                recvByteCount_ = 0;
                recvEvent_ = value;
                break;

            /* 1 byte arguments */
            case STATUS_EVENT_PROGRAM_CHANGE:
            case STATUS_AFTER_TOUCH:
            case STATUS_SONG_SELECT:
                recvBytesNeeded_ = 1;
                recvByteCount_ = 0;
                recvEvent_ = value;
                return;

            /* No arguments ( > 0xf0 events) */
            case STATUS_START_PROPRIETARY:
                recvMode_ |= MODE_PROPRIETARY;

#ifdef CONFIG_MIDI_PROPRIETARY
                proprietaryDecodeStart();
#endif

                break;
            case STATUS_END_PROPRIETARY:
                recvMode_ &= ~MODE_PROPRIETARY;

#ifdef CONFIG_MIDI_PROPRIETARY
                proprietaryDecodeEnd();
#endif

                break;
            case STATUS_TUNE_REQUEST:
                handleTuneRequest();
                break;
            case STATUS_SYNC:
                handleSync();
                break;
            case STATUS_START:
                handleStart();
                break;
            case STATUS_CONTINUE:
                handleContinue();
                break;
            case STATUS_STOP:
                handleStop();
                break;
            case STATUS_ACTIVE_SENSE:
                handleActiveSense();
                break;
            case STATUS_RESET:
                handleReset();
                break;
        }

        return;
    }

    if (++recvByteCount_ == recvBytesNeeded_) {
        /* Copy out the channel (if applicable; in some cases this will be meaningless,
         *  but in those cases the value will be ignored)
         */
        channel = (recvEvent_ & 0x0f) + 1;

        tmp = recvEvent_;
        if (tmp < 0xf0) {
            tmp &= 0xf0;
        }

        /* See if this event matches our MIDI channel
         *  (or we're accepting for all channels)
         */
        if (!channelIn_
             || (channel == channelIn_)
             || (tmp >= 0xf0))
        {
            switch (tmp) {
                case STATUS_EVENT_NOTE_ON:
                    /* If velocity is 0, it's actually a note off & should fall thru
                     *  to the note off case
                     */
                    if (value) {
                        handleNoteOn(channel, recvArg0_, value);
                        break;
                    }

                case STATUS_EVENT_NOTE_OFF:
                    handleNoteOff(channel, recvArg0_, value);
                    break;
                case STATUS_EVENT_VELOCITY_CHANGE:
                    handleVelocityChange(channel, recvArg0_, value);
                    break;
                case STATUS_EVENT_CONTROL_CHANGE:
                    handleControlChange(channel, recvArg0_, value);
                    break;
                case STATUS_EVENT_PROGRAM_CHANGE:
                    handleProgramChange(channel, value);
                    break;
                case STATUS_AFTER_TOUCH:
                    handleAfterTouch(channel, value);
                    break;
                case STATUS_PITCH_CHANGE:
                    bigval = (value << 7) | recvArg0_;
                    handlePitchChange(bigval);
                    break;
                case STATUS_SONG_POSITION:
                    bigval = (value << 7) | recvArg0_;
                    handleSongPosition(bigval);
                    break;
                case STATUS_SONG_SELECT:
                    handleSongSelect(value);
                    break;
            }
        }

        /* Just reset the byte count; keep the same event -- might get more messages
            trailing from current event.
         */
        recvByteCount_ = 0;
    }
    
    recvArg0_ = value;
}
Exemplo n.º 9
0
// Handle decoding incoming MIDI traffic a byte at a time -- remembers
//  what it needs to from one call to the next.
//
//  This is a private function & not meant to be called from outside this class.
//  It's used whenever data is available from the serial port.
//
void USBMidi::dispatchPacket(uint32 p)
{
    union EVENT_t e;
    
    e.i=p;
    // !!!!!!!!!!!!!!!!  Add a sysex handler  FIX THIS VERY VERY SHORTLY !!!!!!!!!!!!!!
    if (recvMode_ & MODE_PROPRIETARY
        && CIN_IS_SYSEX(e.p.cin))
    {
        /* If sysex handling compiled in, just pass all data received
         * to the sysex handler
         */
        
#ifdef CONFIG_MIDI_PROPRIETARY
//        handleSysex(p);
#endif
        
        return;
    }
    
    switch (e.p.cin) {
        case CIN_3BYTE_SYS_COMMON:
            if (e.p.midi0 == MIDIv1_SONG_POSITION_PTR) {
                handleSongPosition(((uint16)e.p.midi2)<<7|((uint16)e.p.midi1));
            }
            break;

        case CIN_2BYTE_SYS_COMMON:
             switch (e.p.midi0) {
                 case MIDIv1_SONG_SELECT:
                     handleSongSelect(e.p.midi1);
                     break;
                 case MIDIv1_MTC_QUARTER_FRAME:
                     // reference library doesnt handle quarter frame.
                     break;
             }
            break;
        case CIN_NOTE_OFF:
            handleNoteOff(MIDIv1_VOICE_CHANNEL(e.p.midi0), e.p.midi1, e.p.midi2);
            break;
        case CIN_NOTE_ON:
            handleNoteOn(MIDIv1_VOICE_CHANNEL(e.p.midi0), e.p.midi1, e.p.midi2);
            break;
        case CIN_AFTER_TOUCH:
            handleVelocityChange(MIDIv1_VOICE_CHANNEL(e.p.midi0), e.p.midi1, e.p.midi2);
            break;
        case CIN_CONTROL_CHANGE:
            handleControlChange(MIDIv1_VOICE_CHANNEL(e.p.midi0), e.p.midi1, e.p.midi2);
            break;
        case CIN_PROGRAM_CHANGE:
            handleProgramChange(MIDIv1_VOICE_CHANNEL(e.p.midi0), e.p.midi1);
            break;
        case CIN_CHANNEL_PRESSURE:
            handleAfterTouch(MIDIv1_VOICE_CHANNEL(e.p.midi0), e.p.midi1);
            break;
                     
        case CIN_PITCH_WHEEL:
            handlePitchChange(((uint16)e.p.midi2)<<7|((uint16)e.p.midi1));
            break;
        case CIN_1BYTE:
            switch (e.p.midi0) {
                case MIDIv1_CLOCK:
                    handleSync();
                    break;
                case MIDIv1_TICK:
                    break;
                case MIDIv1_START:
                    handleStart();
                    break;
                case MIDIv1_CONTINUE:
                    handleContinue();
                    break;
                case MIDIv1_STOP:
                    handleStop();
                    break;
                case MIDIv1_ACTIVE_SENSE:
                    handleActiveSense();
                    break;
                case MIDIv1_RESET:
                    handleReset();
                    break;
                case MIDIv1_TUNE_REQUEST:
                    handleTuneRequest();
                    break;

                default:
                    break;
            }
            break;
    }
}
Exemplo n.º 10
0
/**
 * \see trafficlight.h
 */
void runTrafficLight() 
{
	/* initial state */
	enum Event event = NO_EVENT;
	enum State state = RED;
	toggleLight(RED_LIGHT, ON);

	timer(RED_TIME, STANDBY);
	
	/* state machine loop */
	while (1) 
	{
		event = checkEvent(); // check if an event has been triggered

		switch (event) 
		{
			case STANDBY:
				if (state == RED) 
				{
					state = RED_YELLOW;
					handleStandby();			
				}
				break;
			case GO:
				if (state == RED_YELLOW) 
				{
					state = GREEN;
					handleGo();						            
				}
				break;
			case PREPARE_TO_STOP:
				if (state == GREEN) 
				{
					state = GREEN_BLINKING;
					handlePrepareToStop();
				}
				break;
			case REPEAT:
				if (state == GREEN_BLINKING) 
				{
					handleRepeatGreen();
				}
				else if (state == YELLOW_BLINKING) 
				{
					handleRepeatYellow();
				}
				break;
			case STOP:
				if (state == GREEN_BLINKING) 
				{
					state = YELLOW;
					handleStop();
				}
				break;
			case WAIT:
				if (state == YELLOW) 
				{
					state = RED;
					handleWait();
				}
				break;
			case IDLE:
				if (state == RED) 
				{
					state = YELLOW_BLINKING;
					handleIdle();
				}
			case RESET:
				if (state == YELLOW_BLINKING) 
				{
					state = RED;
					handleReset();
				}
				break;
		}
	}
}