Exemple #1
0
/**
 * \brief handle incoming echo request
 *
 * \param the incoming NewDataEvent
 */
void uip_icmp6_echo_request_input(NewDataEvent * e)
{
	struct uip_icmp_hdr * icmp_hdr;
	struct uip_tcpip_hdr * tcpip_hdr;
	Neighbor_AO * neighbor;
	static QEvent const pr_sig = { PACKET_RECEIVED_SIG};
	static QEvent const ps_sig = { PACKET_SENT_SIG};
	tcpip_hdr = ( struct uip_tcpip_hdr *) &e->buf[UIP_LLH_LEN];
	icmp_hdr = (struct uip_icmp_hdr *)&e->buf[uip_l2_l3_hdr_len];
	
	neighbor = uip_nd6_nbrcache_lookup(&tcpip_hdr->srcipaddr);
	if (NULL != neighbor)
		QActive_postFIFO((QActive *)neighbor, &pr_sig);
	
	switch_eth_addr(e);
	
	memcpy(&tcpip_hdr->destipaddr, &tcpip_hdr->srcipaddr, sizeof(uip_ipaddr_t));
	memcpy(&tcpip_hdr->srcipaddr, &uip_hostaddr, sizeof(uip_ipaddr_t));
	icmp_hdr->type = ICMP6_ECHO_REPLY;
  icmp_hdr->icode = 0;
  icmp_hdr->icmpchksum = 0;
  icmp_hdr->icmpchksum = ~upper_layer_chksum6((unsigned char *) &e->buf);
	e->super.sig = SEND_DATA_SIG;
	QF_publish((QEvent *) e);
	QActive_postFIFO((QActive *)neighbor, &ps_sig);
}
Exemple #2
0
/*..........................................................................*/
void GPIOPortA_IRQHandler(void) {
    QK_ISR_ENTRY();                      /* infrom QK about entering an ISR */

    QActive_postFIFO(AO_Table, Q_NEW(QEvent, MAX_PUB_SIG));  /* for testing */

    QK_ISR_EXIT();                        /* infrom QK about exiting an ISR */
}
Exemple #3
0
/*..........................................................................*/
void QF_tick(void) {                                          /* see NOTE01 */
    QTimeEvt *t;
    QF_INT_LOCK_KEY_

    QF_INT_LOCK_();

    QS_BEGIN_NOLOCK_(QS_QF_TICK, (void *)0, (void *)0)
        QS_TEC_(++QS_tickCtr_);                         /* the tick counter */
    QS_END_NOLOCK_()

    t = QF_timeEvtListHead_;
    while (t != (QTimeEvt *)0) {
        --t->ctr;
        if (t->ctr == (QTimeEvtCtr)0) {     /* is time evt about to expire? */
            if (t->interval != (QTimeEvtCtr)0) { /* is it periodic timeout? */
                t->ctr = t->interval;               /* rearm the time event */
            }
            else { /* one-shot timeout, disarm by removing it from the list */
                if (t == QF_timeEvtListHead_) {
                    QF_timeEvtListHead_ = t->next;
                }
                else {
                    if (t->next != (QTimeEvt *)0) {  /* not the last event? */
                        t->next->prev = t->prev;
                    }
                    t->prev->next = t->next;
                }
                t->prev = (QTimeEvt *)0;         /* mark the event disarmed */

                QS_BEGIN_NOLOCK_(QS_QF_TIMEEVT_AUTO_DISARM, QS_teObj_, t)
                    QS_OBJ_(t);                   /* this time event object */
                    QS_OBJ_(t->act);                   /* the active object */
                QS_END_NOLOCK_()
            }

            QS_BEGIN_NOLOCK_(QS_QF_TIMEEVT_POST, QS_teObj_, t)
                QS_TIME_();                                    /* timestamp */
                QS_OBJ_(t);                        /* the time event object */
                QS_SIG_(t->super.sig);         /* signal of this time event */
                QS_OBJ_(t->act);                       /* the active object */
            QS_END_NOLOCK_()

            QF_INT_UNLOCK_();/* unlock interrupts before calling QF service */

               /* postFIFO() asserts internally that the event was accepted */
            QActive_postFIFO(t->act, (QEvent *)t);
        }
        else {
            static uint8_t volatile dummy;
            QF_INT_UNLOCK_();
            dummy = (uint8_t)0;   /* execute a few instructions, see NOTE02 */
        }

        QF_INT_LOCK_();        /* lock interrupts again to advance the link */
        t = t->next;
    }
Exemple #4
0
/**
 * \brief Reply incoming ICMPv6 Echo Request with an Echo Reply
 * 
 * \param incoming NewDataEvent
 */
void uip_icmp6_echo_reply_input(NewDataEvent * e)
{
	Neighbor_AO * neighbor;
	struct uip_icmpip_hdr * icmpip_hdr;
	static QEvent const icmpr_sig = { ICMPV6_ECHO_REPLY_SIG};
	icmpip_hdr = ( struct uip_icmpip_hdr *) &e->buf[UIP_LLH_LEN];
	
	neighbor = uip_nd6_nbrcache_lookup(&icmpip_hdr->srcipaddr);
	if (NULL != neighbor)
		QActive_postFIFO((QActive *)neighbor, &icmpr_sig);
}
Exemple #5
0
/* @(/2/0/9/1/2/2) .........................................................*/
QState CoffeeAO_startBrewingNow(CoffeeAO * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /* @(/2/0/9/1/2/2) */
        case Q_ENTRY_SIG: {
            QF_INT_ENABLE();
            printf("Starting to brew\n %i", l_CoffeeAO.i++);
            QActive_postFIFO((QActive *)&l_CoffeeAO, Q_NEW(QEvent, BREW_SIG));
            QActive_postFIFO((QActive *)&l_CoffeeAO, Q_NEW(QEvent, GO_BACK_SIG));
            QF_INT_DISABLE();

            status_ = Q_HANDLED();
            break;
        }
        default: {
            status_ = Q_SUPER(&CoffeeAO_submenu);
            break;
        }
    }
    return status_;
}
Exemple #6
0
/* @(/2/0/9/1/2/1) .........................................................*/
QState CoffeeAO_setBrewStrength(CoffeeAO * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /* @(/2/0/9/1/2/1) */
        case Q_ENTRY_SIG: {
            lcd_clear();
            set_cursor(0, 0);
            lcd_print("Use AD-Wheel");
            set_cursor(0, 1);
            lcd_print("Use int0 to save");
            printf("Changing brew strength...\n");
            status_ = Q_HANDLED();
            break;
        }
        /* @(/2/0/9/1/2/1) */
        case Q_EXIT_SIG: {
            printf("saved brew strength: %u\n", l_CoffeeAO.current_brew_strength);
            status_ = Q_HANDLED();
            break;
        }
        /* @(/2/0/9/1/2/1/0) */
        case ADWHEEL_SIG: {
            const int led_count = 8;
            int i = 0;
            l_CoffeeAO.current_brew_strength = ((AdEvt*)e)->val * led_count / 1024;
            for(i = 0; i < led_count; i++) {
                if (i <= l_CoffeeAO.current_brew_strength) {
                    LED_On(i);
                } else {
                    LED_Off(i);
                }
            }

            status_ = Q_HANDLED();
            break;
        }
        /* @(/2/0/9/1/2/1/1) */
        case INT_SIG: {
            QF_INT_ENABLE();
            QActive_postFIFO((QActive *)&l_CoffeeAO, Q_NEW(QEvent, GO_BACK_SIG));
            QF_INT_DISABLE();
            status_ = Q_HANDLED();
            break;
        }
        default: {
            status_ = Q_SUPER(&CoffeeAO_submenu);
            break;
        }
    }
    return status_;
}
Exemple #7
0
/*..........................................................................*/
void BSP_onKeyboardInput(uint8_t key) {
    switch (key) {
        case 0x6f: {                                  /* 'o': Alarm on event? */
            QActive_postFIFO((QActive *)&l_alarmClock,
                             Q_NEW(QEvent, ALARM_ON_SIG));
            break;
        }
        case 0x66: {                                 /* 'f': Alarm off event? */
            QActive_postFIFO((QActive *)&l_alarmClock,
                             Q_NEW(QEvent, ALARM_OFF_SIG));
            break;
        }
        case  0x32:                                                     /* '1' */
        case  0x33:                                                     /* '2' */
        case  0x34:                                                     /* '3' */
        case  0x35:                                                     /* '4' */
        case  0x36:                                                     /* '5' */
        case  0x37:                                                     /* '6' */
        case  0x38:                                                     /* '7' */
        case  0x39:                                                     /* '8' */
        case  0x31:{                                                   /* '9' */
            SetEvt *e = Q_NEW(SetEvt, ALARM_SET_SIG);
            e->digit = (uint8_t)(key - 1);
            QActive_postFIFO((QActive *)&l_alarmClock, (QEvent *)e);
            break;
        }
        case 0x4f: {                                                   /* '0' */
            SetEvt *e = Q_NEW(SetEvt, ALARM_SET_SIG);
            e->digit = 0;
            QActive_postFIFO((QActive *)&l_alarmClock, (QEvent *)e);
            break;
        }
        case 0x61: {                                 /* 'a': Clock 12H event? */
            QActive_postFIFO((QActive *)&l_alarmClock,
                             Q_NEW(QEvent, CLOCK_12H_SIG));
            break;
        }
        case 0x62: {                                 /* 'b': Clock 24H event? */
            QActive_postFIFO((QActive *)&l_alarmClock,
                             Q_NEW(QEvent, CLOCK_24H_SIG));
            break;
        }
        case 0x1b: {                                         /* ESC pressed? */
            QActive_postFIFO((QActive *)&l_alarmClock,
                             Q_NEW(QEvent, TERMINATE_SIG));
            break;
        }
    }
}
Exemple #8
0
/* @(/2/0/9/1/2/8) .........................................................*/
QState CoffeeAO_set_clock_m2(CoffeeAO * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /* @(/2/0/9/1/2/8) */
        case Q_ENTRY_SIG: {
            lcd_clear();
            status_ = Q_HANDLED();
            break;
        }
        /* @(/2/0/9/1/2/8/0) */
        case ADWHEEL_SIG: {
            char clock_message[20];
            int value = ((AdEvt*)e)->val * 10 / 1024;
            HourAndMinute* ham = &l_CoffeeAO.alarm.current_time;
            ham->minutes = (ham->minutes / 10) * 10 + value;
            sprintf(clock_message, "%02u:%02u", ham->hours, ham->minutes);

            set_cursor(0, 0);
            lcd_print(clock_message);
            set_cursor(4, 1);
            lcd_print("^");
            status_ = Q_HANDLED();
            break;
        }
        /* @(/2/0/9/1/2/8/1) */
        case INT_SIG: {
            RtcEvt* rtc_evt = Q_NEW(RtcEvt, TIME_SET_SIG);
            rtc_evt->rtc.hours = l_CoffeeAO.alarm.current_time.hours;
            rtc_evt->rtc.minutes = l_CoffeeAO.alarm.current_time.minutes;

            Alarm_dispatch((QFsm *)&l_CoffeeAO.alarm, (QEvt *) rtc_evt);
            QF_INT_ENABLE();
            QActive_postFIFO((QActive *)&l_CoffeeAO, Q_NEW(QEvent, GO_BACK_SIG));
            QF_INT_DISABLE();

            status_ = Q_HANDLED();
            break;
        }
        default: {
            status_ = Q_SUPER(&CoffeeAO_submenu);
            break;
        }
    }
    return status_;
}
Exemple #9
0
/* @(/2/0/9/1/2/11) ........................................................*/
QState CoffeeAO_set_brew_m2(CoffeeAO * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /* @(/2/0/9/1/2/11) */
        case Q_ENTRY_SIG: {
            lcd_clear();
            status_ = Q_HANDLED();
            break;
        }
        /* @(/2/0/9/1/2/11/0) */
        case ADWHEEL_SIG: {
            char clock_message[20];
            int value = ((AdEvt*)e)->val * 10 / 1024;
            HourAndMinute* ham = &l_CoffeeAO.alarm.alarm_time;
            ham->minutes = MIN((ham->minutes / 10) * 10 + value, 59);
            sprintf(clock_message, "%02u:%02u", ham->hours, ham->minutes);

            set_cursor(0, 0);
            lcd_print(clock_message);
            set_cursor(4, 1);
            lcd_print("^");
            status_ = Q_HANDLED();
            break;
        }
        /* @(/2/0/9/1/2/11/1) */
        case INT_SIG: {
            QF_INT_ENABLE();
            QActive_postFIFO((QActive *)&l_CoffeeAO, Q_NEW(QEvent, GO_BACK_SIG));
            QF_INT_DISABLE();
            status_ = Q_HANDLED();
            break;
        }
        default: {
            status_ = Q_SUPER(&CoffeeAO_submenu);
            break;
        }
    }
    return status_;
}
Exemple #10
0
/**
 * \brief Send an ICMPv6 Echo Request to Neighbor
 * 
 * \param Destination Neighbor_AO
 */
