Arduino:M5Stack公式ライブラリがカスタムパターンを表示するときの問題を解決します

M5Stack開発ボードを購入しましたが、面白かったです。本質的に、それはまだESP32開発ボードですが、独自の充電式バッテリー、ディスプレイ画面、小さなスピーカー、ボタンなどを備えた、約5〜6センチ四方の小さな四角い箱にパッケージされており、非常に美しく実用的です。価格は安くはありませんが、結局のところ、いくつかの問題点は解決しているため、この問題は異なります。

M5公式ライブラリをインストールした後、組み込みのTFT_Flash_Bitmapがテストされ、正常に合格しました。ただし、これに基づいて、M5.Lcd.drawBitmapをさらにテストする予定です。これは、自分のパターンを使用するときに問題があることを示しています。画面「花の画面」です。しかし、この花のスクリーンでは、パターンがはっきりと見えますが、カラーシステムは完全に乱れています。

カスタムパターンは問題なく使用されてきたImageConvert565を使用して作成されているため、バイト生成ツールの要因を排除することができます。投機はディスプレイドライバの要素です。

デフォルトの場所(My Documents \ Arduino \ libraries \ M5Stack \ src)を開き、M5Display.hおよびM5Display.cppを確認します。大まかな分析の結果、TFT_eSPIライブラリにも基づいていることがわかりました。これは扱いが簡単です。いくつかのテストの結果、問題はsetSwapBytes(true)であることがわかりました;。falseをすべて正常に変更します。

既存の関数を直接変更するのは怖いので、M5Display.cppを開き、drawBitmap関数をコピーして貼り付け、独自のオーバーロードを追加し、新しいブールパラメーターを追加して、trueがこのパラメーターによって制御されるようにします。もちろん、これらの新しく作成された関数名もM5Display.hに投稿する必要があります。参照コードは次のとおりです。

cpp里:
///////////////////////////
void M5Display::drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, const uint16_t *data,bool swapBytes) {
  setSwapBytes(swapBytes);
  pushImage((int32_t)x0, (int32_t)y0, (uint32_t)w, (uint32_t)h, data);
}

void M5Display::drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, uint16_t *data,bool swapBytes) {
  setSwapBytes(swapBytes);
  pushImage((int32_t)x0, (int32_t)y0, (uint32_t)w, (uint32_t)h, data);
}

void M5Display::drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, const uint16_t *data, uint16_t transparent,bool swapBytes) {
  setSwapBytes(swapBytes);
  pushImage((int32_t)x0, (int32_t)y0, (uint32_t)w, (uint32_t)h, data, transparent);
}

void M5Display::drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, const uint8_t *data,bool swapBytes) {
  setSwapBytes(swapBytes);
  pushImage((int32_t)x0, (int32_t)y0, (uint32_t)w, (uint32_t)h, (const uint16_t*)data);
}

void M5Display::drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, uint8_t *data,bool swapBytes) {
  setSwapBytes(swapBytes);
  pushImage((int32_t)x0, (int32_t)y0, (uint32_t)w, (uint32_t)h, (uint16_t*)data);
}
//////////////////////////



头文件里:
void drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, const uint16_t *data ,bool swapBytes);
void drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, const uint8_t *data ,bool swapBytes);
void drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, uint16_t *data ,bool swapBytes);
void drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, uint8_t *data ,bool swapBytes);
void drawBitmap(int16_t x0, int16_t y0, int16_t w, int16_t h, const uint16_t *data, uint16_t transparent ,bool swapBytes);

公式コードでは、例のdrawIconは完全に無視でき、ネイティブのdrawImageを呼び出すだけです。Info.hは省略されています。例を参照して、実際のニーズに応じてコードを貼り付けてください。

#include <M5Stack.h>
#include "Info.h"

void setup()
{
  M5.begin();
  M5.Lcd.setBrightness(128);  //设置背光亮度
  M5.Lcd.fillScreen(TFT_BLACK);
  

  // Draw the icons
  // drawIcon不必用了
  //drawIcon(info, 0, 0, infoWidth, infoHeight);
  M5.Lcd.drawBitmap(0,0,infoWidth,infoHeight,info,false);

}

void loop()
{


}

さて、これは私の娘の好きな小さなリスのおもちゃです。

====新しい質問====

今度は画面を使わなくなりましたが、表示色が反転(マイナス)しています。彼の妹のことは思いつかない。とにかく、絵を作るときは、最初にそれを逆にし、時間があれば、ゆっくりと勉強します。

 

122件の元の記事を公開 61のよう 訪問数530,000以上

おすすめ

転載: blog.csdn.net/ki1381/article/details/88804713