Add status boxes
This commit is contained in:
		
							
								
								
									
										37
									
								
								TouchGFX/gui/include/gui/containers/DriverViewStatusItem.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								TouchGFX/gui/include/gui/containers/DriverViewStatusItem.hpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,37 @@
 | 
			
		||||
#ifndef DRIVERVIEWSTATUSITEM_HPP
 | 
			
		||||
#define DRIVERVIEWSTATUSITEM_HPP
 | 
			
		||||
 | 
			
		||||
#include "touchgfx/Color.hpp"
 | 
			
		||||
#include "touchgfx/hal/Types.hpp"
 | 
			
		||||
#include <gui_generated/containers/DriverViewStatusItemBase.hpp>
 | 
			
		||||
 | 
			
		||||
enum class DriverViewStatusType { TS_R2D, AMS, SDC, SCS, PDU, INV };
 | 
			
		||||
 | 
			
		||||
class DriverViewStatusItem : public DriverViewStatusItemBase {
 | 
			
		||||
public:
 | 
			
		||||
  DriverViewStatusItem();
 | 
			
		||||
  virtual ~DriverViewStatusItem() {}
 | 
			
		||||
 | 
			
		||||
  virtual void initialize();
 | 
			
		||||
 | 
			
		||||
  virtual void setType(DriverViewStatusType type);
 | 
			
		||||
 | 
			
		||||
  void update();
 | 
			
		||||
 | 
			
		||||
  static inline colortype COLOR_OFF =
 | 
			
		||||
      touchgfx::Color::getColorFromRGB(0x00, 0x00, 0x00);
 | 
			
		||||
  static inline colortype COLOR_OK =
 | 
			
		||||
      touchgfx::Color::getColorFromRGB(0x0D, 0xBF, 0x00);
 | 
			
		||||
  static inline colortype COLOR_WARNING =
 | 
			
		||||
      touchgfx::Color::getColorFromRGB(0xEB, 0xC4, 0x00);
 | 
			
		||||
  static inline colortype COLOR_ERROR =
 | 
			
		||||
      touchgfx::Color::getColorFromRGB(0xC5, 0x0E, 0x1F);
 | 
			
		||||
  static inline colortype COLOR_TS =
 | 
			
		||||
      touchgfx::Color::getColorFromRGB(0xEB, 0x7D, 0x00);
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
private:
 | 
			
		||||
  DriverViewStatusType type;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // DRIVERVIEWSTATUSITEM_HPP
 | 
			
		||||
@ -23,6 +23,7 @@ public:
 | 
			
		||||
 | 
			
		||||
  void setFieldType(size_t i, DataFieldType type);
 | 
			
		||||
  void updateFieldValues();
 | 
			
		||||
  void updateStatusItems();
 | 
			
		||||
 | 
			
		||||
  void setTemps(const Temperatures &temps);
 | 
			
		||||
  void setTSSoC(uint8_t soc);
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										63
									
								
								TouchGFX/gui/src/containers/DriverViewStatusItem.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								TouchGFX/gui/src/containers/DriverViewStatusItem.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,63 @@
 | 
			
		||||
#include <gui/containers/DriverViewStatusItem.hpp>
 | 
			
		||||
 | 
			
		||||
#include "texts/TextKeysAndLanguages.hpp"
 | 
			
		||||
#include "vehicle.h"
 | 
			
		||||
 | 
			
		||||
DriverViewStatusItem::DriverViewStatusItem() {}
 | 
			
		||||
 | 
			
