Skip to content
Permalink
d3a46b7d74
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
44 lines (38 sloc) 1.13 KB
#include "mbed.h"
/* Mail */
typedef struct {
float voltage; /* AD result of measured voltage */
float current; /* AD result of measured current */
uint32_t counter; /* A counter value */
} mail_t;
Mail<mail_t, 16> mail_box;
Thread thread;
void send_thread(void)
{
uint32_t i = 0;
while (true) {
i++; // fake data update
mail_t *mail = mail_box.alloc();
mail->voltage = (i * 0.1) * 33;
mail->current = (i * 0.1) * 11;
mail->counter = i;
mail_box.put(mail);
ThisThread::sleep_for(1000);
}
}
int main(void)
{
thread.start(callback(send_thread));
while (true) {
// Non Blocking we coculd use try_get_for() to block
// Will also become blocking in a future release
osEvent evt = mail_box.get();
if (evt.status == osEventMail) {
mail_t *mail = (mail_t *)evt.value.p;
printf("\nVoltage: %0.2f V\n\r", mail->voltage);
printf("Current: %0.2f A\n\r", mail->current);
printf("Number of cycles: %lu\n\r", mail->counter);
mail_box.free(mail);
}
}
}