//--------- Begin of function HelpSaveScreen::save_scr --------// //! void HelpSaveScreen::save_scr(int x1, int y1, int x2, int y2, VgaBuf* vgaBuf ) { if( !is_clear() ) // there is already a screen saved return; err_when( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT ); long saveSize = (long)(x2-x1+1) * (y2-y1+1); err_when( saveSize > HELP_SCR_BUF_SIZE ); if( !vgaBuf ) vgaBuf = &vga_front; save_scr_x1 = x1; save_scr_y1 = y1; save_scr_x2 = x2; save_scr_y2 = y2; if( vgaBuf->is_front ) mouse.hide_area( x1, y1, x2, y2 ); save_scr_buf->clear(); save_scr_buf->resize( x1, y1, x2-x1+1, y2-y1+1 ); vgaBuf->read_bitmapW( x1, y1, x2, y2, save_scr_buf->bitmap_ptr() ); if( vgaBuf->is_front ) mouse.show_area(); unclear(); }
void NEXA::Receiver::on_interrupt(uint16_t arg) { // Check start condition if (m_start == 0L) { if (is_clear()) return; m_start = RTC::micros(); m_ix = 0; return; } // Calculate the pulse width (both low and high) and check against threshold uint32_t stop = RTC::micros(); uint32_t us = (stop - m_start); m_start = stop; if (us < LOW_THRESHOLD || us > HIGH_THRESHOLD) goto exception; m_sample[m_ix & IX_MASK] = us; m_ix += 1; // Decode every four pulses to a bit if ((m_ix & IX_MASK) == 0) { int8_t bit = decode_bit(); if (bit < 0) goto exception; m_code = (m_code << 1) | bit; } if (m_ix != IX_MAX) return; // And when all samples have been read push an event Event::push(Event::RECEIVE_COMPLETED_TYPE, this); exception: m_start = 0L; }
void Touch::run() { // Check if sampling should be initiated if (!m_sampling) { mode(INPUT_MODE); m_sampling = true; return; } // Sample the pin and discharge uint8_t state = is_clear(); mode(OUTPUT_MODE); clear(); m_sampling = false; // Was the pin discharge during the sampling period if (state) { m_start = RTT::millis(); if (!m_touched) { on_touch(); m_touched = true; } return; } // The pin was discharge; low-pass filter pin change if (m_touched && (RTT::since(m_start) > THRESHOLD)) { m_touched = false; } }
int main(void) { set_input(DDRB, Switch1); set_output(DDRB, GreenLED); set_output(DDRB, RedLED); while(1) { if(is_clear(PINB, Switch1) && State == 0) { output_high(PORTB, GreenLED); output_low(PORTB, RedLED); } else { output_high(PORTB, RedLED); output_low(PORTB, GreenLED); } switch (State) { case BUTTON_PRESS: break; case LIGHT_LED: break; case LIGHT_LED: } if(is_clear(PINB, Switch1)) { output_high(PORTB, GreenLED); output_low(PORTB, RedLED); } else { output_high(PORTB, RedLED); output_low(PORTB, GreenLED); } _delay_ms(5); } }
//--------- Begin of function HelpSaveScreen::show_area --------// //! void HelpSaveScreen::show_area() { if( is_clear() ) // already restored, or not saved yet return; if( hiding_flag && hiding_flag == hide_area_count ) { vga_front.read_bitmapW( save_scr_x1, save_scr_y1, save_scr_x2, save_scr_y2, save_scr_buf->bitmap_ptr() ); hiding_flag = 0; } --hide_area_count; err_when( hide_area_count < 0 ); }
//--------- Begin of function HelpSaveScreen::hide_area --------// //! void HelpSaveScreen::hide_area(int x1, int y1, int x2, int y2 ) { if( is_clear() ) // there is already a screen saved return; ++hide_area_count; if( !hiding_flag && m.is_touch( x1, y1, x2, y2, save_scr_x1, save_scr_y1, save_scr_x2, save_scr_y2 ) ) { // don't handle mouse cursor vga.active_buf->put_bitmapW( save_scr_x1, save_scr_y1, save_scr_buf->bitmap_ptr() ); hiding_flag = hide_area_count; } }
//this function called when backoff timer expires //THIS IS IN AN INTERRUPT CONTEXT static void backoff_alarm_func(void *user_data) { if (is_clear ()) { //channel clear, fire off send state machine sent_flag = true; mos_thread_resume(sendThread); backoff_alarm.reset_to = 0; } else { //channel busy, wait again rand_val = random () % congestBackoff + 1; backoff_alarm.reset_to = rand_val * 2; //mos_alarm(&backoff_alarm, rand_val * 2); } }
//--------- Begin of function HelpSaveScreen::rest_scr --------// //! void HelpSaveScreen::rest_scr(VgaBuf* vgaBuf, int keepUnclear ) { if( is_clear() ) // already restored, or not saved yet return; err_when( save_scr_x1>save_scr_x2 || save_scr_y1>save_scr_y2 || save_scr_x1<0 || save_scr_y1<0 || save_scr_x2>=VGA_WIDTH || save_scr_y2>=VGA_HEIGHT ); if( !vgaBuf ) vgaBuf = &vga_front; // mouse.hide_area( save_scr_x1, save_scr_y1, save_scr_x2, save_scr_y2 ); vgaBuf->put_bitmapW( save_scr_x1, save_scr_y1, save_scr_buf->bitmap_ptr() ); // mouse.show_area(); if( !keepUnclear ) clear(); // state that it has been restored. }
bool OWI::reset() { uint8_t retry = 4; uint8_t res = 0; do { set_mode(OUTPUT_MODE); set(); clear(); DELAY(480); set(); synchronized { set_mode(INPUT_MODE); DELAY(70); res = is_clear(); } DELAY(410); } while (retry-- && !res); return (res != 0); }
int main(void) { set_input(DDRB, Switch1); set_output(DDRB, GreenLED); set_output(DDRB, RedLED); while(1) { if(is_clear(PINB, Switch1)) { output_high(PORTB, GreenLED); output_low(PORTB, RedLED); } else { output_high(PORTB, RedLED); output_low(PORTB, GreenLED); } _delay_ms(5); } }
/******************************************************************** * Function: void BlinkUSBStatus(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: BlinkUSBStatus turns on and off LEDs * corresponding to the USB device state. * * Note: mLED macros can be found in HardwareProfile.h * USBDeviceState is declared and updated in * usb_device.c. *******************************************************************/ void BlinkUSBStatus(void) { static WORD led_count=0; char a=0; if(led_count == 0)led_count = 10000U; led_count--; #define mLED_Both_Off() {mLED_1_Off();mLED_2_Off();} #define mLED_Both_On() {mLED_1_On();mLED_2_On();} #define mLED_Only_1_On() {mLED_1_On();mLED_2_Off();} #define mLED_Only_2_On() {mLED_1_Off();mLED_2_On();} a = is_clear(); if(a=1) { mLED_3_On(); } else { mLED_3_Off(); } if(USBSuspendControl == 1) { if(led_count==0) { mLED_1_Toggle(); if(mGetLED_1()) { mLED_2_On(); } else { mLED_2_Off(); } }//end if } else { if(USBDeviceState == DETACHED_STATE) { mLED_Both_Off(); } else if(USBDeviceState == ATTACHED_STATE) { mLED_Both_On(); } else if(USBDeviceState == POWERED_STATE) { mLED_Only_1_On(); } else if(USBDeviceState == DEFAULT_STATE) { mLED_Only_2_On(); } else if(USBDeviceState == ADDRESS_STATE) { if(led_count == 0) { mLED_1_Toggle(); mLED_2_Off(); }//end if } else if(USBDeviceState == CONFIGURED_STATE) { if(led_count==0) { mLED_1_Toggle(); if(mGetLED_1()) { mLED_2_Off(); } else { mLED_2_On(); } }//end if }//end if(...) }//end if(UCONbits.SUSPND...) }//end BlinkUSBStatus