		||||
void DriverViewStatusItem::initialize() {
 | 
			
		||||
  DriverViewStatusItemBase::initialize();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void DriverViewStatusItem::setType(DriverViewStatusType type) {
 | 
			
		||||
  this->type = type;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void DriverViewStatusItem::update() {
 | 
			
		||||
  switch (type) {
 | 
			
		||||
  case DriverViewStatusType::TS_R2D:
 | 
			
		||||
    if (vehicle_state.ts_state == TS_ERROR) {
 | 
			
		||||
      text.setTypedText(T_TS);
 | 
			
		||||
      bg.setColor(COLOR_ERROR);
 | 
			
		||||
    } else if (vehicle_state.ts_state == TS_INACTIVE) {
 | 
			
		||||
      text.setTypedText(T_TS);
 | 
			
		||||
      bg.setColor(COLOR_OFF);
 | 
			
		||||
    } else if (vehicle_state.r2d_progress == R2D_INIT_SUCCESS) {
 | 
			
		||||
      text.setTypedText(T_R2D);
 | 
			
		||||
      bg.setColor(COLOR_OK);
 | 
			
		||||
    } else {
 | 
			
		||||
      text.setTypedText(T_TS);
 | 
			
		||||
      bg.setColor(COLOR_TS);
 | 
			
		||||
    }
 | 
			
		||||
    break;
 | 
			
		||||
  case DriverViewStatusType::AMS:
 | 
			
		||||
    text.setTypedText(T_AMS);
 | 
			
		||||
    bg.setColor(vehicle_state.ts_state == TS_ERROR ? COLOR_ERROR : COLOR_OK);
 | 
			
		||||
    break;
 | 
			
		||||
  case DriverViewStatusType::SDC:
 | 
			
		||||
    text.setTypedText(T_SDC);
 | 
			
		||||
    bg.setColor(vehicle_state.sdc_closed ? COLOR_OK : COLOR_WARNING);
 | 
			
		||||
    break;
 | 
			
		||||
  case DriverViewStatusType::SCS:
 | 
			
		||||
    text.setTypedText(T_SCS);
 | 
			
		||||
    bg.setColor(vehicle_state.errors.err_scs ? COLOR_ERROR : COLOR_OK);
 | 
			
		||||
    break;
 | 
			
		||||
  case DriverViewStatusType::PDU:
 | 
			
		||||
    text.setTypedText(T_PDU);
 | 
			
		||||
    bg.setColor(vehicle_state.errors.err_pdu ? COLOR_ERROR : COLOR_OK);
 | 
			
		||||
    break;
 | 
			
		||||
  case DriverViewStatusType::INV:
 | 
			
		||||
    text.setTypedText(T_INV);
 | 
			
		||||
    if (vehicle_state.errors.err_invl || vehicle_state.errors.err_invr) {
 | 
			
		||||
      bg.setColor(COLOR_ERROR);
 | 
			
		||||
    } else if (vehicle_state.errors.invl_ready &&
 | 
			
		||||
               vehicle_state.errors.invr_ready) {
 | 
			
		||||
      bg.setColor(COLOR_OK);
 | 
			
		||||
    } else {
 | 
			
		||||
      bg.setColor(COLOR_OFF);
 | 
			
		||||
    }
 | 
			
		||||
    break;
 | 
			
		||||
  }
 | 
			
		||||
  text.invalidate();
 | 
			
		||||
  bg.invalidate();
 | 
			
		||||
}
 | 
			
		||||
@ -22,6 +22,7 @@ void DriverViewPresenter::vehicleStateUpdated() {
 | 
			
		||||
  updateErrorPopup();
 | 
			
		||||
 | 
			
		||||
  view.updateFieldValues();
 | 
			
		||||
  view.updateStatusItems();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void DriverViewPresenter::nextScreen() {
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,10 @@
 | 
			
		||||
#include "gui/common/NamedField.hpp"
 | 
			
		||||
#include "gui/containers/DriverViewField.hpp"
 | 
			
		||||
#include "gui/containers/DriverViewStatusItem.hpp"
 | 
			
		||||
#include "gui/driverview_screen/DriverViewPresenter.hpp"
 | 
			
		||||
#include "texts/TextKeysAndLanguages.hpp"
 | 
			
		||||
#include "touchgfx/Callback.hpp"
 | 
			
		||||
#include "touchgfx/Drawable.hpp"
 | 
			
		||||
#include "touchgfx/Unicode.hpp"
 | 
			
		||||
#include "vehicle.h"
 | 
			
		||||
#include <gui/driverview_screen/DriverViewView.hpp>
 | 
			
		||||
@ -16,6 +19,12 @@ void DriverViewView::setupScreen() {
 | 
			
		||||
  for (size_t i = 0; i < NUM_FIELDS; i++) {
 | 
			
		||||
    getField(i).setType(fieldTypes[i]);
 | 
			
		||||
  }
 | 
			
		||||
  statusTS_R2D.setType(DriverViewStatusType::TS_R2D);
 | 
			
		||||
  statusAMS.setType(DriverViewStatusType::AMS);
 | 
			
		||||
  statusSDC.setType(DriverViewStatusType::SDC);
 | 
			
		||||
  statusSCS.setType(DriverViewStatusType::SCS);
 | 
			
		||||
  statusPDU.setType(DriverViewStatusType::PDU);
 | 
			
		||||
  statusINV.setType(DriverViewStatusType::INV);
 | 
			
		||||
  fieldTypeSelection.setNumberOfItems(DataFieldType_COUNT);
 | 
			
		||||
  // int tireThresholds[4] = {35, 40, 50, 60};
 | 
			
		||||
  // tireTempFL.setTempThresholds(tireThresholds);
 | 
			
		||||
@ -57,6 +66,22 @@ void DriverViewView::updateFieldValues() {
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class StatusItemUpdateCallback
 | 
			
		||||
    : public touchgfx::GenericCallback<touchgfx::Drawable &> {
 | 
			
		||||
  virtual void execute(Drawable &item) override {
 | 
			
		||||
    DriverViewStatusItem &statusItem =
 | 
			
		||||
        static_cast<DriverViewStatusItem &>(item);
 | 
			
		||||
    statusItem.update();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  virtual bool isValid() const override { return true; }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void DriverViewView::updateStatusItems() {
 | 
			
		||||
  StatusItemUpdateCallback cb;
 | 
			
		||||
  statusItems.forEachChild(&cb);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void DriverViewView::setTemps(const Temperatures &temps) {
 | 
			
		||||
  brakeTempFL.setTemp(roundf(temps.brake_fl));
 | 
			
		||||
  brakeTempFR.setTemp(roundf(temps.brake_fr));
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user