示例#1
0
void bt0PopCallback(void *ptr)
{
  uint32_t dual_state;
  dbSerialPrintln("bt0PopCallback");
  dbSerialPrint("ptr=");
  dbSerialPrintln((uint32_t)ptr);

  // EEPROM
  // Address 1 = 0/1 for language (0: English, 1: Finnish)
  bt0.getValue(&dual_state);
  if(dual_state) {
    dbSerialPrintln("Language: FI");
    langCode = 1;
  }
  else {
    dbSerialPrintln("Language: EN");
    langCode = 0;
  }

  int8_t eepromLang = EEPROM.read(1);
  if(langCode != eepromLang) {
    dbSerialPrint("Writing to EEPROM! Value: ");
    dbSerialPrintln(langCode);
    EEPROM.write(1, langCode);
  }
}
/**
 * Set current backlight brightness value. 
 *
 * @param dimValue - current backlight brightness value.
 * 
 * @retval true - success. 
 * @retval false - failed.
 */
bool setCurrentBrightness(uint8_t dimValue)
{
    bool ret = false;
    char buf[10] = {0};
    String cmd;
    utoa(dimValue, buf, 10);
    cmd += "dim=";
    cmd += buf;
    sendCommand(cmd.c_str());
    delay(10);

    if(recvRetCommandFinished())
    {   
        dbSerialPrint("setCurrentBrightness[ ");
        dbSerialPrint(dimValue);
        dbSerialPrintln("]ok ");
      
        ret = true; 
    }
    else 
    {
        dbSerialPrintln("setCurrentBrightness err ");
    }

    return ret;    
}
示例#3
0
void bt1PopCallback(void *ptr)
{
  uint32_t dual_state;
  dbSerialPrintln("bt1PopCallback");
  dbSerialPrint("ptr=");
  dbSerialPrintln((uint32_t)ptr);

  // EEPROM
  // Address 1 = 0/1 for temperature scale (0: Celsius, 1: Fahrenheit)
  bt1.getValue(&dual_state);
  if(dual_state) {
    dbSerialPrintln("Scale: F");
    tempScale = 1;
  }
  else {
    dbSerialPrintln("Scale: °C");
    tempScale = 0;
  }

  int8_t eepromScale = EEPROM.read(2);
  if(tempScale != eepromScale) {
    dbSerialPrint("Writing to EEPROM! Value: ");
    dbSerialPrintln(tempScale);
    EEPROM.write(2, tempScale);
  }
}
示例#4
0
void b2PopCallback(void *ptr) {
  dbSerialPrintln("b2PopCallback");
  dbSerialPrint("ptr=");
  dbSerialPrintln((uint32_t)ptr);

  renderScreen(SETTINGS_SCREEN);
}
示例#5
0
void b1PopCallback(void *ptr) {
  dbSerialPrintln("b1PopCallback");
  dbSerialPrint("ptr=");
  dbSerialPrintln((uint32_t)ptr);

  // History page TBD!
}
示例#6
0
/* ***************************************** */
void b0PopCallback(void *ptr) {
  dbSerialPrintln("b0PopCallback");
  dbSerialPrint("ptr=");
  dbSerialPrintln((uint32_t)ptr);

  renderScreen(SECOND_SCREEN);
}
示例#7
0
/* Processing weather data which got from forecast.io */
void processWeatherData(const char *name, const char *data) {
  dbSerialPrintln("in processWeather");
  String str = String(data);
  char strBuffer[300] = "";
  str.toCharArray(strBuffer, 300);
  int day = 0;
  String tmpStr;

  dbSerialPrintln("Time now: " + String(Time.hour()) + ":" + String(Time.minute()));
  //dbSerialPrintln("Data: " + str);

  // Parse the API response.
  while(day < 4) {
    if(day == 0)
      weatherData[day].summ = strtok(strBuffer, "~");
    else {
      weatherData[day].summ = strtok(NULL, "~");
      //dbSerialPrintln("Summary: " + );
    }

    weatherData[day].weekday = Time.weekday(Time.now() + day*86400);
    weatherData[day].icon = processIcon(strtok(NULL, "~"), day);

    if(day > 0) {
      weatherData[day].minTemp = (((int)round(atof(strtok(NULL, "~"))))-32)/1.8;
      weatherData[day].maxTemp = (((int)round(atof(strtok(NULL, "~"))))-32)/1.8;
    }

    day++;
  }

  int cnt = 0;
  while(cnt < 4) {
    dbSerialPrint("Day " + String(cnt) + ": ");
    dbSerialPrint("Summary: " + weatherData[cnt].summ + ", ");
    dbSerialPrint("Icon: " + String(weatherData[cnt].icon) + ", ");
    dbSerialPrint("Weekday: " + String(weatherData[cnt].weekday) + ", ");
    dbSerialPrint("Min Temp: " + String(weatherData[cnt].minTemp) + ", ");
    dbSerialPrintln("Max Temp: " + String(weatherData[cnt].maxTemp));
    cnt++;
  }

  weather_state = WEATHER_READY;
  updateweatherhour = Time.hour();

  renderScreen(HOME_SCREEN);
}
示例#8
0
void u0PopCallback(void *ptr)
{
  dbSerialPrintln("u0PopCallback");
  dbSerialPrint("ptr=");
  dbSerialPrintln((uint32_t)ptr);

  renderScreen(HOME_SCREEN);
}
示例#9
0
void n1PopCallback(void *ptr)
{
  dbSerialPrintln("n1PopCallback");
  dbSerialPrint("ptr=");
  dbSerialPrintln((uint32_t)ptr);

  renderScreen(ABOUT_SCREEN);
}
示例#10
0
void NexObject::printObjInfo(void)
{
    dbSerialPrint("[");
    dbSerialPrint((uint32_t)this);
    dbSerialPrint(":");
    dbSerialPrint(__pid);
    dbSerialPrint(",");
    dbSerialPrint(__cid);
    dbSerialPrint(",");
    if (__name)
    {
        dbSerialPrint(__name);
    }
    else
    {
        dbSerialPrint("(null)");
    }
    dbSerialPrintln("]");
}
/**
 * Return current page id.   
 *  
 * @param pageId - output parameter,to save page id.  
 * 
 * @retval true - success. 
 * @retval false - failed. 
 */
