Ejemplo n.º 1
0
// Modulate the IR LED for the given period (usec) and at the duty cycle set.
//
// Args:
//   usec: The period of time to modulate the IR LED for, in microseconds.
// Returns:
//   Nr. of pulses actually sent.
//
// Note:
//   The ESP8266 has no good way to do hardware PWM, so we have to do it all
//   in software. There is a horrible kludge/brilliant hack to use the second
//   serial TX line to do fairly accurate hardware PWM, but it is only
//   available on a single specific GPIO and only available on some modules.
//   e.g. It's not available on the ESP-01 module.
//   Hence, for greater compatibility & choice, we don't use that method.
// Ref:
//   https://www.analysir.com/blog/2017/01/29/updated-esp8266-nodemcu-backdoor-upwm-hack-for-ir-signals/
uint16_t IRsend::mark(uint16_t usec) {
  // Handle the simple case of no required frequency modulation.
  if (!modulation || _dutycycle >= 100) {
    ledOn();
    _delayMicroseconds(usec);
    ledOff();
    return 1;
  }

  // Not simple, so do it assuming frequency modulation.
  uint16_t counter = 0;
  IRtimer usecTimer = IRtimer();
  // Cache the time taken so far. This saves us calling time, and we can be
  // assured that we can't have odd math problems. i.e. unsigned under/overflow.
  uint32_t elapsed = usecTimer.elapsed();

  while (elapsed < usec) {  // Loop until we've met/exceeded our required time.
    ledOn();
    // Calculate how long we should pulse on for.
    // e.g. Are we to close to the end of our requested mark time (usec)?
    _delayMicroseconds(std::min((uint32_t) onTimePeriod, usec - elapsed));
    ledOff();
    counter++;
    if (elapsed + onTimePeriod >= usec)
      return counter;  // LED is now off & we've passed our allotted time.
    // Wait for the lesser of the rest of the duty cycle, or the time remaining.
    _delayMicroseconds(std::min(usec - elapsed - onTimePeriod,
                                (uint32_t) offTimePeriod));
    elapsed = usecTimer.elapsed();  // Update & recache the actual elapsed time.
  }
  return counter;
}
Ejemplo n.º 2
0
/*
 * Summary:     Signals whether this specific board is set to give a faulty result
 *              3 flashes with half-second interval;
 *              GREEN=>non-faulty, RED=>faulty.
 * Parameters:  u32 led status
 *              BODY_RGB_GREEN_PIN = green, BODY_RGB_RED_PIN = red
 * Return:      None.
 */
