void startup_blink() { disp_on(); for (uint8_t i = 0; i < 2; ++i) { my_time.secs = 0xFF; my_time.mins = 0xFF; my_time.hours = 0xFF; disp_time(ENABLE); _delay_ms(500); my_time.secs = 0x00; my_time.mins = 0x00; my_time.hours = 0x00; disp_time(ENABLE); _delay_ms(500); } return; }
void main() { sys_init(); //initialize system while(1) { temp=temp_acquire(); //get temperature data while(temp>temp_thres) //possible fire { buzzer=1; //sound the alarm } buzzer=0; //display stuff on LCD disp_time(); //display time Delay_ms(10000); disp_weather(); //display weather Delay_ms(10000); } }
int main(int argc, const char *argv[]) { int sockfd, len; //socklen_t len; struct sockaddr_in dest; char buf[MAXBUF + 1]; fd_set rfds; struct timeval tv; int retval, maxfd = -1; char *time_str = NULL; time_str = (char *)malloc(sizeof(char)*20); if (argc !=3) { printf("error! : \n\t\t%s IP PORT\n\t such as:\t%s 127.0.0.1 80\n",argv[0], argv[0]); exit(0); } if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { perror("socket"); exit(1); } bzero(&dest, sizeof(dest)); dest.sin_family = AF_INET; dest.sin_port = htons(atoi(argv[2])); if (inet_aton(argv[1], (struct in_addr *)&dest.sin_addr) == 0) { perror(argv[1]); exit(errno); } if (connect(sockfd, (struct sockaddr *)&dest, sizeof(dest)) != 0) { perror("connect"); exit(errno); } printf("\n***********begin to chat*************\n"); while(1) { FD_ZERO(&rfds); FD_SET(0, &rfds); maxfd = 0; FD_SET(sockfd, &rfds); if (sockfd > maxfd) { maxfd = sockfd; } tv.tv_sec = 1; tv.tv_usec = 0; retval = select(maxfd+1, &rfds, NULL, NULL, &tv); if (retval == -1) { printf("Something wrong with the select %s,now it will exit......", strerror(errno)); break; } else { if(retval == 0) { continue; } else { if (FD_ISSET(sockfd, &rfds)) { bzero(buf, MAXBUF+1); len = recv(sockfd, buf, MAXBUF, 0); if (len > 0) { disp_time(time_str); printf("%s\n\tReceive success! You have sent %d bytes\n",buf, len); } else { if (len < 0) { printf("%s\n\tReceive Failed!, the errno is %d, the massege %s\n", buf, errno, strerror(errno)) ; } else { printf("The other side is exit...\n"); } break; } } if (FD_ISSET(0, &rfds)) { bzero(buf, MAXBUF+1); fgets(buf, MAXBUF, stdin); //printf("buf: %d\n",sizeof(buf)); //printf("buf: %d\n",strlen(buf)); if(!strncasecmp(buf, "quit", 4)) { printf("You are requiring to exit"); break; } //buf[strlen(buf)] = '\0';/*FIXME*/ //printf("buf: %d\n",sizeof(buf)); //printf("buf: %d\n",strlen(buf)); len = send(sockfd, buf, strlen(buf)-1, 0); if (len < 0) { printf("%s\n\tSent Failed!, the errno is %d, the massege %s\n", buf, errno, strerror(errno)) ; break; } else { //printf("%s\n\tSent success! You have sent %d bytes\n",buf, len); disp_time(time_str); printf("\tSent success! You have sent %d bytes\n", len); } } } } } close(sockfd); return 0; }
int main() { uint8_t i = 0; uint8_t n = 0; uint8_t pos; char strbuf[64]; char timebuf[16]; uint8_t seconds_last = seconds; uint8_t minutes_last = minutes; unsigned int ch; // FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW); // stdin = stdout = &uart_stream; // always calibrate the internal RC oscillator using external 32Khz crystal do_calibration(); // OSCCAL = 55; rtc_init(); key_init(); extra_init(); ht1632_setup(1); // use ram #ifdef USE_UARTSYNC uart_init(); #else #ifdef USE_V0 uart_init( UART_BAUD_SELECT(9600,F_CPU) ); #else // uart_init( UART_BAUD_SELECT(38400,F_CPU) ); uart_init( UART_BAUD_SELECT(9600,F_CPU) ); #endif #endif sei(); // turn on interrupt handler // strncpy(strbuf, "ready: ", 7); // sprintf(&strbuf[7], "%d", OSCCAL); // ht1632_scrollstr(strbuf, 10, 10); int start = 5; ht1632_putchar(start,1,'L'); ht1632_putchar(start+6,1,'E'); ht1632_putchar(start+12,1,'D'); ht1632_putchar(start+18,1,'I'); delay_ms(5000); set_time(timebuf); disp_time(timebuf); // play tone to indicate we started play_tone(A5, 4); _delay_ms(5); play_tone(A5, 4); _delay_ms(10); while(1) { n = term_recvstr(BUF, BUFSIZE); if(n<0) { term_sendstr(PSTR("error occurred on uart\r\n")); } if(n>0) { MODE = term_check_mode(BUF,n); switch(MODE) { case MODE_TIMESET: mode_timeset(BUF,n); break; case MODE_DRAW: mode_draw(); break; case MODE_INVALID: default: mode_msg(BUF,n); break; } // just to be paranoid stop_led_sync_timer(); // hack to force time display minutes_last = minutes - 1; } if(last_button1state == 1) { demo_life(); // if we come out of demo_life, we show time set_time(timebuf); disp_time(timebuf); } if(seconds_last != seconds || last_buttonstate & BT_PRESS) { seconds_last = seconds; if(minutes_last != minutes) { minutes_last = minutes; set_time(timebuf); disp_time(timebuf); } disp_bindots(); } // fast cycle if(last_buttonstate & BT_HOLD) { while(!(PINC & (1<<BUTTON2))) { minutes++; update_datetime(1); set_time(timebuf); disp_time(timebuf); minutes_last = minutes; _delay_ms(20); } intcount = 0; } // while ((ASSR & (1<<OCR2BUB)) != 0) {} } }
void state_machine() { // Spend most of the time in sleep switch (current_state) { // LEDs off, waiting for button presses case SLEEPING: next_state = SLEEPING; disp_time(DISABLE); //TODO: Go back to sleep sleep_proc(); break; case IDLE: next_state = IDLE; if (timeout_ticks > _LED_TIMEOUT_TICKS) { next_state = SLEEPING; } if (SET || MODE) next_state = WAKE; break; // LEDs on, waiting for timeout case WAKE: next_state = WAKE; enable_pwm(); disp_on(); if (!SET && !MODE) { next_state = IDLE; } if ((debouncer_test(SET_BTN) == LONG_PRESSED) && (debouncer_test(MODE_BTN) == LONG_PRESSED)) { next_state = READY_TO_SET_HOURS; } break; case READY_TO_SET_HOURS: next_state = READY_TO_SET_HOURS; last_set_state = FALSE; flash_mins(); flash_hours(); if (!MODE && !SET) next_state = SET_HOURS; break; // Time set mode, pressing set will increment hours up to 24, then // roll over, pressing mode will switch to minute set mode case SET_HOURS: next_state = SET_HOURS; flash_mins(); if (debouncer_test(MODE_BTN) == DEBOUNCED) { next_state = READY_TO_SET_MINS; } if (debouncer_test(SET_BTN) == DEBOUNCED) { last_set_state = TRUE; } else if (debouncer_test(SET_BTN) == LONG_PRESSED) { next_state = QUICK_HOURS_INC; } if ((last_set_state == TRUE) && !SET) { last_set_state = FALSE; ++my_time.hours; } break; case QUICK_HOURS_INC: next_state = QUICK_HOURS_INC; flash_mins(); if (!SET) next_state = SET_HOURS; if (quick_inc) { quick_inc = FALSE; ++my_time.hours; } break; case READY_TO_SET_MINS: next_state = READY_TO_SET_MINS; last_set_state = FALSE; flash_mins(); flash_hours(); if (!MODE) next_state = SET_MINS; break; // Time set mode, pressing set will increment minutes up to 59, then // roll over, pressing mode will exit time set mode case SET_MINS: next_state = SET_MINS; flash_hours(); if (debouncer_test(MODE_BTN) == DEBOUNCED) { next_state = WAKE; } if (debouncer_test(SET_BTN) == DEBOUNCED) { last_set_state = TRUE; } else if (debouncer_test(SET_BTN) == LONG_PRESSED) { next_state = QUICK_MINS_INC; } if ((last_set_state == TRUE) && !SET) { last_set_state = FALSE; ++my_time.mins; } break; case QUICK_MINS_INC: next_state = QUICK_MINS_INC; flash_hours(); if (!SET) next_state = SET_MINS; if (quick_inc) { quick_inc = FALSE; ++my_time.mins; } break; default: next_state = IDLE; break; } if (current_state != SLEEPING) { test_buttons(); } if (next_state != current_state) { current_state = next_state; } }
int main() { sp_context sp_main_ctx; int ret = 0; InitBoard(); Beep(3); // printf("in function main"); #ifdef TEST_BYTE_ORDER do_test_byte_order(); #endif //看门狗初始化 #ifdef OPEN_WDT InitWatchDog(); #endif //串口设置 sp_init_com(); //测试模式 #ifdef TEST_MODE test_deselect_card(&sp_main_ctx); #endif // 上电后检测POS 机参数 //0、初始化系统存储区 ret = sp_check_context(&sp_main_ctx); if(ret) { SP_WAIT_AND_DISPMSG(SP_KEY_CONFIRM, "检查全局系统参数失败!!按确认键退出程序,ret=%04x", ret); return 1; } //1、初始化全局结构体 ret = sp_init_syspara(&sp_main_ctx); if(ret) { SP_WAIT_AND_DISPMSG(SP_KEY_CONFIRM, "初始化全局系统参数失败!!按确认键退出程序,ret=%04x", ret); return 1; } //1.5、 检查日期是否变化 ret = sp_check_date_change(&sp_main_ctx); if(ret) { SP_WAIT_AND_DISPMSG(SP_KEY_CONFIRM, "检查日期变化失败,ret=%04x", ret); return 1; } //2、初始化流水存储区 ret = sp_init_transdtl(&sp_main_ctx); if(ret) { SP_WAIT_AND_DISPMSG(SP_KEY_CONFIRM, "初始化流水存储区失败,ret=%04x", ret); return 1; } //3、初始化黑名单存储区 ret = sp_init_blacklist(&sp_main_ctx); if(ret) { SP_WAIT_AND_DISPMSG(SP_KEY_CONFIRM, "初始化黑名单存储区失败,ret=%4x", ret); return 1; } //4、初始化psam卡 ret = do_init_sam_card(&sp_main_ctx); if(ret) { SP_WAIT_AND_DISPMSG(SP_KEY_CONFIRM, "初始化psam卡失败!!按确认键退出程序,ret=%04x", ret); return 1; } #ifdef TEST_M1 test_m1_card(&sp_main_ctx); #endif #ifdef TEST_TIME //测试获取时间函数 test_get_time(&sp_main_ctx); disp_time(); #endif //5、签到 ret = do_auth(&sp_main_ctx); if(ret) { SP_WAIT_AND_DISPMSG(SP_KEY_CONFIRM, "签到失败!!按确认键退出程序,ret=%04x", ret); return 1; } //消费菜单 sp_menu_consume(&sp_main_ctx); return 0; }