/* 1/2 cycle delay in .5us goes in 0x26 and 0x27 */ void tone(float frequency, float length) { set_beeper_pitch(frequency); beeper_on(); sleep(length); beeper_off(); }
static void play(e_timer a_pin, struct note *a_note) { if (a_note->note || a_note->duration) { beeper_beep(a_pin, a_note->note, a_note->duration); /* beeper_block(a_pin); */ } else { beeper_off(a_pin); } }
void warb() { float freq = warb_low; twitch(); /* Motion accompanies sound */ beeper_on(); for (freq = warb_low; freq < warb_high; freq = freq + 10.0) { set_beeper_pitch(freq); sleep(warb_dur); } beeper_off(); }
void sos(void) { const uint16_t short_s = 120; const uint16_t long_s = short_s * 3; const uint16_t pause_s = short_s; /* symbole */ const uint16_t pause_c = long_s - pause_s; /* character */ const uint16_t pause_w = (short_s * 7) - pause_s; /* word */ size_t n = 0; for(n = 0; n < 3; ++n) { beeper_on(); _delay_ms(short_s); beeper_off(); _delay_ms(pause_s); } _delay_ms(pause_c); for(n = 0; n < 3; ++n) { beeper_on(); _delay_ms(long_s); beeper_off(); _delay_ms(pause_s); } _delay_ms(pause_c); for(n = 0; n < 3; ++n) { beeper_on(); _delay_ms(short_s); beeper_off(); _delay_ms(pause_s); } _delay_ms(pause_w); }
void beeper_on_off(void) { if(GPB.GPBDAT&(0x1<<0)) { beeper_off(); } else { beeper_on(); } }
/* ARGSUSED */ static void kb8042_type4_cmd(struct kb8042 *kb8042, int cmd) { switch (cmd) { case KBD_CMD_BELL: beeper_on(BEEP_TYPE4); break; case KBD_CMD_NOBELL: beeper_off(); break; } }
int beep_fini(void) { BEEP_DEBUG1((CE_CONT, "beep_fini() : start.")); (void) beeper_off(); mutex_enter(&beep_state.mutex); if (beep_state.mode == BEEP_UNINIT) { mutex_exit(&beep_state.mutex); BEEP_DEBUG((CE_WARN, "beep_fini : beep_state already uninitialized.")); return (0); } if (beep_state.queue != NULL) kmem_free(beep_state.queue, sizeof (beep_entry_t) * beep_state.queue_size); beep_state.arg = (void *)NULL; beep_state.mode = BEEP_UNINIT; beep_state.beep_freq = (beep_freq_func_t)NULL; beep_state.beep_on = (beep_on_func_t)NULL; beep_state.beep_off = (beep_off_func_t)NULL; beep_state.timeout_id = 0; beep_state.queue_head = 0; beep_state.queue_tail = 0; beep_state.queue_size = 0; beep_state.queue = (beep_entry_t *)NULL; mutex_exit(&beep_state.mutex); BEEP_DEBUG1((CE_CONT, "beep_fini() : done.")); return (0); }
void get_command() { while (1) { int foo = usb_peek(); if (foo < 0 || buflen >= BUFSIZE) { break; } serial_char = foo; if (serial_char == '\n' || serial_char == '\r' || (serial_char == ':' && comment_mode == false) || serial_count >= (MAX_CMD_SIZE - 1)) { if (!serial_count) { //if empty line comment_mode = false; //for new command return; } cmdbuffer[bufindw][serial_count] = 0; //terminate string if (!comment_mode) { comment_mode = false; //for new command if (strstr(cmdbuffer[bufindw], "N") != NULL) { strchr_pointer = strchr(cmdbuffer[bufindw], 'N'); gcode_N = (strtol(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL, 10)); if (gcode_N != gcode_LastN + 1 && (strstr(cmdbuffer[bufindw], "M110") == NULL)) { printf("Error: Line Number is not Last Line Number+1, Last Line:%lu\n", gcode_LastN); //Serial.println(gcode_N); FlushSerialRequestResend(); serial_count = 0; return; } if (strstr(cmdbuffer[bufindw], "*") != NULL) { unsigned char checksum = 0; unsigned char count = 0; while (cmdbuffer[bufindw][count] != '*') checksum = checksum^cmdbuffer[bufindw][count++]; strchr_pointer = strchr(cmdbuffer[bufindw], '*'); if ((int) (strtod(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL)) != checksum) { printf("Error:checksum mismatch, Last Line:%lu\n", gcode_LastN); FlushSerialRequestResend(); serial_count = 0; return; //if no errors, continue parsing } } else { printf("Error:No Checksum with line number, Last Line:%lu\n", gcode_LastN); FlushSerialRequestResend(); serial_count = 0; return; } gcode_LastN = gcode_N; //if no errors, continue parsing } else // if we don't receive 'N' but still see '*' { if ((strstr(cmdbuffer[bufindw], "*") != NULL)) { printf("Error:No Line Number with checksum, Last Line:%lu\n", gcode_LastN); serial_count = 0; return; } } if ((strstr(cmdbuffer[bufindw], "G") != NULL)) { strchr_pointer = strchr(cmdbuffer[bufindw], 'G'); switch ((int) ((strtod(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL)))) { case 0: case 1: case 2: case 3: printf("ok\n"); break; default: break; } } bufindw = (bufindw + 1) % BUFSIZE; buflen += 1; } serial_count = 0; //clear buffer } else { bool skipmode = false; if (serial_char == ';') { // IN;SP1;PU698,727;PD453,632;PD236,779;PD251,517;PD44,356;PD298,289;PD387,42;PD529,263;PD791,272;PD625,475;PD698,727;PU; if (serial_count == 2 && cmdbuffer[bufindw][0] == 'I' && cmdbuffer[bufindw][1] == 'N') { hgpl_ack(); skipmode = true; } else if (serial_count == 3 && cmdbuffer[bufindw][0] == 'S' && cmdbuffer[bufindw][1] == 'P' && cmdbuffer[bufindw][2] == '1') { hgpl_ack(); skipmode = true; } else if (serial_count >= 2 && cmdbuffer[bufindw][0] == 'P' && (cmdbuffer[bufindw][1] == 'U' || cmdbuffer[bufindw][1] == 'D')) { if (serial_count > 2) { cmdbuffer[bufindw][serial_count] = '\0'; strchr_pointer = strchr(cmdbuffer[bufindw], ','); if (strchr_pointer != NULL) { int y = atoi(strchr_pointer + 1); *strchr_pointer = '\0'; int x = atoi(&cmdbuffer[bufindw][2]); if (cmdbuffer[bufindw][1] == 'U') { stepper_move(x, y); } else { stepper_draw(x, y); } hgpl_ack(); } } else { if (cmdbuffer[bufindw][1] == 'U') { stepper_move(0, 0); beeper_on(1360); msleep(30); beeper_off(); hgpl_ack(); } } skipmode = true; } else { comment_mode = true; } } if (skipmode) { serial_count = 0; skipmode = false; } else { if (!comment_mode) { cmdbuffer[bufindw][serial_count++] = serial_char; } } } } }
void doirq(void) { #if RTCDIS==1 char time[7]; char buf[32], *p[9]; int i; #endif switch(get_intoffset()) { case 5: #if EINT==1 if(get_eintpend(11)) { beeper_off(); #if TIME==1 timer_stop(); #endif clear_eintpend(11); } clear_srcpnd(5); #endif break; case 14: beeper_on_off(); clear_srcpnd(14); break; case 28: #if RTCDIS==1 if(get_subsrcpend(0)) { gets(buf); buf[strlen(buf)-2] = '\0'; p[0] = strtok(buf, " "); for(i=1; p[i-1]!=NULL; i++) { p[i] = strtok(NULL, " "); } #if RTCSET==1 if(strcmp(p[0], "timeset") == 0) { time[0] = atoh(p[1]); time[1] = atoh(p[2]); time[2] = atoh(p[3]); time[3] = atoh(p[4]); time[4] = atoh(p[5]); time[5] = atoh(p[6]); time[6] = atoh(p[7]); rtc_init(time); } #endif if(strcmp(p[0], "alarmset") == 0) { time[0] = atoh(p[1]); time[1] = atoh(p[2]); time[2] = atoh(p[3]); time[3] = atoh(p[4]); time[4] = atoh(p[5]); time[5] = atoh(p[6]); #if ALARM==1 alarm_init(time); #endif } clear_subsrcpend(0); } clear_srcpnd(28); #endif break; case 30: #if ALARM==1 beeper_on(); #if TIME==1 timer_update(); #endif clear_srcpnd(28); #endif break; } clear_intpnd(); }
/* 充放电结束后放置一小时 */ int delay_hour(void) { FRESULT result; FATFS fs; FIL file; DIR DirInf; uint32_t bw; char time_buf[TIME_MAX]; char write_buf[WR_MAX]; char tmp_buf[8]; int sec = 0; int i = 0; int min_count = 0; double vol; result = f_mount(0, &fs); if (result != FR_OK){ printf("FileSystem Mounted Failed (%d)\r\n", result); goto ERROR; } result = f_opendir(&DirInf, "/"); if (result != FR_OK){ printf("Open Root Directory Error (%d)\r\n", result); goto ERROR; } result = f_open(&file, conf->file_name, FA_OPEN_ALWAYS | FA_READ | FA_WRITE); if(result !=FR_OK){ printf("open error, errornu:%d\n\r",result); goto ERROR; } if(f_lseek(&file,file.fsize) != FR_OK){ printf("f_lseek error, errornu:%d\n\r",result); goto ERROR; } beeper_on(); delay_ms(200); beeper_off(); memset(time_buf,0,TIME_MAX); memset(write_buf,0,WR_MAX); printf("\n\r静置开始"); Time_Display(RTC_GetCounter()); printf("\n\r"); bsp_LedOn(4); StartTimer(0, 1000); // Time_Display(RTC_GetCounter()); do{ if(jump) goto JMP; if(CheckTimer(0) ) { StartTimer(0, 1000); sec++; min_count ++; vol = ADC_SAMPLING(); if(min_count >= 60){ min_count = 0; record_time(time_buf); strcat(time_buf,","); strcat(write_buf, time_buf); memset(time_buf,0,TIME_MAX); sprintf(tmp_buf, "%.2f", vol); strcat(write_buf, tmp_buf); strcat(write_buf,",静置\n"); if(i >= 9){ result = f_write(&file,write_buf,sizeof(write_buf),&bw); if(result != FR_OK){ printf("file write faild, errornu:%d\n\r",result); goto ERROR; } memset(write_buf,0,WR_MAX); i = 0; } i++; } } }while(sec < 3600); /* 静置时间(单位:秒) */ JMP: jump = 0; if(i != 0){ result = f_write(&file,write_buf,(15 + TIME_MAX)*i, &bw); if(result != FR_OK){ printf("file write faild, errornu:%d\n\r",result); goto ERROR; } i = 0; } memset(write_buf,0,WR_MAX); printf("静置结束"); Time_Display(RTC_GetCounter()); printf("\n\r"); bsp_LedOff(4); f_close(&file); f_mount(0, NULL); return 0; ERROR: bsp_LedOff(4); f_close(&file); f_mount(0, NULL); return 1; }
/*********************************************** 电池放电 ***********************************************/ int dis_charge(void) { FRESULT result; FATFS fs; FIL file; DIR DirInf; uint32_t bw; char time_buf[TIME_MAX]; char write_buf[WR_MAX]; char tmp_buf[8]; int dis_time = 0; int i = 0; int min_count = 0; double vol; result = f_mount(0, &fs); if (result != FR_OK){ printf("FileSystem Mounted Failed (%d)\r\n", result); goto ERROR; } result = f_opendir(&DirInf, "/"); if (result != FR_OK){ printf("Open Root Directory Error (%d)\r\n", result); goto ERROR; } result = f_open(&file, conf->file_name, FA_OPEN_ALWAYS | FA_READ | FA_WRITE); if(result !=FR_OK){ printf("open error, errornu:%d\n\r",result); goto ERROR; } if(f_lseek(&file,file.fsize) != FR_OK){ printf("f_lseek error, errornu:%d\n\r",result); goto ERROR; } load_con_on(); //打开负载通道LOAD_CON bsp_LedOn(3); beeper_on(); delay_ms(200); beeper_off(); memset(time_buf,0,TIME_MAX); memset(write_buf,0,WR_MAX); StartTimer(0, 1000); // Time_Display(RTC_GetCounter()); // vol = ADC_SAMPLING(); do{ if(jump) goto JMP; if(CheckTimer(0)) { dis_time ++; StartTimer(0, 1000); min_count ++; vol = ADC_SAMPLING(); if(min_count >=60){ min_count = 0; memset(time_buf,0,TIME_MAX); record_time(time_buf); strcat(time_buf,","); strcat(write_buf, time_buf); memset(time_buf,0,TIME_MAX); sprintf(tmp_buf, "%.2f", vol); strcat(write_buf, tmp_buf); strcat(write_buf,",放电\n"); if(i > 9){ result = f_write(&file,write_buf,sizeof(write_buf),&bw); if(result != FR_OK){ printf("file write faild, errornu:%d\n\r",result); goto ERROR; } memset(write_buf,0,WR_MAX); i = 0; } i++; } } }while(dis_charge_timeout(vol)); JMP: record[rec]= dis_time/60; rec++; jump = 0; if(i != 0){ result = f_write(&file,write_buf,35*i, &bw); if(result != FR_OK){ printf("file write faild, errornu:%d\n\r",result); goto ERROR; } i = 0; } memset(write_buf,0,WR_MAX); bsp_LedOff(3); //放电结束 load_con_off(); f_close(&file); f_mount(0, NULL); return 0; //关闭负载通道LOAD_CON ERROR: bsp_LedOff(3); f_close(&file); f_mount(0, NULL); return 1; }
/*********************************************************** 电池充电 **************************************************************/ int charge(void) { FRESULT result; FATFS fs; FIL file; DIR DirInf; uint32_t bw; char time_buf[TIME_MAX]; char write_buf[WR_MAX]; char tmp_buf[8]; int i = 0; int min_count = 0; int adc_value = 0; int adc_tmp = 0; int flag = 0; int times = 0; double charge_time = 0; double vol; /* 挂载文件系统,打开文件,定位文件指针 */ result = f_mount(0, &fs); if (result != FR_OK){ printf("FileSystem Mounted Failed (%d)\r\n", result); goto ERROR; } result = f_opendir(&DirInf, "/"); if (result != FR_OK){ printf("Open Root Directory Error (%d)\r\n", result); goto ERROR; } result = f_open(&file, conf->file_name, FA_OPEN_ALWAYS | FA_READ | FA_WRITE); if(result !=FR_OK){ printf("open error, errornu:%d\n\r",result); goto ERROR; } if(f_lseek(&file,file.fsize) != FR_OK){ printf("f_lseek error, errornu:%d\n\r",result); goto ERROR; } beeper_on(); /* 蜂鸣器提示 */ delay_ms(200); beeper_off(); load_con_off(); /*负载通道关闭 */ charge_con_on(); /*打开CHAR_CON充电通道 */ bsp_LedOn(2); memset(time_buf,0,TIME_MAX); /*清空数组,防止乱码*/ memset(write_buf,0,WR_MAX); StartTimer(0, 100); adc_value = GetADC(); do{ if(jump) goto JMP; if(CheckTimer(0)) { vol = ADC_SAMPLING(); charge_time ++; min_count ++; StartTimer(0, 1000); adc_tmp = GetADC(); if((abs(adc_value - adc_tmp) > 3) || (times != 0)){ if(abs(adc_value - adc_tmp) <= 3){ times = 0; } else{ times++; if(times >= 10){ times = 0; flag = 0; adc_value = adc_tmp; } } } else if((abs(adc_value - adc_tmp) <= 3) && (times == 0)){ flag ++; } if(min_count >= 60){ /* 每隔一分钟采样一次 */ min_count = 0; record_time(time_buf); strcat(time_buf,","); strcat(write_buf, time_buf); memset(time_buf,0,TIME_MAX); sprintf(tmp_buf, "%.2f", vol); strcat(write_buf, tmp_buf); strcat(write_buf,",充电\n"); if(i > 9){ /* 10次采样将数据记录到flash中 */ result = f_write(&file,write_buf,sizeof(write_buf),&bw); if(result != FR_OK){ printf("file write faild, errornu:%d\n\r",result); goto ERROR; } memset(write_buf,0,WR_MAX); i = 0; } i++; } } }while(charge_timeout(charge_time/3600, vol, flag)); /* 充电时间 */ JMP: jump = 0; if(i != 0){ /* 最后将不足10次的数据记录到flash中 */ result = f_write(&file,write_buf,(15 + TIME_MAX)*i, &bw); if(result != FR_OK){ printf("file write faild, errornu:%d\n\r",result); goto ERROR; } i = 0; } memset(write_buf,0,WR_MAX); charge_con_off(); /* 关闭CHAR_CON充电通道 */ bsp_LedOff(2); /* 关闭文件,卸载文件系统 */ f_close(&file); f_mount(0, NULL); return 0; ERROR: /* 错误处理 */ bsp_LedOff(2); f_close(&file); f_mount(0, NULL); return 1; }