void
faultSignal(u32 STATUS_LED)
{
  bool LED_PIN_STATE[3] =
    { false }; // place-holder for remembering which LEDs were on

  for (u32 i = 0; i < 3; ++i)
    { // Preserve the state of the LED lights
      LED_PIN_STATE[i] = ledIsOn(LED_PIN[i]);
      ledOff(LED_PIN[i]); // Turn off the light
    }

  for (u32 j = 0; j < 3; ++j)
    { // Flash thrice if faulty or not
      ledOn(STATUS_LED);
      delay(FAULT_STATUS_PERIOD);

      ledOff(STATUS_LED);
      delay(FAULT_STATUS_PERIOD);
    }

  for (u32 k = 0; k < 3; ++k)
    if (LED_PIN_STATE[k])
      ledOn(LED_PIN[k]); // Restore the state of the LED lights

  return;
}
Ejemplo n.º 3
0
/* entry points ======================================================== */
int main(void)
{
	int i;

	initLeds();

	while(1)
	{
		ledOn(LED_D1_GPIO_PORT,LED_D1_GPIO_PIN);
		ledOn(LED_D2_GPIO_PORT,LED_D2_GPIO_PIN);
		ledOn(LED_D3_GPIO_PORT,LED_D3_GPIO_PIN);
		ledOn(LED_D4_GPIO_PORT,LED_D4_GPIO_PIN);

		for(i=0;i<0x500000;i++);

		ledOff(LED_D1_GPIO_PORT,LED_D1_GPIO_PIN);
		ledOff(LED_D2_GPIO_PORT,LED_D2_GPIO_PIN);
		ledOff(LED_D3_GPIO_PORT,LED_D3_GPIO_PIN);
		ledOff(LED_D4_GPIO_PORT,LED_D4_GPIO_PIN);

		for(i=0;i<0x500000;i++);

	}

}
Ejemplo n.º 4
0
void ledBlinkOne(unsigned char _led,unsigned int _delay,unsigned char _repeat)
{
unsigned char i;
ledNo(0);
for(i=0;i<=_repeat;i++)
{
ledOn(_led,1);
_delay_milli(_delay);
ledOn(_led,0);
_delay_milli(_delay);
}
ledNo(0);
}
Ejemplo n.º 5
0
void testledOnOff(void)
{
unsigned char i;
for(i=1;i<=4;i++)
{
_delay_milli(LED_ON_OFF_DELAY);
ledOn(i,1);
}
for(i=1;i<=4;i++)
{
_delay_milli(LED_ON_OFF_DELAY);
ledOn(i,0);
}
}
void blink(void *pdata)
{
	(void)pdata;
	while (1) {
		ledOn();
		OSTimeDly(1);
		ledOff();
		OSTimeDly(29);
		ledOn();
		OSTimeDly(1);
		ledOff();
		OSTimeDly(219);
	}
}
Ejemplo n.º 7
0
void readSensors(DataPacket_t *packet)
{
    PRINTF("reading sensors...\n");
    uint32_t start = getJiffies();

    ledOn();
    humidityOn();

    packet->timestamp = getUptime();
    if (!islRead(&packet->islLight, true)) {
        PRINT("islRead failed\n");
        packet->islLight = 0xffff;
    // } else {
    //     PRINT("islRead OK\n");
    }
    packet->internalVoltage = adcRead(ADC_INTERNAL_VOLTAGE);
    packet->internalTemperature = adcRead(ADC_INTERNAL_TEMPERATURE);
    packet->sht75Humidity = humidityRead();
    packet->sht75Temperature = temperatureRead();

    humidityOff();
    ledOff();

    uint32_t end = getJiffies();
    PRINTF("   time spent: %u ms\n", end - start);
}
Ejemplo n.º 8
0
long Transmitter::getBytes()
{
	long temp = bytes;
	bytes = 0;
	ledOn(false);
	return temp;
}
Ejemplo n.º 9
0
void ICACHE_FLASH_ATTR mqtt_timer(void *arg)
{
	static bool on = true;
	MQTT_Client* client = (MQTT_Client*)arg;
	mqtt_message_t* outbound_message;
#if 0
	INFO("\r\nLED: %s\r\n", on ? "on" : "off");
	ledOn(on);
	on = !on;
#endif
	if(client->connState == MQTT_DATA){
		client->keepAliveTick ++;
		if(client->keepAliveTick > client->mqtt_state.connect_info->keepalive){

//spam			INFO("\r\nMQTT: Send keepalive packet to %s:%d!\r\n", client->host, client->port);
			outbound_message = mqtt_msg_pingreq(&client->mqtt_state.mqtt_connection);
			if(QUEUE_Puts(&client->msgQueue, outbound_message->data, outbound_message->length) == -1){
//spam				INFO("MQTT: Exceed the amount of queues\r\n");
			}

			client->keepAliveTick = 0;
			system_os_post(MQTT_TASK_PRIO, 0, (os_param_t)client);
		}

	} else if(client->connState == TCP_RECONNECT_REQ){
		client->reconnectTick ++;
		if(client->reconnectTick > MQTT_RECONNECT_TIMEOUT) {
//spam			INFO("MQTT: Recon timeout\r\n");
			client->reconnectTick = 0;
			client->connState = TCP_RECONNECT;
			system_os_post(MQTT_TASK_PRIO, 0, (os_param_t)client);
		}
	}
}
Ejemplo n.º 10
0
void toggleLed()
{
        static int state=0;
        if(state==0) ledOff();
        else ledOn();
        state^=0x01;
}
Ejemplo n.º 11
0
void main (void)
{
	unsigned char led ;
													
	ledOff();							 // Set led off
	led = LED_OFF;
		
	for	(;;)
	{
		for (;getkey() == KEY_OFF;);	// Key is now off
		delayms(10);

		if (led == LED_OFF)				// key is now on
		{
			led = LED_ON;
			ledOn();
		}
		else
		{
			led = LED_OFF;
			ledOff();
		}
		for (;getkey() == KEY_ON;);		// key is now on
		delayms(10);					// key is now off

	}
}
Ejemplo n.º 12
0
void main (void)
{
	unsigned char lastsw, led ;

	P1 =0xFF;
	ledOff();

	lastsw = getKey();
	
	for(;;)
	{
		if (( getKey() == KEYON ) && ( lastsw == KEYOFF) )
		{
			 if (led == 1)
			 {
			 	led = LIGHTOFF;
				ledOff();
				
			 }
			 else
			 {
			  	led = LIGHTON;
				ledOn();
			 }
		 }
	}
}
Ejemplo n.º 13
0
static void appSendData(void)
{
#ifdef NWK_ENABLE_ROUTING
  msg.parentShortAddr = NWK_RouteNextHop(0);
#else
  msg.parentShortAddr = 0;
#endif

  msg.sensors.battery     = rand();
  msg.sensors.temperature = rand() & 0x7f;
//  msg.sensors.light       = rand() & 0xff;

#if APP_COORDINATOR
  appSendMessage((uint8_t *)&msg, sizeof(msg));
  SYS_TimerStart(&appDataSendingTimer);
  appState = APP_STATE_WAIT_SEND_TIMER;
#else
  nwkDataReq.dstAddr = 0;
  nwkDataReq.dstEndpoint = APP_ENDPOINT;
  nwkDataReq.srcEndpoint = APP_ENDPOINT;
  nwkDataReq.options = NWK_OPT_ACK_REQUEST | NWK_OPT_ENABLE_SECURITY;
  nwkDataReq.data = (uint8_t *)&msg;
  nwkDataReq.size = sizeof(msg);
  nwkDataReq.confirm = appDataConf;

  ledOn(LED_DATA);
  NWK_DataReq(&nwkDataReq);

  appState = APP_STATE_WAIT_CONF;
#endif
}
Ejemplo n.º 14
0
static void appDataConf(NWK_DataReq_t *req)
{
  ledOff(LED_DATA);

  if (NWK_SUCCESS_STATUS == req->status)
  {
    if (!appNetworkStatus)
    {
      ledOn(LED_NETWORK);
      SYS_TimerStop(&appNetworkStatusTimer);
      appNetworkStatus = true;
    }
  }
  else
  {
    msg.sensors.light++;

    if (appNetworkStatus)
    {
      ledOff(LED_NETWORK);
      SYS_TimerStart(&appNetworkStatusTimer);
      appNetworkStatus = false;
    }
  }

  appState = APP_STATE_SENDING_DONE;
}
Ejemplo n.º 15
0
void Transmitter::send(float *sample, int samples)
{
	if (isSpeaking(sample, samples)) 
	{
		if (status == TRANSMITTER_STATUS_WAITING)
			status = TRANSMITTER_STATUS_START;
		speak = stoptx; // To guarantee stream even for small speech pauses
	}
	switch (status)
	{
		case TRANSMITTER_STATUS_START:
			sendAudioPacket(prebuffer, frame_size);
			status = TRANSMITTER_STATUS_NORMAL;
		case TRANSMITTER_STATUS_NORMAL:
			if (speak > 0) {
				sendAudioPacket(sample, samples);
				speak--;
				break;
			}
			else 
			{
				status = TRANSMITTER_STATUS_WAITING;
			}
		case TRANSMITTER_STATUS_WAITING:  // It keeps the previous buffer to anticipate a little the speech
			memcpy(prebuffer, sample, samples*sizeof(float));
		case TRANSMITTER_STATUS_MUTE:
			ledOn(false);
			break;
	}
}
Ejemplo n.º 16
0
byte BlinkPlug::state () {
    byte saved = leds;
    ledOff(1+2);
    byte result = !digiRead() | (!digiRead2() << 1);
    ledOn(saved);
    return result;
}
Ejemplo n.º 17
0
static void APP_TaskHandler(void)
{
  switch (appState)
  {
    case APP_STATE_INITIAL:
    {
      appInit();
    } break;

    case APP_STATE_SEND:
    {
      appSendData();
    } break;

    case APP_STATE_SENDING_DONE:
    {
#if APP_ENDDEVICE
      appState = APP_STATE_PREPARE_TO_SLEEP;
#else
      SYS_TimerStart(&appDataSendingTimer);
      appState = APP_STATE_WAIT_SEND_TIMER;
#endif
    } break;

    case APP_STATE_PREPARE_TO_SLEEP:
    {
      if (!NWK_Busy())
      {
        NWK_SleepReq();
        appState = APP_STATE_SLEEP;
      }
    } break;

    case APP_STATE_SLEEP:
    {
      ledsClose();

      PHY_SetRxState(false);

      HAL_Sleep(APP_SENDING_INTERVAL);
      appState = APP_STATE_WAKEUP;
    } break;

    case APP_STATE_WAKEUP:
    {
      NWK_WakeupReq();

      ledsInit();
      ledOn(LED_NETWORK);

      PHY_SetRxState(true);

      appState = APP_STATE_SEND;
    } break;

    default:
      break;
  }
}
Ejemplo n.º 18
0
/* Toggle the state of an LED */
void ledToggle(Led_TypeDef led) {
    uint8_t curState = 0;
    
    curState = GPIO_ReadOutputDataBit(LED_PORT[led], LED_PIN[led]);

    if (curState) ledOff(led);
    else ledOn(led);
}
Ejemplo n.º 19
0
inline static void ledRapidBlink(uint8_t times) {
	for(int i = 0; i < times; i++) {
		ledOn();
		delay(200);
		ledOff();
		delay(200);
	}
}
Ejemplo n.º 20
0
void displayBuffer::secondOn(unsigned int second)
{
  if(second < 60)
  {
    clockTime[SECOND] = second;
    ledOn(getSecondLedNr(clockTime[SECOND]));
  }
}
Ejemplo n.º 21
0
void displayBuffer::minuteOn(unsigned int minute)
{
  if(minute < 60)
  {
    clockTime[MINUTE] = minute;
    ledOn(getMinuteLedNr(clockTime[MINUTE]));
  }
}
Ejemplo n.º 22
0
void displayBuffer::hourOn(unsigned int hour)
{
  if(hour < 12)
  {
    clockTime[HOUR] = hour;
    ledOn(getHourLedNr(clockTime[HOUR]));
  }
}
Ejemplo n.º 23
0
Archivo: main.c Proyecto: atiselsts/osw
void appMain(void)
{
    uint16_t i;

    // ------------------------- serial number
    DPRINTF("Mote %#04x starting...\n", localAddress);

    // ------------------------- external flash
#if WRITE_TO_FLASH
    prepareExtFlash();
#endif

    // ------------------------- light sensors
    if (localAddress != 0x0796) {
        PRINT("init isl\n");
        islInit();
        islOn();
    } else {
        PRINT("init ads\n");
        adsInit();
        adsSelectInput(0);
    }

    // ------------------------- main loop
    mdelay(3000);
    DPRINTF("starting main loop...\n");
    for (i = 0; i < 6; ++i) {
        redLedToggle();
        mdelay(100);
    }
    ledOff();

    uint32_t nextDataReadTime = 0;
    uint32_t nextBlinkTime = 0;
    for (;;) {
        uint32_t now = getRealTime();
        if (timeAfter32(now, nextDataReadTime)) {
            if (getJiffies() < 300 * 1000ul ) {
                nextDataReadTime = now + DATA_INTERVAL_SMALL;
            } else {
                nextDataReadTime = now + DATA_INTERVAL;
            }
            DataPacket_t packet;
            readSensors(&packet);
#if PRINT_PACKET
            printPacket(&packet);
#endif
        }
        if (timeAfter32(now, nextBlinkTime)) {
            nextBlinkTime = now + BLINK_INTERVAL;
            ledOn();
            msleep(100);
            ledOff();
        }
        msleep(1000);
    }
}
Ejemplo n.º 24
0
Archivo: main.c Proyecto: atiselsts/osw
void appMain(void)
{
    PRINTF("Mote %#04x data...\n", localAddress);
    ledOn();
    prepareExtFlash();
    readExtFlash();
    //PRINTF("External flash is empty!\n");
    ledOff();
}
Ejemplo n.º 25
0
void inIRQTimer(){
	#define CHK 10
	char channels[CHK] = {1,2,3,5,7,10,16,29,57,62};

	uint16_t s;
	static uint16_t n = CHK;

	if (n++ >= CHK)
		n = 0;


	//loggerWrite("\n\r",2);
	//loggerWrite("\n\r",2);

	s = spektrum[channels[n]] ;
	//loggerWrite("\n\r",2);
	//s /= FFT_N;
		
	if(s >= 1){
		if (s > 2){
			if (s > 4){
				if (s > 7){
					if (s > 10){
						if (s > 14){
							if ( s > 20){
								if (s > 30){
									if (s > 55){
										if ( s > 70){
											if (s > 100){
												if (s > 135){
													if (s > 155){
														if ( s > 180){
															s = 14;
														} else s = 13;
													} else s = 12;
												} else s = 11;
											} else s = 10;
										} else s = 9;
									} else s = 8;
								} else s = 7;
							} else s = 6;
						} else s = 5;
					} else s = 4;
				} else s = 3;
			} else s = 2;
		} else s = 1;
	} else s = 0;

					
	//for (m = 0; m < s; m++) loggerWrite("**",1);

	ledOff();
	setChannel(n);
	ledOn(s);


}
int main(void)
{
	unsigned long i;
	
	// Configurations.
	clockConfiguration();
	moduleEnable();
	
	// Port.
	portSetup();
	
	// USB.
	usbModuleSetup();
	usbPipeSetup();
	usbInterruptSetup();
	
	// 
	irqConfiguration();
	
    
	DEBUGFIFO_Init();


	//HW_Init();


	// TODO: add application code here
	DEBUGFIFO_OutLine("============================");
	DEBUGFIFO_OutLine("=== RX62 USB TEST Start! ===");
	DEBUGFIFO_OutLine("============================");
	DEBUGFIFO_OutLine("");

	
	// Wait for setup;
	for(i = 0; i < 0x017FFFFF; i++);

	ledOn();
	
	DEBUGFIFO_OutLine("LED ON.");		

    while (1) {
		unsigned char c[3] = {0x00, 0x40, 0x40};
		
		for(i = 0; i < 0x00400000; i++);
		DEBUGFIFO_OutLine("Loop!");		

		p_pipe2Buf = &c[0];
		pipe2BufCnt = 3;

		USB0.BRDYENB.BIT.PIPE1BRDYE = 1;
    }
  
  	return 0;
}
Ejemplo n.º 27
0
main()
{
    ledInit();
    
    for (;;) {
        ledOn();
        delay(1000);
        ledOff();
        delay(1000);
    }
}
Ejemplo n.º 28
0
void ColorSensor::setActive() {
  ledOn();
  writeRegister(CAP_RED, 15);
  writeRegister(CAP_GREEN, 15);
  writeRegister(CAP_BLUE, 15);
  writeRegister(CAP_CLEAR, 15);
  // calibrated to ~800 covered with white paper
  writeRegisterLong(INT_RED_LO, 333);
  writeRegisterLong(INT_GREEN_LO, 354);
  writeRegisterLong(INT_BLUE_LO, 436);
  writeRegisterLong(INT_CLEAR_LO, 130);
}
Ejemplo n.º 29
0
Archivo: main.c Proyecto: atiselsts/osw
void readSensors(DataPacket_t *packet)
{
    DPRINTF("reading sensors...\n");

    ledOn();
    humidityOn();

    packet->timestamp = getJiffies();
    packet->sourceAddress = localAddress;
    packet->dataSeqnum = ++dataSeqnum;

    if (localAddress != 0x0796) {
        if (!islRead(&packet->islLight, true)) {
            PRINT("islRead failed\n");
            packet->islLight = 0xffff;
        }
        packet->sq100Light = 0xffff;
    } else {
        packet->islLight = 0xffff;
        if (!readAds(&packet->sq100Light)) {
            PRINT("readAdsRegister failed\n");
            packet->sq100Light = 0xffff;
        }
    }

    packet->internalVoltage = adcRead(ADC_INTERNAL_VOLTAGE);
    packet->internalTemperature = adcRead(ADC_INTERNAL_TEMPERATURE);

    DPRINT("read hum\n");
    packet->sht75Humidity = humidityRead();
    packet->sht75Temperature = temperatureRead();
    DPRINT("read done\n");

    packet->crc = crc16((uint8_t *) packet, sizeof(*packet) - 2);

#if WRITE_TO_FLASH
    if (extFlashAddress < EXT_FLASH_SIZE) {
        DPRINT("Writing to flash\n");
        extFlashWrite(extFlashAddress, packet, sizeof(*packet));
        DataPacket_t verifyRecord;
        memset(&verifyRecord, 0, sizeof(verifyRecord));
        extFlashRead(extFlashAddress, &verifyRecord, sizeof(verifyRecord));
        if (memcmp(packet, &verifyRecord, sizeof(verifyRecord))) {
            ASSERT("writing in flash failed!" && false);
        }
        extFlashAddress += sizeof(verifyRecord);
    }
#endif

    humidityOff();
    ledOff();
}
Ejemplo n.º 30
0
int main(){
	uint16_t counter=0;
	PORTD = 0x08;
	DDRB |= 0x01; /*Enable LED*/
	_delay_ms(100);
	if((PIND & 0x08) != 0){
		PORTD = 0x00;
		ledOn();
		_delay_ms(100);
		ledOff();
		DDRB &= ~0x01;
		asm volatile("jmp 0x0000\n\t");
	}