Mbed studio does not recognize the library

I need to write a program in mbed studio, here are the requirements.

What am I doing
The board serves as a demonstration device for the villain from the detective story: It behaves like a time bomb, instead of wires that must be connected correctly, we will have some colored areas of the display (“buttons”).

The time until the explosion lights up on the display, which you count down (for this you use the Ticker), which adjusts the time every 100 ms – you start at 1 minute. The fact that the board explodes (resets) every 1 minute is handled by the Watchdog – set it to 1 minute when not stopped or reset and the board will restart.

Next, you light up three buttons (rectangles or something on the display) – one of them stops the timer, but we don’t know which one – it’s the equivalent of connecting wires in an exciting detective story. Create a separate thread for reading the touchscreen. You alternate the functions of the buttons randomly after the reset (so that we don’t know which is which). Each button has its own event flag (see EventFlags). The features are as follows:

explode straight away (board lights up red and resets)
reset (we reset the timer for the watchdog and also for the countdown display)
stop (we stop the watchdog and stop the countdown – the display does nothing)
Separate threads wait for events from the buttons, which arrange the corresponding function and the correct display update.

Threads you need:

Screen touch control (generates events)
Regular update of the countdown on the display (according to the Ticker)
Three threads for three events from “buttons”
Locks and other things:

Display lock – different threads write to it, synchronization is very convenient here
Lock for working with EventFlags (4 threads work with them asynchronously)
Other mbed components:

Ticker
Watchdog
EventFlags

The first photo is a photo of where the mistakes are. But the thing is that I imported the library
mistakes
library

This is my code

#include "mbed.h"
#include "stm32746g_discovery_lcd.h"
#include "SPI_TFT.h" 

const int MAX_TIME = 60;  
const uint32_t RESET_TIME = 60000; 

Ticker ticker;
Watchdog &watchdog = Watchdog::get_instance();
Mutex lcdMutex;
EventFlags buttonFlags;
int countdown = MAX_TIME;

#define EXPLODE_FLAG 0x01
#define RESET_FLAG 0x02
#define STOP_FLAG 0x04

const int TOUCH_AREA_X = 100;
const int TOUCH_AREA_Y = 100;
const int TOUCH_AREA_WIDTH = 50;
const int TOUCH_AREA_HEIGHT = 50;

void updateDisplay() {
lcdMutex.lock();
BSP_LCD_Clear(LCD_COLOR_BLACK);
BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
BSP_LCD_SetFont(&Font24);
char str[32];
sprintf(str, "Time left: %d sec", countdown);
BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)str, CENTER_MODE);
lcdMutex.unlock();
}

void countdownFunction() {
while (true) {
    if (countdown > 0) {
        countdown--;
        updateDisplay();
    }
    ThisThread::sleep_for(1000ms);
}
}

void touchscreenFunction() {
SPI_TFT ts(D11, D12, D13, D10, D9, "touchscreen");
int x, y;

while (true) {
    if (ts.getTouch(&x, &y)) {
        if (x >= TOUCH_AREA_X && x < TOUCH_AREA_X + TOUCH_AREA_WIDTH &&
            y >= TOUCH_AREA_Y && y < TOUCH_AREA_Y + TOUCH_AREA_HEIGHT) {
            buttonFlags.set(EXPLODE_FLAG);
        }
    }
    ThisThread::sleep_for(100ms); 
}
}

void explodeFunction() {
while (true) {
    buttonFlags.wait_any(EXPLODE_FLAG);
    NVIC_SystemReset(); 
}
}

void resetFunction() {
while (true) {
    buttonFlags.wait_any(RESET_FLAG);
    countdown = MAX_TIME;
    updateDisplay();
    watchdog.kick();
}
}

void stopFunction() {
while (true) {
    buttonFlags.wait_any(STOP_FLAG);
    ticker.detach(); 
    watchdog.stop(); 
}
}

int main() {
BSP_LCD_Init();
BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS);
BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER);
BSP_LCD_DisplayOn();
BSP_LCD_Clear(LCD_COLOR_BLACK);

watchdog.start(RESET_TIME);

ticker.attach(&countdownFunction, 1s);

Thread touchThread;
touchThread.start(&touchscreenFunction);

Thread explodeThread;
explodeThread.start(&explodeFunction);

Thread resetThread;
resetThread.start(&resetFunction);

Thread stopThread;
stopThread.start(&stopFunction);

while (true) {
    ThisThread::sleep_for(osWaitForever);
}
}

trying googling and use chatgpt

  • 1

    A note about ChatGPT: It is a language model, and that language is not C++. It does not know how to program; all it knows is how to string together tokens into convincing text. If your problem has been experienced and answered by many and those answers have been included in the model’s training set, you may get a good answer. But when you’re facing something rare or complicated, GPT is of little value, and worse, it lies!

    – 

Leave a Comment