wenzel reichmuth / Mbed OS bel-example-pentabarf

Dependencies:   BleSerial Cli ConfigFile MbedJSONValue

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Hardware.cpp Source File

Hardware.cpp

00001 #include "Hardware.h"
00002 
00003  Hardware::Hardware()
00004 {
00005 
00006 }
00007   
00008 InitResult Hardware::init()
00009 {
00010     //this->led1 = new DigitalOut(LED1, 1);
00011     this->led = new PwmOut(LED1);
00012     this->led->period_ms(20);
00013     this->led->write(0.0f);    
00014     this->pc = new Serial(USBTX, USBRX);// tx, rx
00015     
00016     this->initCli();
00017     
00018     MbedJSONValue demo;
00019    std::string s;
00020  
00021    //fill the object
00022    demo["my_array"][0] = "demo_string";
00023    demo["my_array"][1] = 10;
00024    demo["my_boolean"] = false;
00025  
00026    //serialize it into a JSON string
00027    s = demo.serialize();
00028    this->pc->printf("json: %s\r\n", s.c_str());
00029     
00030     return InitResultOk;
00031 }
00032 
00033 InitResult Hardware::initCli(){
00034     //this->pc->printf("INIT CLI\n"); 
00035     this->myCli = new Cli(this->pc, "#~> ", 50, 10);
00036     this->myCli->setEcho(true);
00037     this->myCli->appendCmd("print", "prints hello world to stream", static_cast<void*> (this), Hardware::cb_print);
00038     this->myCli->welcome();
00039     this->myCli->prompt();
00040     
00041     BLE &ble = BLE::Instance();
00042     this->bleSerial = new BleSerial(ble);
00043     this->bleCli = new Cli(this->bleSerial, "#~> ", 50, 10);
00044     this->bleCli->appendCmd("print", "prints hello world to stream", static_cast<void*> (this), Hardware::cb_print);
00045     this->bleCli->setEcho(true);
00046     this->bleCli->welcome();
00047     this->bleCli->prompt();
00048     
00049     return InitResultOk;
00050 }
00051 
00052 CbResult Hardware::cb_print(void* pObject, va_list args)
00053 {
00054     if (!pObject)
00055     {
00056         return CbResultError;
00057     }
00058 
00059     char* s = static_cast<char*>(va_arg(args, char*));
00060     Stream *io = static_cast<Stream*>(va_arg(args, Stream*));
00061     va_end(args);
00062 
00063     Hardware* mySelf = static_cast<Hardware*> (pObject);
00064 
00065     //mySelf->pc->printf("HALLO WELT %s\n", s);
00066     io->printf("HALLO WELT %s\n", s);
00067 
00068     return CbResultOk;
00069 }