void uip_icmp6_echo_request_output_to_neighbor(Neighbor_AO * neighbor)
{
	NewDataEvent *e;
	struct uip_icmpip_hdr * icmpip_hdr;
	static QEvent const ps_sig = { PACKET_SENT_SIG};
	e= Q_NEW(NewDataEvent, SEND_DATA_SIG);
	icmpip_hdr = ( struct uip_icmpip_hdr *) &e->buf[UIP_LLH_LEN];

	
	set_eth_src_addr_local(e);
	set_eth_dst_addr(e, &neighbor->lladdr);
	
	/* IP header fields */
  icmpip_hdr->vtc = 0x60;
  icmpip_hdr->tcf = 0;
  icmpip_hdr->flow = 0;
  icmpip_hdr->proto = UIP_PROTO_ICMP6;
  icmpip_hdr->ttl = UIP_ND6_HOP_LIMIT;
	
	memcpy(&icmpip_hdr->destipaddr, &neighbor->ipaddr, sizeof(uip_ipaddr_t));
	memcpy(&icmpip_hdr->srcipaddr, &uip_hostaddr, sizeof(uip_ipaddr_t));
	
	icmpip_hdr->len[0] = 0; /* length will not be more than 255 */
	icmpip_hdr->len[1] = UIP_ICMPH_LEN + UIP_ICMP_QUENCH_LEN+ 32;
	
	e->len = UIP_LLH_LEN + UIP_IPH_LEN + UIP_ICMPH_LEN + UIP_ICMP_QUENCH_LEN + 32;
	icmpip_hdr->type = ICMP6_ECHO_REQUEST;
  icmpip_hdr->icode = 0;
	//ICMP QUENCH
	icmpip_hdr->id = htons(0x0002);
	icmpip_hdr->seq = htons(neighbor->icmp_seq);
	neighbor->icmp_seq++;
	
  icmpip_hdr->icmpchksum = 0;
  icmpip_hdr->icmpchksum = ~upper_layer_chksum6((unsigned char *) &e->buf);

	QF_publish((QEvent *) e);
	QActive_postFIFO((QActive *)neighbor, &ps_sig);
}
Exemple #11
0
/* @(/2/0/9/1/2/12) ........................................................*/
QState CoffeeAO_coffeePotToggle(CoffeeAO * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /* @(/2/0/9/1/2/12) */
        case Q_ENTRY_SIG: {
            l_CoffeeAO.is_coffee_pot_in_machine = l_CoffeeAO.is_coffee_pot_in_machine == 0 ? 1 : 0;
            QActive_postFIFO((QActive *)&l_CoffeeAO, Q_NEW(QEvent, GO_BACK_SIG));
            status_ = Q_HANDLED();
            break;
        }
        /* @(/2/0/9/1/2/12) */
        case Q_EXIT_SIG: {
            printf("toggled coffee pot in machine to: %u\n", l_CoffeeAO.is_coffee_pot_in_machine);
            status_ = Q_HANDLED();
            break;
        }
        default: {
            status_ = Q_SUPER(&CoffeeAO_submenu);
            break;
        }
    }
    return status_;
}
Exemple #12
0
/*..........................................................................*/
QState Philo_hungry(Philo *me, QEvent const *e) {
    switch (e->sig) {
    case Q_ENTRY_SIG: {
        TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG);
        pe->philoNum = PHILO_ID(me);
        QActive_postFIFO(AO_Table, (QEvent *)pe);
        return Q_HANDLED();
    }
    case EAT_SIG: {
        if (((TableEvt const *)e)->philoNum == PHILO_ID(me)) {
            BSP_busyDelay();
            return Q_TRAN(&Philo_eating);
        }
        break;
    }
    case DONE_SIG: {
        /* DONE must be for other Philos than this one */
        Q_ASSERT(((TableEvt const *)e)->philoNum != PHILO_ID(me));
        return Q_HANDLED();
    }
    }
    return Q_SUPER(&QHsm_top);
}
Exemple #13
0
/* @(/2/0/9/1/2/3) .........................................................*/
QState CoffeeAO_timeBrewActivatedToggle(CoffeeAO * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /* @(/2/0/9/1/2/3) */
        case Q_ENTRY_SIG: {
            l_CoffeeAO.is_automatic_brew_active = l_CoffeeAO.is_automatic_brew_active == 0 ? 1 : 0;
            Alarm_dispatch((QFsm *)&l_CoffeeAO.alarm, Q_NEW(QEvent, ALARM_TOGGLE_SIG));
            QActive_postFIFO((QActive *)&l_CoffeeAO, Q_NEW(QEvent, GO_BACK_SIG));
            status_ = Q_HANDLED();
            break;
        }
        /* @(/2/0/9/1/2/3) */
        case Q_EXIT_SIG: {
            printf("toggled automatic brew to: %u\n", l_CoffeeAO.is_automatic_brew_active);
            status_ = Q_HANDLED();
            break;
        }
        default: {
            status_ = Q_SUPER(&CoffeeAO_submenu);
            break;
        }
    }
    return status_;
}
Exemple #14
0
/**
 * AlarmMenu state handler
 **/
