Example #1
0
/* This originally was for battery charge control, but now it handles
 * other things that must be periodically checked such as 
 * mux control and task check in (watchdog)
 */
static void MonitorBattery(void)
{
  static unsigned char LastPercent = 101;

#if CHECK_CSTACK
  if (LastPercent == 101) CheckCStack();
#endif

  unsigned char ClipChanged = CheckClip();
  CheckBattery();
  
  if (ClipChanged || Charging() || CurrentPage[PageType] == StatusPage)
  {
    unsigned char CurrPercent = BatteryPercentage();

    if (CurrPercent != LastPercent || ClipChanged)
    {
      if (CurrentPage[PageType] == StatusPage) DrawWatchStatusScreen();
      else UpdateClock(); // must be the last to avoid screen mess-up
      
      LastPercent = CurrPercent;
    }
  }

  /* Watchdog requires each task to check in.
   * If the background task reaches here then it can check in.
   * Send a message to the other tasks so that they must check in.
   */
  TaskCheckIn(eDisplayTaskCheckInId);
  CreateAndSendMessage(WrapperTaskCheckInMsg, MSG_OPT_NONE);

#if TASK_DEBUG
  UTL_FreeRtosTaskStackCheck();
#endif
}
Example #2
0
const unsigned char *GetBatteryIcon(unsigned char Id)
{
  unsigned int Level = Read(BATTERY);
  unsigned char Index = 0;

  if (Level >= BATTERY_FULL_LEVEL) Index = BATTERY_LEVEL_NUMBER;
  else if (Level <= BatteryCriticalLevel(CRITICAL_WARNING) && !Charging()) Index = 1; // warning icon index
  else
  {
    unsigned int Empty = BatteryCriticalLevel(CRITICAL_BT_OFF);
    unsigned int Step = (BATTERY_FULL_LEVEL - Empty) / BATTERY_LEVEL_NUMBER;
    
    while (Level > (Empty + Step * Index)) Index ++;
  }
  
  const unsigned char *pIcon = IconInfo[Id].pIconSet + (Index * IconInfo[Id].Width * IconInfo[Id].Height);
  if (!Charging()) pIcon += BATTERY_ICON_NUM * IconInfo[Id].Width * IconInfo[Id].Height;

  return pIcon;
}
void FORTE_iCreateBattery::executeEvent(int pa_nEIID){
  switch (pa_nEIID){
    case scm_nEventREQID:
      create_battery_charge();
      Charging() = static_cast<TForteInt16>(gc_charge_state); //get_create_charging_state(LAG());
      Voltage() = static_cast<TForteInt16>(gc_batt_voltage);
      Current() = static_cast<TForteInt16>(gc_current_flow);
      Temperature() = static_cast<TForteInt16>(gc_batt_temp);
      Charge() = static_cast<TForteInt16>(gc_batt_charge);
      Capacity() = static_cast<TForteInt16>(gc_batt_capacity);
      sendOutputEvent(scm_nEventCNFID);
      break;
  }
}
Example #4
0
/* 80 us
 * 
 * conversion time = 13 * ADC12DIV *  1/FreqAdcClock
 * 13 * 8 * 1/5e6 = 20.8 us
 */
void BatterySenseCycle(void)
{ 
  static unsigned char Index = 0;

  xSemaphoreTake(AdcMutex, portMAX_DELAY);
  
  BATTERY_SENSE_ENABLE();
  ENABLE_REFERENCE();

  /* low_bat_en assertion to bat_sense valid is ~100 ns */
  /* Start battery sense conversion */
  AdcCheck();
  CLEAR_START_ADDR();
  ADC12CTL1 |= ADC12CSTARTADD_1;
  ENABLE_ADC();

  WaitForAdcBusy();

  /* Convert the ADC count for the battery input into a voltage 
   * ADC12MEM1: Counts Battery Voltage in ADC counts
   * Result: Battery voltage in millivolts */
  unsigned int Value = (unsigned int)(CONVERSION_FACTOR_BATTERY * (double)ADC12MEM1);

  if (ValidCalibration()) Value += GetBatteryCalibrationValue();

  /* smoothing algorithm: cut extreme values (gap > 20) */
  unsigned char Prev = (Index == 0) ? MAX_SAMPLES - 1: Index - 1;
  if (Sample[BATTERY][Prev])
  {
    int Gap = Value - Sample[BATTERY][Prev];
    if (Charging())
    {
      if (Gap > GAP_BIG) Gap = GAP_BIG;
      else if (Gap < GAP_SMALL_NEGATIVE) Gap = GAP_SMALL_NEGATIVE;
    }
    else
    {
      if (Gap > GAP_SMALL) Gap = GAP_SMALL;
      else if (Gap < GAP_BIG_NEGATIVE) Gap = GAP_BIG_NEGATIVE;
    }
    
    Sample[BATTERY][Index] = Sample[BATTERY][Prev] + Gap;
  }
  else Sample[BATTERY][Index] = Value;

  if (++Index >= MAX_SAMPLES) Index = 0;
  
  BATTERY_SENSE_DISABLE();
  EndAdcCycle(); //xSemaphoreGive()
}
Example #5
0
/*! Read the voltage of the battery. This provides power good, battery charging,
 * battery voltage, and battery voltage average.
 *
 * \param tHostMsg* pMsg is unused
 *
 */
