#include "leds.h" #include "leds_matrix.h" #include /* Author: Michael Salathe This program is public domain: you can redistribute it and/or modify it. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ void print_help(){ printf("Usage: leds\n"); } int led_enable(char* message, int off, char* value) { message[off]=message[off] | value[0]; message[off+1]=message[off+1] | value[1]; } int create_checksum(char* message) { int i=0; int sum=0; for(i=0;iifa_name,ifname)==0 &&((struct sockaddr_in *)addrs->ifa_addr)->sin_family == AF_INET ){ source_addr.sin_addr=((struct sockaddr_in *)addrs->ifa_addr)->sin_addr; msgv("Interface:%s",addrs->ifa_name,LINFO,LLEVEL); msgv("IP:%d",source_addr.sin_addr.s_addr,LINFO,LLEVEL); break; } addrs=addrs->ifa_next; } if(source_addr.sin_addr.s_addr==NULL) { msg("No LAN interface found",LNORMAL,LLEVEL); exit(1); } source_addr.sin_family = AF_INET; source_addr.sin_port=htons(SPORT); if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { msg("socket not ready",LNORMAL,LLEVEL); exit(1); } if(bind(fd, (struct sockaddr*)&source_addr, sizeof(source_addr))<0){ msg("unable to bind",LNORMAL,LLEVEL); exit(1); } msg("Socket ready",LINFO,LLEVEL); /* set up destination address */ memset(&addr,0,sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr(DEST); addr.sin_port=htons(DPORT); //start with a rainbow i=0; while(i<3) { i++; for(x=0;x<10;x++) { msgv("x: %d",x,LDEBUG,LLEVEL); for(y=0;y<6;y++) { usleep(50000); msgv("y: %d",y,LDEBUG,LLEVEL); memset(message,0,PLEN); memcpy(message,"\x20\x01\x20",3); set_matrix(message,x,y); msg("sending message",LDEBUG,LLEVEL); create_checksum(message); if (sendto(fd, message, PLEN, 0,(struct sockaddr *) &addr, sizeof(addr)) < 0) { msg("error while sending message",LNORMAL,LLEVEL); exit(1); } } } } //blink all leds i=0; while(i<10) { char *all; init_data(all,PLEN); memcpy(all,"\x20\x01\x20",3); for(x=0;x<10;x++) { for(y=0;y<6;y++) { set_matrix(all,x,y); } } memset(message,0,PLEN); memcpy(message,"\x20\x01\x20",3); create_checksum(message); create_checksum(all); i++; for(x=0;x<10;x++) { usleep(10000); msg("sending message",LDEBUG,LLEVEL); if (sendto(fd, all, PLEN, 0,(struct sockaddr *) &addr, sizeof(addr)) < 0) { msg("error while sending message",LNORMAL,LLEVEL); exit(1); } } for(x=0;x<10;x++) { usleep(10000); msg("sending message",LDEBUG,LLEVEL); if (sendto(fd, message, PLEN, 0,(struct sockaddr *) &addr, sizeof(addr)) < 0) { msg("error while sending message",LNORMAL,LLEVEL); exit(1); } } } //show some text i=0; while(i<1) { i++; char text[]=" UTOPIA "; for(x=0;x