static QState MenuAO_AlarmMenu(MenuAO *me, QEvent const *e)
{
    switch ( e->sig )
    {
    case Q_INIT_SIG:
    {
        return Q_HANDLED();
    }

    case Q_ENTRY_SIG:
    {
        // get current alarm
        RTC_GetAlarm(&rtcTime);
        sprintf(output, "3: Alarm %02d:%02d", rtcTime.RTC_Hour, rtcTime.RTC_Min);

        // display alarm menu (1st row of LCD)
        lcd_clear();
        set_cursor(0, 0);
        lcd_print((unsigned char*)output);

        return Q_HANDLED();
    }

    case BUTTON_SHORTPRESS_SIG:
    {
        // short press > proceed to next submenu
        if (!me->waitingForSetTime)
            // guard condition: only if not waiting for set time
            return Q_TRAN(&MenuAO_ClockMenu);
        else
            return Q_HANDLED();
    }

    case BUTTON_LONGPRESS_SIG:
    {
        if (me->waitingForSetTime != true)
        {
            // long press > send change time request and wait for response
            me->waitingForSetTime = true;

            // send ENTER_SET_TIME_SIG to SetTimeAO
            QActive_postFIFO(SetTimeAOBase, (QEvent*)&l_EnterSetTimeEvt);
        }

        return Q_HANDLED();
    }

    case TIME_SET_SIG:
    {
        TimeSetEvt* evt = (TimeSetEvt*)e;
        me->waitingForSetTime = false;

        // save and arm time at RTC
        RTC_AlarmDisable();
        RTC_SetAlarm(&evt->time);
        RTC_AlarmEnable();

        // display new alarm
        sprintf(output, "3: Alarm %02d:%02d", evt->time.RTC_Hour, evt->time.RTC_Min);

        lcd_clear();
        set_cursor(0, 0);
        lcd_print((unsigned char*)output);

        return Q_HANDLED();
    }

    case Q_EXIT_SIG:
    {
        return Q_HANDLED();
    }
    }

    return Q_SUPER(&MenuAO_Idle);
}
Exemple #15
0
/**
 * ClockMenu state handler
 **/