static void ReadBatteryVoltageHandler(void)
{
  tMessage Msg;
  SetupMessageAndAllocateBuffer(&Msg, VBatRespMsg, MSG_OPT_NONE);
  Msg.Length = 6;

  Msg.pBuffer[0] = ClipOn();
  Msg.pBuffer[1] = Charging();
  Msg.pBuffer[2] = BatteryPercentage();

  unsigned int bv = Read(BATTERY);
  Msg.pBuffer[4] = bv & 0xFF;
  Msg.pBuffer[5] = (bv >> 8) & 0xFF;

  RouteMsg(&Msg);
}
Example #6
0
double BatteryManager::ChargingTime() const {
  MOZ_ASSERT(NS_IsMainThread());
  // For testing, unable to report the battery status information
  if (Preferences::GetBool("dom.battery.test.default", false)) {
    return 0.0;
  }
  if (Preferences::GetBool("dom.battery.test.charging", false)) {
    return 42.0;
  }

  if (!Charging() || mRemainingTime == kUnknownRemainingTime) {
    return std::numeric_limits<double>::infinity();
  }

  return mRemainingTime;
}
Example #7
0
//use time for IR sensor value if using TRIP
void WallFollow(int mode, int time, int dir){
	 int startTime, diff, close;
	 switch(mode){
		 case NEVER:
		 while(1){
		 	 diff = WallFollowPID(  ADS7830_Values[FRONT_LEFT] -  ADS7830_Values[BACK_LEFT], P9v , 0 , D12v , divP12v, 1 , divD12v);
		 	 close = 0;//WallFollowPID2( IDEAL_DISTANCE - (ADS7830_Values[FRONT_LEFT] + ADS7830_Values[BACK_LEFT]) , 1 , 0 , 0, 1 , 0 , 0);
			 UARTprintf("Back Left: %d Front_Left: %d, close: %d, diff: %d\n",ADS7830_Values[BACK_LEFT], ADS7830_Values[FRONT_LEFT], close, diff);
			 SetMotorPowersBlocking( dir*(127 + diff + close) ,dir*(127 - diff - close));
		 }
		 //break;
		 case CHARGING:
		 while(!Charging()){
		 	 diff = WallFollowPID(  ADS7830_Values[FRONT_LEFT] -  ADS7830_Values[BACK_LEFT], P9v , 0 , D12v , divP12v, 1 , divD12v);
		 	 close = 0;//WallFollowPID2( IDEAL_DISTANCE - (ADS7830_Values[FRONT_LEFT] + ADS7830_Values[BACK_LEFT]) , 1 , 0 , 0, 1 , 0 , 0);
			 UARTprintf("Back Left: %d Front_Left: %d, close: %d, diff: %d\n",ADS7830_Values[BACK_LEFT], ADS7830_Values[FRONT_LEFT], close, diff);
			 SetMotorPowersBlocking( dir*(127 + diff + close) ,dir*(127 - diff - close));
		 }
		 break;
		 case TIMEOUT:
		 startTime = GetTimeMS();
		 while(GetTimeMS()<startTime+time){
		 	 diff = WallFollowPID(  ADS7830_Values[FRONT_LEFT] -  ADS7830_Values[BACK_LEFT], P9v , 0 , D12v , divP12v, 1 , divD12v);
		 	 close = 0;//WallFollowPID2( IDEAL_DISTANCE - (ADS7830_Values[FRONT_LEFT] + ADS7830_Values[BACK_LEFT]) , 1 , 0 , 0, 1 , 0 , 0);
			 UARTprintf("Back Left: %d Front_Left: %d, close: %d, diff: %d\n",ADS7830_Values[BACK_LEFT], ADS7830_Values[FRONT_LEFT], close, diff);
			 SetMotorPowersBlocking( dir*(127 + diff + close) ,dir*(127 - diff - close));
		 }
		 break;
		 case TRIP:
		 while(!tripped(time,LOWER)){
		 	 diff = WallFollowPID(  ADS7830_Values[FRONT_LEFT] -  ADS7830_Values[BACK_LEFT], P9v , 0 , D12v , divP12v, 1 , divD12v);
		 	 close = 0;//WallFollowPID2( IDEAL_DISTANCE - (ADS7830_Values[FRONT_LEFT] + ADS7830_Values[BACK_LEFT]) , 1 , 0 , 0, 1 , 0 , 0);
			 UARTprintf("Back Left: %d Front_Left: %d, close: %d, diff: %d\n",ADS7830_Values[BACK_LEFT], ADS7830_Values[FRONT_LEFT], close, diff);
			 SetMotorPowersBlocking( dir*(127 + diff + close) ,dir*(127 - diff - close));
		 }
		 break;

	 }
}
Example #8
0
void Moose::FSM()
{
	switch (mCurState)
	{
	case ES_IDLE:
		Idle();
		break;
	case ES_HUNTING:
		Hunting();
		break;
	case ES_ATTACK:
		Attack();
		break;
	case ES_STALKING:
		Stalking();
		break;
	case ES_MATING:
		Mating();
		break;
	case ES_CHARGING:
		Charging();
		break;
	}
}
Example #9
0
void DrawDateTime(void)
{
  // clean date&time area
  FillMyBuffer(STARTING_ROW, WATCH_DRAW_SCREEN_ROW_NUM, 0x00);

  SetFont(DEFAULT_HOURS_FONT);  
  gRow = DEFAULT_HOURS_ROW;
  gColumn = DEFAULT_HOURS_COL;
  gBitColumnMask = DEFAULT_HOURS_COL_BIT;
  DrawHours(DRAW_OPT_BITWISE_OR);

  gRow = DEFAULT_MINS_ROW;
  gColumn = DEFAULT_MINS_COL;
  gBitColumnMask = DEFAULT_MINS_COL_BIT;
  DrawMins(DRAW_OPT_BITWISE_OR);
  
  if (GetProperty(PROP_TIME_SECOND)) DrawSecs();
  else if (Charging()) DrawBatteryOnIdleScreen(3, 9, MetaWatch5);
  else
  {
    if (!GetProperty(PROP_24H_TIME_FORMAT))
    {
      gRow = DEFAULT_AM_PM_ROW;
      gColumn = DEFAULT_AM_PM_COL;
      gBitColumnMask = DEFAULT_AM_PM_COL_BIT;
      SetFont(DEFAULT_AM_PM_FONT);
      DrawString((RTCHOUR > 11) ? "PM" : "AM", DRAW_OPT_BITWISE_OR);
    }

    gRow = GetProperty(PROP_24H_TIME_FORMAT) ? DEFAULT_DOW_24HR_ROW : DEFAULT_DOW_12HR_ROW;
    gColumn = DEFAULT_DOW_COL;
    gBitColumnMask = DEFAULT_DOW_COL_BIT;
    SetFont(DEFAULT_DOW_FONT);
    DrawString((tString *)DaysOfTheWeek[LANG_EN][RTCDOW], DRAW_OPT_BITWISE_OR);

    //add year when time is in 24 hour mode
    if (GetProperty(PROP_24H_TIME_FORMAT))
    {
      gRow = DEFAULT_DATE_YEAR_ROW;
      gColumn = DEFAULT_DATE_YEAR_COL;
      gBitColumnMask = DEFAULT_DATE_YEAR_COL_BIT;
      SetFont(DEFAULT_DATE_YEAR_FONT);

      unsigned char Year = RTCYEARH;
      DrawChar(BCD_H(Year) + ZERO, DRAW_OPT_BITWISE_OR);
      DrawChar(BCD_L(Year) + ZERO, DRAW_OPT_BITWISE_OR);
      Year = RTCYEARL;
      DrawChar(BCD_H(Year) + ZERO, DRAW_OPT_BITWISE_OR);
      DrawChar(BCD_L(Year) + ZERO, DRAW_OPT_BITWISE_OR);
    }

    //Display month and day
    //Watch controls time - use default date position
    unsigned char DayFirst = GetProperty(PROP_DDMM_DATE_FORMAT);
    char Rtc[2];
    Rtc[DayFirst ? 0 : 1] = RTCDAY;
    Rtc[DayFirst ? 1 : 0] = RTCMON;

    gRow = DEFAULT_DATE_FIRST_ROW;
    gColumn = DEFAULT_DATE_FIRST_COL;
    gBitColumnMask = DEFAULT_DATE_FIRST_COL_BIT;
    SetFont(DEFAULT_DATE_MONTH_FONT);
    
    DrawChar(BCD_H(Rtc[0]) + ZERO, DRAW_OPT_BITWISE_OR);
    DrawChar(BCD_L(Rtc[0]) + ZERO, DRAW_OPT_BITWISE_OR);
    
    //Display separator
    SetFont(DEFAULT_DATE_SEPARATOR_FONT);
    DrawChar(DayFirst ? '.' : '/', DRAW_OPT_BITWISE_OR);
    
    //Display day second
    gRow = DEFAULT_DATE_SECOND_ROW;
    gColumn = DEFAULT_DATE_SECOND_COL;
    gBitColumnMask = DEFAULT_DATE_SECOND_COL_BIT;
    SetFont(DEFAULT_DATE_DAY_FONT);
    
    DrawChar(BCD_H(Rtc[1]) + ZERO, DRAW_OPT_BITWISE_OR);
    DrawChar(BCD_L(Rtc[1]) + ZERO, DRAW_OPT_BITWISE_OR);
  }
  
  SendMyBufferToLcd(STARTING_ROW, WATCH_DRAW_SCREEN_ROW_NUM);
}