pick_sequence() //get data from Sequence { //printf("Start pick_sequence() for Sequence=%d\n",Sequence); if (Old_Sequence != Sequence) { printf("New Sequence = %d\n",Sequence); Old_Sequence = Sequence; } while(1) { //printf("pick_sequence: Sequence = %d\n",Sequence); switch (Sequence) { case(0): //printf("Starting blink_none....\n"); blink_none(); break; case(1): //printf("Starting blink_all....\n"); blink_all(); break; case(2): //printf("Starting test_dim....\n"); test_dim(); break; case(3): //printf("Starting time_display....\n"); time_display(); break; case(4): //printf("Looping up_down_4....\n"); up_down_4(); break; case(5): //printf("Starting time_display....\n"); time_display(); break; case(6): //printf("Starting all_on....\n"); all_on(); break; case(7): printf("Starting Random Blink\n"); blink_random(); break; default: //printf("Sorry I don't know what to do with %d\trunning blink_none\n",Sequence); blink_none(); break; } } }
void HEADBAND::start() { int led; int action = random(17); switch (action) { case 0: case 1: // strobe up strobe_up(); break; case 2: case 3: // strobe down strobe_down(); break; case 5: strobe_up(); strobe_down(); break; case 6: case 7: case 8: case 9: led = random(_nr_leds); _leds[led].choose(); break; case 10: glow_up(); break; case 11: glow_down(); break; case 12: glow_all(); break; case 13: blink_all(random(3)); break; case 14: shira_morse(); break; case 15: alternate(random(5) + 5); break; case 16: all_on(); break; } do_sleep(random(15) * 1000); }
int poll_udp() { int port_l,value,rtn,bytes; int addr_len,i; int ntmp,man,exp,sign; float fvalue,fman; char sfloat[5]; short s; char button[20],comment[5]; float pvalue; time_t tt,tloc; char buf[40],tmp[20]; for (i=0;i<100;i++) Buffer[i] = '\0'; //Buffer[0]='\0'; addr_len = sizeof(addr); //format of input is * Port A/B/C and value bytes = recvfrom(sd, Buffer,100 , 0, (struct sockaddr*)&addr, &addr_len); //strcpy(rcvfrom,(char *) inet_ntoa(addr.sin_addr)); //if (!Daemon) printf("main:listen_io24 Data:%d bytes\tfrom %s\t port %c\tdata 0x%X\t buffer[0]=%d or %c\n",bytes,inet_ntoa(addr.sin_addr),buffer[1],value,buffer[0],buffer[0]); if (!Daemon) printf("bytes=%d\t %s\t%d\n",bytes,Buffer,Buffer[bytes-1]); for(i=0;i<bytes;i++) { printf ("%d\t0x%x\t%d\t%c\n",i,Buffer[i],Buffer[i],Buffer[i]); } sscanf(Buffer,"%s %s %f",button,comment,&fvalue); //sscanf(Buffer,"%s%d%s%d%d%f",button,comment,&i,&i,&fvalue); //printf("Button= %s\tComment=%s\tFloat is %f\n",button,comment,fvalue); /* sfloat[0] = Buffer[bytes-4]; sfloat[1] = Buffer[bytes-3]; sfloat[2] = Buffer[bytes-2]; sfloat[3] = Buffer[bytes-1]; sfloat[4] = '\0'; sscanf(sfloat,"%f",&fvalue); sign = sfloat[0] & 0x080; if (sign) { sign = -1; } else { sign = 1; } exp = sfloat[0] & 0x7F; exp = exp << 1; ntmp = sfloat[1] & 0x080; ntmp = ntmp >> 7; exp = exp + ntmp; exp = exp - 127; //127 is the mid point man = sfloat[4] & 0xFF; ntmp = sfloat[3] & 0xFF; man = (man << 8) + ntmp; ntmp = sfloat[2] & 0x8F; ntmp = ntmp << 16; man = man + ntmp; fman = (float)man; fman = 1 + (fman / 10000000); fvalue = sign * (2 ^ exp) * fman; printf("sign = %d\texp = %d\tfman = %f\tfvalue = %f\n",sign,exp,fman,fvalue); //printf("Fvalue = %f\n",fvalue); */ printf ("size of char = %ld\n",sizeof(char)); pvalue = (float)Buffer[bytes-4]; //pppppp printf("pvalue = %f\n",pvalue); /* IEEE floating point 32 standard is: 1 bit for sign 8 bits for exponent, not 7 23 bits for mantissa, not 24 0/1000010 0/1010101 01100110 00101010 Sign Bit Exponent Bits Mantissa Bits */ //printf("Button= %s\tFloat = %f\n",button,fvalue); //Rate = 8; tt = time(&tloc); if (Buffer[5] == 'b') //button { if (Buffer[11] == '1') //button 1 { if (Buffer[bytes-1] == 1) { Button[0] = 1; if (tt - Last_read[0] < 2) { if (!Daemon) printf("Double click button 1\n"); find_insteon_data(0,1); } else { find_insteon_data(0,0); } Last_read[0] = tt; } else { Button[0] = 0; } } if (Buffer[11] == '2') //button 1 { if (Buffer[bytes-1] == 1) { Button[1] = 1; if (tt - Last_read[1] < 2) { if (!Daemon) printf("Double click button 2\n"); } Last_read[1] = tt; find_insteon_data(1,0); if ((Button[0] == 1) && (Button[1] == 1)) { all_on(); } } else { Button[1] = 0; } } if (Buffer[11] == '3') //button 1 { if (Buffer[bytes-1] == 1) { Button[2] = 1; if (tt - Last_read[2] < 2) { if (!Daemon) printf("Double click button 3\n"); } Last_read[2] = tt; find_insteon_data(2,0); if ((Button[0] == 1) && (Button[2] == 1)) { all_off(); } } else { Button[2] = 0; } } if (Buffer[11] == '4') //button 1 { if (Buffer[bytes-1] == 1) { Button[3] = 1; Last_read[3] = tt; } else { Button[3] = 0; } } } if (Buffer[5] == 's') { if (Button[3] == 0) { Slider = Buffer[bytes-1]; Level = Slider; //printf("Setting Level to %d\n",Level); } else { Rate = Buffer[bytes-1]; //printf("Setting Rate to %d\n",Rate); } //printf("Level = %d\tRate = %d\n",Level,Rate); } }