static QState MenuAO_ClockMenu(MenuAO *me, QEvent const *e)
{
    switch ( e->sig )
    {
    case Q_INIT_SIG:
    {
        return Q_HANDLED();
    }

    case Q_ENTRY_SIG:
    {
        // get current time
        RTC_GetTime(&rtcTime);

        // display clock menu (1st row of LCD)
        sprintf(output, "1: Clock %02d:%02d", rtcTime.RTC_Hour, rtcTime.RTC_Min);
        lcd_clear();
        set_cursor(0, 0);
        lcd_print((unsigned char*)output);

        // send BREWSTRENGTH_SET_SIG to CoffeeMachineAO
        l_BrewStrengthSetEvt.brewStrength = me->brewStrength;
        QActive_postFIFO(CoffeeMachineAOBase, (QEvent*)&l_BrewStrengthSetEvt);

        return Q_HANDLED();
    }

    case BUTTON_SHORTPRESS_SIG:
    {
        // short press > proceed to next submenu
        if (!me->waitingForSetTime)
            // guard condition: only if not waiting for set time
            return Q_TRAN(&MenuAO_BrewStrengthMenu);
        else
            return Q_HANDLED();
    }

    case BUTTON_LONGPRESS_SIG:
    {
        if (me->waitingForSetTime != true)
        {
            // long press > send change time request and wait for response
            me->waitingForSetTime = true;

            // send ENTER_SET_TIME_SIG to SetTimeAO
            QActive_postFIFO(SetTimeAOBase, (QEvent*)&l_EnterSetTimeEvt);
        }

        return Q_HANDLED();
    }

    case TIME_SET_SIG:
    {
        TimeSetEvt* evt = (TimeSetEvt*)e;
        me->waitingForSetTime = false;

        // display new time (1st row of LCD)
        sprintf(output, "1: Clock %02d:%02d", evt->time.RTC_Hour, evt->time.RTC_Min);
        lcd_clear();
        set_cursor(0, 0);
        lcd_print((unsigned char*)output);

        // save time at RTC
        RTC_Stop();
        RTC_SetTime(&evt->time);
        RTC_Start();

        return Q_HANDLED();
    }

    case TIME_UPDATE_SIG:
    {
        // display updated time
        TimeUpdateEvt* evt = (TimeUpdateEvt*)e;
        sprintf(output, "1: Clock %02d:%02d", evt->time.RTC_Hour, evt->time.RTC_Min);

        set_cursor(0, 0);
        lcd_print((unsigned char*)output);

        return Q_HANDLED();
    }

    case Q_EXIT_SIG:
    {
        return Q_HANDLED();
    }
    }

    return Q_SUPER(&MenuAO_Idle);
}
Exemple #16
0
/**
 * ChangeBrewStrength state handler
 **/