bool sendCurrentPageId(uint8_t* pageId)
{

    bool ret = false;
    uint8_t temp[5] = {0};

    if (!pageId)
    {
        goto __return;
    }
    sendCommand("sendme");
    delay(50);
    nexSerial.setTimeout(100);
    if (sizeof(temp) != nexSerial.readBytes((char *)temp, sizeof(temp)))
    {
        goto __return;
    }

    if (temp[0] == NEX_RET_CURRENT_PAGE_ID_HEAD
    && temp[2] == 0xFF
    && temp[3] == 0xFF
    && temp[4] == 0xFF
    )
    {
        *pageId = temp[1];
        ret = true;
    }

    __return:

    if (ret) 
    {
        dbSerialPrint("recvPageId :");
        dbSerialPrintln(*pageId);
    }
    else
    {
        dbSerialPrintln("recvPageId err");
    }

    return ret;

}
/*
 * Receive uint32_t data. 
 * 
 * @param number - save uint32_t data. 
 * @param timeout - set timeout time. 
 *
 * @retval true - success. 
 * @retval false - failed.
 *
 */
bool recvRetNumber(uint32_t *number, uint32_t timeout)
{
    bool ret = false;
    uint8_t temp[8] = {0};

    if (!number)
    {
        goto __return;
    }
    
    nexSerial.setTimeout(timeout);
    if (sizeof(temp) != nexSerial.readBytes((char *)temp, sizeof(temp)))
    {
        goto __return;
    }

    if (temp[0] == NEX_RET_NUMBER_HEAD
        && temp[5] == 0xFF
        && temp[6] == 0xFF
        && temp[7] == 0xFF
        )
    {
        *number = (temp[4] << 24) | (temp[3] << 16) | (temp[2] << 8) | (temp[1]);
        ret = true;
    }

__return:

    if (ret) 
    {
        dbSerialPrint("recvRetNumber :");
        dbSerialPrintln(*number);
    }
    else
    {
        dbSerialPrintln("recvRetNumber err");
    }
    
    return ret;
}
/*
 * Receive string data. 
 * 
 * @param buffer - save string data. 
 * @param len - string buffer length. 
 * @param timeout - set timeout time. 
 *
 * @return the length of string buffer.
 *
 */
