DALI send/recv library see: https://os.mbed.com/users/okini3939/code/DALI/

Dependencies:   mbed DALI

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "DALI.h"
00003 
00004 #define DALI_ADDRESS 1
00005 
00006 Serial pc(USBTX, USBRX);
00007 DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4);
00008 DALI dali(p22, p21); // tx, rx
00009 
00010 int main() {
00011 
00012     pc.baud(115200);
00013     pc.printf("DALI sample\r\n");
00014     led1 = 1;
00015 
00016     for (;;) {
00017         if (dali.readable()) {
00018             int f, a, v;
00019             led3 = 1;
00020             dali.read((enum DALI::DALI_FRAME*)&f, &a, &v);
00021             pc.printf("recv f=%d a=%d v=%d\r\n", f, a, v);
00022         }
00023 
00024         if (pc.readable()) {
00025             char c = pc.getc();
00026             led4 = 1;
00027             if (c >= '0' && c <= '9') {
00028                 dali.write(DALI::FORWARD_SHORT_DAP, DALI_ADDRESS, (c - '0') * 20);
00029                 dali.write(DALI::FORWARD_GROUP_DAP, DALI_ADDRESS, (c - '0') * 20);
00030             } else
00031             if (c == ' ') {
00032                 dali.write(DALI::FORWARD_SHORT_DAP, DALI_ADDRESS, 255);
00033             } else
00034             if (c == 'a') {
00035                 dali.write(DALI::FORWARD_SHORT_IAP, DALI_ADDRESS, DALI::OFF); // OFF
00036             } else
00037             if (c == 'b') {
00038                 dali.write(DALI::FORWARD_SHORT_IAP, DALI_ADDRESS, DALI::RECALL_MAX_LEVEL); // RECALL_MAX_LEVEL
00039             } else
00040             if (c == 'c') {
00041                 dali.write(DALI::FORWARD_SHORT_IAP, DALI_ADDRESS, DALI::QUERY_STATUS); // QUERY_STATUS
00042             } else
00043             if (c == 'd') {
00044                 dali.write(DALI::FORWARD_GROUP_DAP, 63, 127);
00045             }
00046         }
00047 
00048         wait_ms(1);
00049         led2 = ! led2;
00050         led3 = led4 = 0;
00051     }
00052 }