static QState MenuAO_ChangeBrewStrength(MenuAO *me, QEvent const *e)
{
    static BrewStrength tmpBrewStrength;

    switch ( e->sig )
    {
    case Q_INIT_SIG:
    {
        return Q_HANDLED();
    }

    case Q_ENTRY_SIG:
    {
        // reset brew strength
        tmpBrewStrength = Unchanged;

        // display change brew strength (2nd row of LCD)
        sprintf(output, "SetStrength> %d", 2*me->brewStrength+2);
        set_cursor(0, 1);
        lcd_print((unsigned char*)output);

        return Q_HANDLED();
    }

    case BUTTON_SHORTPRESS_SIG:
    {
        // short press > block proceeding to next submenu in parent-state
        return Q_HANDLED();
    }

    case BUTTON_LONGPRESS_SIG:
    {
        if (tmpBrewStrength != Unchanged)
        {
            // brew strength has been changed
            me->brewStrength = tmpBrewStrength;

            // TODO maybe better use dynamic event, but should be okay here!
            l_BrewStrengthSetEvt.brewStrength = tmpBrewStrength;

            // send BREWSTRENGTH_SET_SIG to CoffeeMachineAO
            QActive_postFIFO(CoffeeMachineAOBase, (QEvent*)&l_BrewStrengthSetEvt);

            // display brew strength menu (1st row of LCD)
            sprintf(output, "2: Strength %d", 2*me->brewStrength+2);
            lcd_clear();
            set_cursor(0, 0);
            lcd_print((unsigned char*)output);
        }

        // long press > leave changing state and go back to submenu
        return Q_TRAN(&MenuAO_BrewStrengthMenu);
    }

    case AD_VALUE_SIG:
    {
        // set brew strength according to AD value

        // calculate brew strenght:
        // - ad value is from 0..100
        // - multiplying by 2 and dividing by 100 scales between 0..2
        // - adding 50 for correct rounding (integer-division)

        AdValueChangedEvt* evt = (AdValueChangedEvt*)e;
        tmpBrewStrength = (BrewStrength)(((evt->value * 2 + 50) / 100));

        // display change brew strength (2nd row of LCD)
        sprintf(output, "SetStrength> %d", 2*tmpBrewStrength+2);
        set_cursor(0, 1);
        lcd_print((unsigned char*)output);

        return Q_HANDLED();
    }

    case Q_EXIT_SIG:
    {
        return Q_HANDLED();
    }
    }

    return Q_SUPER(&MenuAO_BrewStrengthMenu);
}
Exemple #17
0
/* @(/2/0/9/1/1) ...........................................................*/
QState CoffeeAO_menu(CoffeeAO * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /* @(/2/0/9/1/1/0) */
        case ADWHEEL_SIG: {
            // calculate current menu entry
            char menu_text[20];
            struct Entry* menu_entry = &menu_entries[me->current_menu_index];
            me->current_menu_index = ((AdEvt*)e)->val * me->max_menu_index / 1024;
            lcd_clear();
            set_cursor(0, 0);
            switch (menu_entry->interpolate_with) {
            case NOTHING:
                strcpy(menu_text, menu_entry->menu_label);
                break;
            case BREW_STRENGTH:
                sprintf(menu_text, menu_entry->menu_label, l_CoffeeAO.current_brew_strength + 1);
                break;
            case IS_COFFEE_POT_IN_MACHINE:
                sprintf(menu_text, menu_entry->menu_label, l_CoffeeAO.is_coffee_pot_in_machine);
                break;
            case IS_AUTOMATIC_BREW_ACTIVE:
                sprintf(menu_text, menu_entry->menu_label, l_CoffeeAO.is_automatic_brew_active);
                break;
            }
            lcd_print(menu_text);

            set_cursor(4, 1);
            sprintf(menu_text, "%02u:%02u:%02u", l_CoffeeAO.alarm.real_current_time.hours, l_CoffeeAO.alarm.real_current_time.minutes, l_CoffeeAO.alarm.real_current_time.seconds);
            lcd_print(menu_text);
            status_ = Q_HANDLED();
            break;
        }
        /* @(/2/0/9/1/1/1) */
        case INT_SIG: {
            QEvent *menuEvt = Q_NEW(QEvent, menu_entries[me->current_menu_index].signal);
            //QEvent *menuEvt = Q_NEW(QEvent, GO_COFFEE_POT_TOGGLE_SIG);
            QF_INT_ENABLE();
            QActive_postFIFO((QActive *)&l_CoffeeAO, menuEvt);
            QF_INT_DISABLE();

            status_ = Q_HANDLED();
            break;
        }
        /* @(/2/0/9/1/1/2) */
        case GO_COFFEE_POT_TOGGLE_SIG: {
            status_ = Q_TRAN(&CoffeeAO_coffeePotToggle);
            break;
        }
        /* @(/2/0/9/1/1/3) */
        case GO_TIME_BREW_TOGGLE_SIG: {
            status_ = Q_TRAN(&CoffeeAO_timeBrewActivatedToggle);
            break;
        }
        /* @(/2/0/9/1/1/4) */
        case GO_SET_BREW_TIME_CLOCK_SIG: {
            status_ = Q_TRAN(&CoffeeAO_set_brew_h1);
            break;
        }
        /* @(/2/0/9/1/1/5) */
        case GO_SET_TIME_OF_DAY_SIG: {
            status_ = Q_TRAN(&CoffeeAO_set_clock_h1);
            break;
        }
        /* @(/2/0/9/1/1/6) */
        case GO_START_BREWING_SIG: {
            status_ = Q_TRAN(&CoffeeAO_startBrewingNow);
            break;
        }
        /* @(/2/0/9/1/1/7) */
        case GO_SET_BREW_STRENGTH_SIG: {
            status_ = Q_TRAN(&CoffeeAO_setBrewStrength);
            break;
        }
        default: {
            status_ = Q_SUPER(&CoffeeAO_coffeemachine);
            break;
        }
    }
    return status_;
}