uint16_t recvRetString(char *buffer, uint16_t len, uint32_t timeout)
{
    uint16_t ret = 0;
    bool str_start_flag = false;
    uint8_t cnt_0xff = 0;
    String temp = String("");
    uint8_t c = 0;
    long start;

    if (!buffer || len == 0)
    {
        goto __return;
    }
    
    start = millis();
    while (millis() - start <= timeout)
    {
        while (nexSerial.available())
        {
            c = nexSerial.read();
            if (str_start_flag)
            {
                if (0xFF == c)
                {
                    cnt_0xff++;                    
                    if (cnt_0xff >= 3)
                    {
                        break;
                    }
                }
                else
                {
                    temp += (char)c;
                }
            }
            else if (NEX_RET_STRING_HEAD == c)
            {
                str_start_flag = true;
            }
        }
        
        if (cnt_0xff >= 3)
        {
            break;
        }
    }

    ret = temp.length();
    ret = ret > len ? len : ret;
    strncpy(buffer, temp.c_str(), ret);
    
__return:

    dbSerialPrint("recvRetString[");
    dbSerialPrint(temp.length());
    dbSerialPrint(",");
    dbSerialPrint(temp);
    dbSerialPrintln("]");

    return ret;
}
void nexLoop(NexTouch *nex_listen_list[])
{
    static uint8_t __buffer[20];
    
    uint16_t i;
    uint8_t c;  
    
    while (nexSerial.available() > 0)
    {   
        delay(10);
        c = nexSerial.read();
        
        if (NEX_RET_EVENT_TOUCH_HEAD == c)
        {
            if (nexSerial.available() >= 6)
            {
                __buffer[0] = c;  
                for (i = 1; i < 7; i++)
                {
                    __buffer[i] = nexSerial.read();
                }
                __buffer[i] = 0x00;
                
                if (0xFF == __buffer[4] && 0xFF == __buffer[5] && 0xFF == __buffer[6])
                {
                    NexTouch::iterate(nex_listen_list, __buffer[1], __buffer[2], (int32_t)__buffer[3], NULL);
                }
                
            }
        }
        else if( NEX_RET_CURRENT_PAGE_ID_HEAD == c)
        {
            dbSerialPrint("page cmd:");
            if (nexSerial.available() >= 4)
            {
                __buffer[0] = c;  
                for (i = 1; i < 5; i++)
                {
                    __buffer[i] = nexSerial.read();
                }
                __buffer[i] = 0x00;
                
                if (0xFF == __buffer[2] && 0xFF == __buffer[3] && 0xFF == __buffer[4])
                {
                    dbSerialPrintln(__buffer[1]);
                    NexTouch::iterate(nex_listen_list, __buffer[1], 0, (int32_t)NEX_EVENT_PUSH, NULL);
                }
                
            }
        }
        else if (NEX_RET_VALUE_HEAD == c)
        {
            dbSerialPrint("value cmd:");
            if (nexSerial.available() >= 10)
            {
                __buffer[0] = c;  
                for (i = 1; i < 12; i++)
                {
                    __buffer[i] = nexSerial.read();
                }
                __buffer[i] = 0x00;
                
                if (0xFF == __buffer[i-1] && 0xFF == __buffer[i-2] && 0xFF == __buffer[i-3])
                {
                    dbSerialPrint(" Page:");
                    dbSerialPrint(__buffer[1]);
                    dbSerialPrint(" Component:");
                    dbSerialPrint(__buffer[2]);
                    dbSerialPrint(" Value:");
                    i = __buffer[4] | (((unsigned long)__buffer[5]) << 8) | (((unsigned long)__buffer[6]) << 16) | (((unsigned long)__buffer[6]) << 24);
                    dbSerialPrintln(i);
                    NexTouch::iterate(nex_listen_list, __buffer[1], __buffer[2], (int32_t)__buffer[3], (void *)&(__buffer[4]));
                }
            }   
        }
    }
}
示例#15
0
/* Rendering home screen */
void renderHomeScreen() {
  dbSerialPrintln("renderHomeScreen");
  writeLocation();

  // Render outside temperature
  char bufTemp[10];
  if(tempScale == 0)
    sprintf(bufTemp, "%.1f", currentOutsideTemperatureC);
  else {
    sprintf(bufTemp, "%.1f", currentOutsideTemperatureC * 1.8 + 32); // Celsius to Fahrenheit conversion
    dbSerialPrint("Temp in F: ");
    dbSerialPrintln(bufTemp);
  }
  t0.setText(bufTemp);

  // Render outside humidity
  char bufHumid[10];;
  sprintf(bufHumid, "%.1f", currentOutsideHumidity);
  t8.setText(bufHumid);

  // Render correct temperature scale based on the selection
  if(tempScale == 0) {
    t1.setText("°C");
    t4.setText("°C");
    t13.setText("°C");
    t15.setText("°C");
    t17.setText("°C");
    t19.setText("°C");
    t21.setText("°C");
    t23.setText("°C");
  }
  else {
    t1.setText("F");
    t4.setText("F");
    t13.setText("F");
    t15.setText("F");
    t17.setText("F");
    t19.setText("F");
    t21.setText("F");
    t23.setText("F");
  }

  /* Render days of week for forecast
  dbSerialPrint("Time: ");
  dbSerialPrint(Time.hour());
  dbSerialPrint(":");
  dbSerialPrintln(Time.minute());
  dbSerialPrint("Day of week: ");
  dbSerialPrintln(Time.weekday());*/

  int day = 0;
  while(day < 4) {
    // Icons for all days
    dbSerialPrintln("weatherData[" + String(day) + "]: " + String(weatherData[day].icon));
    if(weatherData[day].icon > 0) {
      if(day == 0)
        p0.setPic(weatherData[day].icon);
      else if(day == 1)
        p1.setPic(weatherData[day].icon);
      else if(day == 2)
        p2.setPic(weatherData[day].icon);
      else if(day == 3)
        p3.setPic(weatherData[day].icon);
    }

    // Day + 1 forecast info
    if(day == 1) {
      if(langCode==0)
        t5.setText(daysOfWeek_en[weatherData[day].weekday]);
      else
        t5.setText(daysOfWeek_fi[weatherData[day].weekday]);

      if(tempScale == 0)
        t12.setText(String(weatherData[day].minTemp));
      else
        t12.setText(String((int)round(weatherData[day].minTemp * 1.8 + 32)));

      if(tempScale == 0)
        t14.setText(String(weatherData[day].maxTemp));
      else
        t14.setText(String((int)round(weatherData[day].maxTemp * 1.8 + 32)));
    }
    // Day + 2 forecast info
    else if(day == 2) {
      if(langCode==0)
        t6.setText(daysOfWeek_en[weatherData[day].weekday]);
      else
        t6.setText(daysOfWeek_fi[weatherData[day].weekday]);
      //t16.setText(String(weatherData[day].minTemp));
      //t18.setText(String(weatherData[day].maxTemp));

      if(tempScale == 0)
        t16.setText(String(weatherData[day].minTemp));
      else
        t16.setText(String((int)round(weatherData[day].minTemp * 1.8 + 32)));

      if(tempScale == 0)
        t18.setText(String(weatherData[day].maxTemp));
      else
        t18.setText(String((int)round(weatherData[day].maxTemp * 1.8 + 32)));
    }
    // Day +3 foreast info
    else if(day == 3) {
      if(langCode==0)
        t7.setText(daysOfWeek_en[int(weatherData[day].weekday)]);
      else
        t7.setText(daysOfWeek_fi[weatherData[day].weekday]);
      //t20.setText(String(weatherData[day].minTemp));
      //t22.setText(String(weatherData[day].maxTemp));

      if(tempScale == 0)
        t20.setText(String(weatherData[day].minTemp));
      else
        t20.setText(String((int)round(weatherData[day].minTemp * 1.8 + 32)));

      if(tempScale == 0)
        t22.setText(String(weatherData[day].maxTemp));
      else
        t22.setText(String((int)round(weatherData[day].maxTemp * 1.8 + 32)));
    }

    day++;
  }
}