You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

54 lines
1.1 KiB

#include "shelf.h"
#include "item.h"
#include "pusher.h"
#include "led.h"
#include "coin.h"
using namespace std;
extern Pusher pusher;
extern Led led;
extern Coin coin;
Shelf::Shelf(int size)
: num_items(size) {
for(int i=0; i<size; i++) {
item.push_back(new Item(i));
}
}
void Shelf::reload(void) {
for(int i=0; i<num_items; i++) {
delete item.at(i);
}
item.clear();
for(int i=0; i<num_items; i++) {
item.push_back(new Item(i));
}
}
void Shelf::dispenseTask(void* parameters) {
Serial.println("dispensing");
if (coin.getMoney() >= 50) {
item.at(num)->quantity--;
led.changeAnimation(1, 0);
pusher.push(num);
coin.subtractMoney(50);
vTaskDelay(500 / portTICK_PERIOD_MS);
led.changeAnimation(2, 0);
vTaskDelay(7000 / portTICK_PERIOD_MS);
led.changeAnimation(0, 0);
} else {
led.changeAnimation(4,200);
}
vTaskDelete(NULL);
}
void Shelf::cTaskWrapper(void* parameters) {
static_cast<Shelf*>(parameters)->dispenseTask(NULL);
}
void Shelf::dispense(int num) {
this->num = num;
xTaskCreate(&cTaskWrapper, "dispenseTask", 1024, this, tskIDLE_PRIORITY+2, &dispenseTaskHandle);
}