void NEXA::Transmitter::send_code(code_t cmd, int8_t onoff) { // Send the code four times with a pause between each for (uint8_t i = 0; i < SEND_CODE_MAX; i++) { const uint8_t BITS_MAX = 32; const uint8_t ONOFF_POS = 27; int32_t bits = cmd; // Send start pulse with extended delay, code bits and stop pulse send_pulse(0); DELAY(START_PULSE); for (uint8_t j = 0; j < BITS_MAX; j++) { // Check for dim level (-1..-15) if ((j == ONOFF_POS) && (onoff < 0)) { send_pulse(0); send_pulse(0); } else send_bit(bits < 0); bits <<= 1; } // Check for dim level transmission; level encoded as -1..-15 if (onoff < 0) { int8_t level = (-onoff) << 4; for (uint8_t j = 0; j < 4; j++) { send_bit(level < 0); level <<= 1; } } send_pulse(0); RTC::delay(PAUSE); } }
/* lirc to tx */ static ssize_t lirc_write(struct file *file, const char *buf, size_t n, loff_t *ppos) { int i, count; unsigned long flags; long delta = 0; int *wbuf; if (!gpio_out_pin) { return -ENODEV; } count = n / sizeof(int); if (n % sizeof(int) || count % 2 == 0) return -EINVAL; wbuf = memdup_user(buf, n); if (IS_ERR(wbuf)) return PTR_ERR(wbuf); spin_lock_irqsave(&lock, flags); dprintk("lirc_write called, offset %d",TX_OFFSET_GPIOCHIP); for (i = 0; i < count; i++) { if (i%2) send_space(wbuf[i] - delta); else delta = send_pulse(wbuf[i]); } gpiochip->set(gpiochip, TX_OFFSET_GPIOCHIP, invert); spin_unlock_irqrestore(&lock, flags); if (count>11) { dprintk("lirc_write sent %d pulses: no10: %d, no11: %d\n",count,wbuf[10],wbuf[11]); } kfree(wbuf); return n; }
inline void send_repeat(struct ir_remote *remote) { send_lead(remote); send_pulse(remote->prepeat); send_space(remote->srepeat); send_trail(remote); }
static ssize_t lirc_write(struct file *file, const char *buf, size_t n, loff_t *ppos) { int i, count; unsigned long flags; long delta = 0; int *wbuf; count = n / sizeof(int); if (n % sizeof(int) || count % 2 == 0) return -EINVAL; wbuf = memdup_user(buf, n); if (IS_ERR(wbuf)) return PTR_ERR(wbuf); spin_lock_irqsave(&lock, flags); for (i = 0; i < count; i++) { if (i%2) send_space(wbuf[i] - delta); else delta = send_pulse(wbuf[i]); } gpiochip->set(gpiochip, gpio_out_pin, invert); spin_unlock_irqrestore(&lock, flags); kfree(wbuf); return n; }
int hcsr04_send_pulse(void) { if (oper_mode == CONTINUOUS) return 0; return send_pulse(); }
inline void send_header(struct ir_remote *remote) { if (has_header(remote)) { send_pulse(remote->phead); send_space(remote->shead); } }
inline void send_foot(struct ir_remote *remote) { if (has_foot(remote)) { send_space(remote->sfoot); send_pulse(remote->pfoot); } }
void send_lead(struct ir_remote *remote) { if(remote->plead!=0) { send_pulse(remote->plead); } }
void send_trail(struct ir_remote *remote) { if(remote->ptrail!=0) { send_pulse(remote->ptrail); } }
static ssize_t lirc_write(struct file * file, const char * buf, size_t n, loff_t * pos) { int i; int retval; if(n%sizeof(lirc_t) || (n/sizeof(lirc_t)) > WBUF_LEN) return(-EINVAL); retval = verify_area(VERIFY_READ, buf, n); if (retval) return retval; copy_from_user(tx_buf, buf, n); i = 0; n/=sizeof(lirc_t); init_send(); while (1) { if (i >= n) break; if (tx_buf[i]) send_pulse(tx_buf[i]); i++; if (i >= n) break; if (tx_buf[i]) send_space(tx_buf[i]); i++; } terminate_send(tx_buf[i-1]); return n; }
static int lirc_write(struct inode *node, struct file *file, const char *buf, int n) #endif { #ifdef LIRC_SERIAL_TRANSMITTER int retval,i,count; unsigned long flags; if(n%sizeof(lirc_t)) return(-EINVAL); retval=verify_area(VERIFY_READ,buf,n); if(retval) return(retval); count=n/sizeof(lirc_t); if(count>WBUF_LEN || count%2==0) return(-EINVAL); # ifdef KERNEL_2_1 copy_from_user(wbuf,buf,n); # else memcpy_fromfs(wbuf,buf,n); # endif save_flags(flags);cli(); # ifdef LIRC_SERIAL_IRDEO /* DTR, RTS down */ on(); # endif for(i=0;i<count;i++) { if(i%2) send_space(wbuf[i]); else send_pulse(wbuf[i]); } off(); restore_flags(flags); return(n); #else return(-EBADF); #endif }
int hcsr04_start_continuous_meas(void) { int ret_val = send_pulse(); if (ret_val) oper_mode = CONTINUOUS; return ret_val; }
int main ( int argc, char *argv[] ) { if(argc<4) { printf("Expecting at least four params.\n"); return 1; } wiringPiSetup () ; //setup pins pinMode (0, OUTPUT) ;//LED pinMode (1, OUTPUT) ;//Sender digitalWrite (1, LOW) ; int system_type=0; char unit_type='A'; char onoff=0; int retries=5; system_type=atoi(argv[1]); unit_type=argv[2][0]; if(strcmp(argv[3],"on")==0){ onoff=1; } if(argc>=4){ retries=atoi(argv[4]); } printf("Brennenstuhl remote power socket. \nSystem code: %i \nUnit code: %c\nSwitch %i ",system_type,unit_type,onoff); printf(argv[3]); printf("\nRetries %i\n",retries); //signal sending init int signal[PULSE_CNT]; char cmd[CMD_LEN]; if(encode_cmd(cmd,CMD_LEN,system_type,unit_type,onoff)){ if(encode_signal(signal,PULSE_CNT,cmd,CMD_LEN)){ int j=0; for(j=0;j<retries;j++){ char pulse=START_PULSE; int i=0; for(i=0;i<PULSE_CNT;i++){ send_pulse(signal[i],pulse,1); pulse=pulse*-1+1; } } } } digitalWrite(0,LOW); digitalWrite(1,LOW); return 0 ; }
void send_data(struct ir_remote *remote,ir_code data,int bits,int done) { int i; int all_bits = bit_count(remote); int toggle_bit_mask_bits = bits_set(remote->toggle_bit_mask); ir_code mask; data=reverse(data,bits); if(is_rcmm(remote)) { mask=(ir_code)1<<(all_bits-1-done); if(bits%2 || done%2) { return; } for(i=0;i<bits;i+=2,mask>>=2) { switch(data&3) { case 0: send_pulse(remote->pzero); send_space(remote->szero); break; /* 2 and 1 swapped due to reverse() */ case 2: send_pulse(remote->pone); send_space(remote->sone); break; case 1: send_pulse(remote->ptwo); send_space(remote->stwo); break; case 3: send_pulse(remote->pthree); send_space(remote->sthree); break; } data=data>>2; } return; } else if(is_xmp(remote))
inline void send_pre(struct ir_remote *remote) { if(has_pre(remote)) { send_data(remote,remote->pre_data,remote->pre_data_bits,0); if(remote->pre_p>0 && remote->pre_s>0) { send_pulse(remote->pre_p); send_space(remote->pre_s); } } }
inline void send_post(struct ir_remote *remote) { if(has_post(remote)) { if(remote->post_p>0 && remote->post_s>0) { send_pulse(remote->post_p); send_space(remote->post_s); } send_data(remote,remote->post_data,remote->post_data_bits, remote->pre_data_bits+remote->bits); } }
static ssize_t store_timefor_shoot(struct device *dev, struct device_attribute *attr, const char *buf, size_t count){ unsigned long val; unsigned long flags; int err; spin_lock_irqsave(&lock, flags); val = length; err = send_pulse(val); gpiochip->set(gpiochip, gpio_out_pin, invert); spin_unlock_irqrestore(&lock, flags); return count; }
/* SECTION: Communication with user-space */ static int sir_tx_ir(struct rc_dev *dev, unsigned int *tx_buf, unsigned int count) { unsigned long flags; int i; local_irq_save(flags); for (i = 0; i < count;) { if (tx_buf[i]) send_pulse(tx_buf[i]); i++; if (i >= count) break; if (tx_buf[i]) send_space(tx_buf[i]); i++; } local_irq_restore(flags); return count; }
static inline void send_start_stop() { send_pulse(IR_PULSE_COUNT, IR_START_STOP_COUNT); wait(); }
/** * Sends a pulse from the ping sensor, determines delta, and converts into a distance in cm * @param delta the raw delta value from the ISR * @return distance the distance from the sensor in cm */ unsigned long ping_read(unsigned long delta) { send_pulse(); //send a pulse and calculate delta unsigned long distance = timeToDist(delta); //convert delta to cm return distance; }
void hcsr04_init(){ send_pulse(); //timer_init(); //pin_init(); }
static inline void send_high() { send_pulse(IR_PULSE_COUNT, IR_HIGH_COUNT); wait(); }
inline void send_data(struct ir_remote *remote,ir_code data,int bits,int done) { int i; int all_bits = bit_count(remote); ir_code mask; if(is_rcmm(remote)) { data=reverse(data,bits); mask=1<<(all_bits-1-done); if(bits%2 || done%2) { logprintf(LOG_ERR,"invalid bit number."); return; } for(i=0;i<bits;i+=2,mask>>=2) { switch(data&3) { case 0: send_pulse(remote->pzero); send_space(remote->szero); break; /* 2 and 1 swapped due to reverse() */ case 2: send_pulse(remote->pone); send_space(remote->sone); break; case 1: send_pulse(remote->ptwo); send_space(remote->stwo); break; case 3: send_pulse(remote->pthree); send_space(remote->sthree); break; } data=data>>2; } return; } data=reverse(data,bits); mask=((ir_code) 1)<<(all_bits-1-done); for(i=0;i<bits;i++,mask>>=1) { if(has_toggle_bit_mask(remote) && mask&remote->toggle_bit_mask) { data &= ~((ir_code) 1); if(remote->toggle_bit_mask_state&mask) { data |= (ir_code) 1; } } if(has_toggle_mask(remote) && mask&remote->toggle_mask && remote->toggle_mask_state%2) { data ^= 1; } if(data&1) { if(is_biphase(remote)) { if(mask&remote->rc6_mask) { send_space(2*remote->sone); send_pulse(2*remote->pone); } else { send_space(remote->sone); send_pulse(remote->pone); } } else if(is_space_first(remote)) { send_space(remote->sone); send_pulse(remote->pone); } else { send_pulse(remote->pone); send_space(remote->sone); } } else { if(mask&remote->rc6_mask) { send_pulse(2*remote->pzero); send_space(2*remote->szero); } else if(is_space_first(remote)) { send_space(remote->szero); send_pulse(remote->pzero); } else { send_pulse(remote->pzero); send_space(remote->szero); } } data=data>>1; } }
static inline void send_low() { send_pulse(IR_PULSE_COUNT, IR_LOW_COUNT); wait(); }
int main(void) { GPIO_InitTypeDef GPIO_InitStructure; // Enable Peripheral Clocks /*(1)*/ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); //manual //RCC->APB2ENR |= RCC_APB2ENR_IOPCEN; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //manual //RCC->APB2ENR |= RCC_APB2ENR_IOPAEN; // Configure Pins /*(2)*/ GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 + GPIO_Pin_8 + GPIO_Pin_6; //adding both GPIOs! GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); //manually //GPIOC_CRH |= (1<<1); //GPIOC->CRH |= (1<<1); //GPIOC->CRH = GPIO_CRH_MODE8_1; //button config here GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); // GPIOA_CRL |= (1<<2); //GPIOA->CRL |= (1<<2); //GPIOA->CRL |= GPIO_CRL_CNF0_0; //setup input pulse pin GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); // Configure SysTick Timer /*(3)*/ if (SysTick_Config(SystemCoreClock / 1000)) while (1); int Pressed = 0; int Pressed_Confidence_Level = 0; //Measure button press cofidence int Released_Confidence_Level = 0; //Measure button release confidence while (1) { if(state_num == 0) { //debouncing code for button press, taken from other code //and transferred to this STM32 based project. if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0 ) == 1) { Pressed_Confidence_Level ++; //Increase Pressed Conficence Released_Confidence_Level = 0; //Reset released button confidence since there is a button press if (Pressed_Confidence_Level >500) //Indicator of good button press { if (Pressed == 0) { //PORTB ^= 1 << PINB0; //PORTB ^= 1 << PINB2; send_pulse(); state_num = 1; Pressed = 1; } //Zero it so a new pressed condition can be evaluated Pressed_Confidence_Level = 0; } } else { Released_Confidence_Level ++; //This works just like the pressed Pressed_Confidence_Level = 0; //Reset pressed button confidence since the button is released if (Released_Confidence_Level >500) { Pressed = 0; Released_Confidence_Level = 0; } } } else if(state_num == 1) { in_pulse_len = 0; pulse_state = 1; measure_in_pulse(); } else if(state_num == 2) { judge_pulse(); } else if(state_num == 3) { led_out_setup(); } else if(state_num == 4) { blink_led(); } } }