Ejemplo n.º 1
0
void main()
{
	uchar t=0;
	while(1)
	{
		writetime(t);
		t++;
		delay(500);
	}
}
Ejemplo n.º 2
0
static void print_time (void)
{
  time_t secs;
  
  secs = time (NULL);
  writestr (cur_slot, "Current time: ");
  writestr (cur_slot, ctime (&secs));
  writestr (cur_slot, "Time on: ");
  writetime (cur_slot, secs - cur_slot->login_time);
  writech (cur_slot, '\n');
}
Ejemplo n.º 3
0
/* $begin get_requesthdrs */
void get_requesthdrs(rio_t *rp) 
{
    char buf[MAXLINE];

    Rio_readlineb(rp, buf, MAXLINE);
    writetime();  /* write access time in log file */
    printf("%s", buf);
    while(strcmp(buf, "\r\n")) 
    {
	Rio_readlineb(rp, buf, MAXLINE);
	writelog(buf);
	printf("%s", buf);
    }
    return;
}
Ejemplo n.º 4
0
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Function to set time offset in minutes and hours
void set_hrs_mins(){
    
    
    if (digitalRead(button_set_mins_in) == HIGH){ //check minutes button
        offset_m = offset_m + 60000; //add one minute to offset
        
        beep();
        Serial.print("Increment minutes");
        Serial.print(offset_m);
        Serial.print("\n");
        delay(200);
    }
    if (digitalRead(button_set_hrs_in) == HIGH){ //check hours button
        offset_m = offset_m + 60*60000; //add 60*1 minutes to offset the time
        
        beep();
        Serial.print("Increment hours");
        Serial.print(offset_m);
        Serial.print("\n");
        delay(200);
    }
    
    beepOK = 0;
    gettime();
    
    //Now make the display blink while setting the time.
    
    if((millis_left%1000) > 500){ //0.5 seconds lit up
        writetime();
        matrix.drawColon(true);
        matrix.writeDisplay();
    }
    else{
        matrix.drawColon(false); //0.5 seconds lit off
        matrix.writeDigitRaw(0,B00000000); //" "
        matrix.writeDigitRaw(1,B00000000); //" "
        matrix.writeDigitRaw(3,B00000000); //" "
        matrix.writeDigitRaw(4,B00000000); //" "
        matrix.writeDisplay();
    }
    
    
}
Ejemplo n.º 5
0
/* $begin post_requesthdrs */
void post_requesthdrs(rio_t *rp,int *length) 
{
    char buf[MAXLINE];
    char *p;

    Rio_readlineb(rp, buf, MAXLINE);
    writetime();  /* write access time in log file */
    while(strcmp(buf, "\r\n")) 
    {
	Rio_readlineb(rp, buf, MAXLINE);
	if(strncasecmp(buf,"Content-Length:",15)==0)
	{
		p=&buf[15];	
		p+=strspn(p," \t");
		*length=atol(p);
	}
	writelog(buf);
	printf("%s", buf);
    }
    return;
}
Ejemplo n.º 6
0
static int32_t
conswrite(Chan *c, void *va, int32_t n, int64_t off)
{
	Proc *up = externup();
	char buf[256];
	int32_t l, bp;
	char *a;
	Mach *mp;
	int i;
	uint32_t offset;
	Cmdbuf *cb;
	Cmdtab *ct;
	a = va;
	offset = off;
	extern int printallsyscalls;

	switch((uint32_t)c->qid.path){
	case Qcons:
		/*
		 * Can't page fault in putstrn, so copy the data locally.
		 */
		l = n;
		while(l > 0){
			bp = l;
			if(bp > sizeof buf)
				bp = sizeof buf;
			memmove(buf, a, bp);
			putstrn0(buf, bp, 1);
			a += bp;
			l -= bp;
		}
		break;

	case Qconsctl:
		print("consctl\n");
		if(n >= sizeof(buf))
			n = sizeof(buf)-1;
		strncpy(buf, a, n);
		buf[n] = 0;
		for(a = buf; a;){
			if(strncmp(a, "sys", 3) == 0) {
				printallsyscalls = ! printallsyscalls;
				print("%sracing syscalls\n", printallsyscalls ? "T" : "Not t");
			}
			if(a = strchr(a, ' '))
				a++;
		}
		break;

	case Qtime:
		if(!iseve())
			error(Eperm);
		return writetime(a, n);

	case Qbintime:
		if(!iseve())
			error(Eperm);
		return writebintime(a, n);

	case Qhostowner:
		return hostownerwrite(a, n);

	case Qhostdomain:
		return hostdomainwrite(a, n);

	case Quser:
		return userwrite(a, n);

	case Qnull:
		break;

	case Qreboot:
		if(!iseve())
			error(Eperm);
		cb = parsecmd(a, n);

		if(waserror()) {
			free(cb);
			nexterror();
		}
		ct = lookupcmd(cb, rebootmsg, nelem(rebootmsg));
		switch(ct->index) {
		case CMhalt:
			reboot(nil, 0, 0);
			break;
		case CMreboot:
			rebootcmd(cb->nf-1, cb->f+1);
			break;
		case CMpanic:
			*(volatile uint32_t*)0=0;
			panic("/dev/reboot");
		}
		poperror();
		free(cb);
		break;

	case Qsysstat:
		for(i = 0; i < MACHMAX; i++)
			if((mp = sys->machptr[i]) != nil && mp->online){
				mp = sys->machptr[i];
				mp->cs = 0;
				mp->intr = 0;
				mp->syscall = 0;
				mp->pfault = 0;
				mp->tlbfault = 0;	/* not updated */
				mp->tlbpurge = 0;	/* # mmuflushtlb */
			}
		break;

	case Qswap:
		if(n >= sizeof buf)
			error(Egreg);
		memmove(buf, va, n);	/* so we can NUL-terminate */
		buf[n] = 0;
		if(!iseve())
			error(Eperm);
		if(buf[0]<'0' || '9'<buf[0])
			error(Ebadarg);
		if(strncmp(buf, "start", 5) == 0){
			print("request to start pager ignored\n");
			break;
		}
		break;

	case Qsysname:
		if(offset != 0)
			error(Ebadarg);
		if(n <= 0 || n >= sizeof buf)
			error(Ebadarg);
		strncpy(buf, a, n);
		buf[n] = 0;
		if(buf[n-1] == '\n')
			buf[n-1] = 0;
		kstrdup(&sysname, buf);
		break;

	case Qdebug:
		if(n >= sizeof(buf))
			n = sizeof(buf)-1;
		strncpy(buf, a, n);
		buf[n] = 0;
		if(n > 0 && buf[n-1] == '\n')
			buf[n-1] = 0;
		error(Ebadctl);
		break;

	case Qsyscall:
		if(n >= sizeof(buf))
			n = sizeof(buf)-1;
		strncpy(buf, a, n);
		buf[n] = 0;
		if(n > 0 && buf[n-1] == '\n')
			buf[n-1] = 0;
		// Doing strncmp right is just painful and overkill here.
		if (buf[0] == 'o') {
			if (buf[1] == 'n' && buf[2] == 0) { 
				printallsyscalls = 1;
				break;
			}
			if (buf[1] == 'f' && buf[2] == 'f' && buf[3] == 0) {
				printallsyscalls = 0;
				break;
			}
		}
		error("#c/syscall: can only write on or off");
		break;
	default:
		print("conswrite: %#llx\n", c->qid.path);
		error(Egreg);
	}
	return n;
}
Ejemplo n.º 7
0
static long
conswrite(Chan *c, void *va, long n, vlong off)
{
	char buf[256];
	long l, bp;
	char *a;
	Mach *mp;
	int id, fd;
	Chan *swc;
	ulong offset;
	Cmdbuf *cb;
	Cmdtab *ct;

	a = va;
	offset = off;

	switch((ulong)c->qid.path){
	case Qcons:
		/*
		 * Can't page fault in putstrn, so copy the data locally.
		 */
		l = n;
		while(l > 0){
			bp = l;
			if(bp > sizeof buf)
				bp = sizeof buf;
			memmove(buf, a, bp);
			putstrn0(buf, bp, 1);
			a += bp;
			l -= bp;
		}
		break;

	case Qconsctl:
		error(Egreg);

	case Qtime:
		if(!iseve())
			error(Eperm);
		return writetime(a, n);

	case Qbintime:
		if(!iseve())
			error(Eperm);
		return writebintime(a, n);

	case Qhostowner:
		return hostownerwrite(a, n);

	case Qhostdomain:
		return hostdomainwrite(a, n);

	case Quser:
		return userwrite(a, n);

	case Qnull:
		break;

	case Qconfig:
		error(Eperm);
		break;

	case Qreboot:
		if(!iseve())
			error(Eperm);
		cb = parsecmd(a, n);

		if(waserror()) {
			free(cb);
			nexterror();
		}
		ct = lookupcmd(cb, rebootmsg, nelem(rebootmsg));
		switch(ct->index) {
		case CMhalt:
			reboot(nil, 0, 0);
			break;
		case CMreboot:
			rebootcmd(cb->nf-1, cb->f+1);
			break;
		case CMpanic:
			*(ulong*)0=0;
			panic("/dev/reboot");
		case CMrdb:
			if(consdebug == nil)
				consdebug = rdb;
			consdebug();
			break;
		}
		poperror();
		free(cb);
		break;

	case Qsysstat:
		for(id = 0; id < 32; id++) {
			if(active.machs & (1<<id)) {
				mp = MACHP(id);
				mp->cs = 0;
				mp->intr = 0;
				mp->syscall = 0;
				mp->pfault = 0;
				mp->tlbfault = 0;
				mp->tlbpurge = 0;
			}
		}
		break;

	case Qswap:
		if(n >= sizeof buf)
			error(Egreg);
		memmove(buf, va, n);	/* so we can NUL-terminate */
		buf[n] = 0;
		/* start a pager if not already started */
		if(strncmp(buf, "start", 5) == 0){
			kickpager();
			break;
		}
		if(!iseve())
			error(Eperm);
		if(buf[0]<'0' || '9'<buf[0])
			error(Ebadarg);
		fd = strtoul(buf, 0, 0);
		swc = fdtochan(fd, -1, 1, 1);
		setswapchan(swc);
		break;

	case Qsysname:
		if(offset != 0)
			error(Ebadarg);
		if(n <= 0 || n >= sizeof buf)
			error(Ebadarg);
		strncpy(buf, a, n);
		buf[n] = 0;
		if(buf[n-1] == '\n')
			buf[n-1] = 0;
		kstrdup(&sysname, buf);
		break;
	
	case Qmordor:
		error("one does not simply write into mordor");
		return 0;

	default:
		print("conswrite: %#llux\n", c->qid.path);
		error(Egreg);
	}
	return n;
}
Ejemplo n.º 8
0
static long conswrite(struct chan *c, void *va, long n, int64_t off)
{
    ERRSTACK(1);
    char buf[256], ch;
    long l, bp;
    char *a;
    //Mach *mp;
    int id, fd;
    struct chan *swc;
    uint32_t offset;
    struct cmdbuf *cb;
    struct cmdtab *ct;
    int x;
    uint64_t rip, rsp, cr3, flags, vcpu;
    int ret;
    struct vmctl vmctl;

    a = va;
    offset = off;

    switch ((uint32_t) c->qid.path) {
    case Qcons:
        /*
         * Can't page fault in putstrn, so copy the data locally.
         */
        l = n;
        while (l > 0) {
            bp = l;
            if (bp > sizeof buf)
                bp = sizeof buf;
            memmove(buf, a, bp);
            putstrn0(buf, bp, 1);
            a += bp;
            l -= bp;
        }
        break;

    case Qconsctl:
        if (n >= sizeof(buf))
            n = sizeof(buf) - 1;
        strncpy(buf, a, n);
        buf[n] = 0;
        for (a = buf; a;) {
            if (strncmp(a, "rawon", 5) == 0) {
                kbd.raw = 1;
                /* clumsy hack - wake up reader */
                ch = 0;
                qwrite(kbdq, &ch, 1);
            } else if (strncmp(a, "rawoff", 6) == 0) {
                kbd.raw = 0;
            } else if (strncmp(a, "ctlpon", 6) == 0) {
                kbd.ctlpoff = 0;
            } else if (strncmp(a, "ctlpoff", 7) == 0) {
                kbd.ctlpoff = 1;
            }
            if ((a = strchr(a, ' ')) != NULL)
                a++;
        }
        break;

    case Qtime:
        if (!iseve())
            error(EPERM, "Hodie Natus Est Radici Frater");
        return writetime(a, n);

    case Qbintime:
        if (!iseve())
            error(EPERM, ERROR_FIXME);
        return writebintime(a, n);

#if 0
    case Qhostowner:
        return hostownerwrite(a, n);

    case Qhostdomain:
        return hostdomainwrite(a, n);

    case Quser:
        return userwrite(a, n);
#endif

    case Qnull:
        break;

    case Qconfig:
        error(EPERM, "Cannot write to config QID");
        break;

    case Qsysctl:
        //if (!iseve()) error(EPERM, ERROR_FIXME);
        cb = parsecmd(a, n);
        if (cb->nf > 1)
            printd("cons sysctl cmd %s\n", cb->f[0]);

    case Qreboot:
        if (!iseve())
            error(EPERM, ERROR_FIXME);
        cb = parsecmd(a, n);

        if (waserror()) {
            kfree(cb);
            nexterror();
        }
        ct = lookupcmd(cb, rebootmsg, ARRAY_SIZE(rebootmsg));
        switch (ct->index) {
        case CMhalt:
            cpu_halt();
            break;
        case CMbroken:
            keepbroken = 1;
            break;
        case CMnobroken:
            keepbroken = 0;
            break;
        case CMreboot:
            reboot();
            break;
        case CMpanic:
            *(uint32_t *) 0 = 0;
            panic("/dev/reboot");
        }
        poperror();
        kfree(cb);
        break;

#if 0
    case Qsysstat:
        for (id = 0; id < 32; id++) {
            if (active.machs & (1 << id)) {
                mp = MACHP(id);
                mp->cs = 0;
                mp->intr = 0;
                mp->syscall = 0;
                mp->pfault = 0;
                mp->tlbfault = 0;
                mp->tlbpurge = 0;
            }
        }
        break;

    case Qswap:
        if (n >= sizeof buf)
            error(EINVAL, "n is bigger than sizeof buf for Qswap");
        memmove(buf, va, n);	/* so we can NUL-terminate */
        buf[n] = 0;
        /* start a pager if not already started */
        if (strncmp(buf, "start", 5) == 0) {
            kickpager();
            break;
        }
        if (!iseve())
            error(EPERM, ERROR_FIXME);
        if (buf[0] < '0' || '9' < buf[0])
            error(EINVAL, ERROR_FIXME);
        fd = strtoul(buf, 0, 0);
        swc = fdtochan(fd, -1, 1, 1);
        setswapchan(swc);
        break;
#endif

    case Qsysname:
        if (offset != 0)
            error(EINVAL, ERROR_FIXME);
        if (n <= 0 || n >= sizeof buf)
            error(EINVAL, ERROR_FIXME);
        strncpy(buf, a, n);
        buf[n] = 0;
        if (buf[n - 1] == '\n')
            buf[n - 1] = 0;
        kstrdup(&sysname, buf);
        break;

    default:
        printd("conswrite: %#llux\n", c->qid.path);
        error(EINVAL, "bad QID in conswrite");
    }
    return n;
}
Ejemplo n.º 9
0
void loop() {
    
    
    //Write time
    Serial.print(" --- Time \n");
    writetime();
    delay(30);
    
    
    //Draw dots
    drawDots();
    delay(30);
    
    
    //Check whether to go into settings mode
    if(digitalRead(button_settings_in) == HIGH){
        beep();
        Serial.print("In settings \n");
        settings();
    }
    delay(30);
    
    
    //Now check if we have alarm acivated!
    gettime();
    //Serial.print("Before: Alarm = ");
    //Serial.print(alarm);
    //Serial.print("\n");
    //delay(30);
    if( time == alarm_1_time && alarm){
        //alarm = 0;
        alarm_beep();  //Play the beep
        Serial.print("NO MORE BEEP \n");
        delay(500);
    }
    else if(time != alarm_1_time) alarm = 1;
    //Serial.print("After: Alarm = ");
    //Serial.print(alarm);
    //Serial.print("\n");
    //Serial.print("NO ALARM \n");
    //delay(60);
    
    //Check brightness
    if (digitalRead(button_set_mins_in) == HIGH){ //check minutes button
        brightness++; //increase brightness
        beep();
        if( brightness > 15 ) { brightness = 15; delay(beep_delay); beep(); delay(beep_delay); beep(); }
        matrix.setBrightness(brightness);
        Serial.print("Brightness level changed:");
        Serial.print(brightness);
        Serial.print("\n");
        delay(150);
    }
    if (digitalRead(button_set_hrs_in) == HIGH){ //check hours button
        brightness--; //decrease brightness
        beep();
        if( brightness < 0 ) { brightness = 0; delay(beep_delay); beep(); delay(beep_delay); beep(); }
        matrix.setBrightness(brightness);
        Serial.print("Brightness level changed:");
        Serial.print(brightness);
        Serial.print("\n");
        delay(150);
    }
    
}
Ejemplo n.º 10
0
void alarm_beep(){
    int count0 = 0;
    do{
        count0++;
        int count = 0; //cut the beep at some point
        writetime();
        drawDots();
        delay(20);
        digitalWrite(led_RGB_1, HIGH);
        digitalWrite(led_RGB_2, HIGH);
        
        if( count0%3 == 0 ){
            print_sad(); //Print a sad smile
            delay(300);
        }
        
        //Serial.print("In alarm - beep \n");
        beep();
        delay(100);
        beep();
        delay(100);
        beep();
        delay(150);
        
        
        
        if (digitalRead(alarm_off_1) == HIGH){
            //Serial.print("One 1 end touched :) \n");
            digitalWrite(led_RGB_1, LOW);
            print_smile();
            delay(500);
            do{
                
                //Now beep less
                if(count%5 == 0) {
                    beep();
                }
                count++;
                
                writetime();
                drawDots();
                
                if (digitalRead(alarm_off_2) == HIGH){
                    //Alarm off
                    //Serial.print("Other 2 end touched, alarm = 0 \n");
                    digitalWrite(led_RGB_2, LOW);
                    alarm = 0;
                    break;
                }
                //Serial.print("In while loop 1! \n");
                delay(100);
            }
            while(digitalRead(alarm_wire) == LOW || alarm == 0);
            delay(100);
            //Serial.print("While loop exited, now exit alarm \n");
            
        }
        else if (digitalRead(alarm_off_2) == HIGH){
            //Serial.print("One 2 end touched :) \n");
            digitalWrite(led_RGB_2, LOW);
            print_smile();
            delay(500);
            do{
                
                //Now beep less
                if(count%5 == 0) {
                    beep();
                }
                count++;
                
                writetime();
                drawDots();
                
                if (digitalRead(alarm_off_1) == HIGH){
                    //Alarm off
                    //Serial.print("Other 1 end touched, alarm = 0 \n");
                    digitalWrite(led_RGB_1, LOW);
                    alarm = 0;
                    break;
                }
                Serial.print("In while loop 2! \n");
                delay(100);
            }
            while(digitalRead(alarm_wire) == LOW || alarm == 0);
            delay(100);
            //Serial.print("While loop exited, now exit alarm \n");
            //exit;
        }
        
        
        
    }
    while( alarm != 0 );
    print_smile(); //Show a smile
    delay(700);
    print_alarm_off();
    
    //Serial.print("I said!!!!! Exit alarm loop: Alarm = ");
    //Serial.print(alarm);
    //Serial.print("\n");
}