diff --git a/NexSlider.cpp b/NexSlider.cpp new file mode 100644 index 00000000..3ec6d49 --- /dev/null +++ b/NexSlider.cpp @@ -0,0 +1,86 @@ +/** + * @file NexSlider.cpp + * + * API of NexSlider. + * + * @author Wu Pengfei (email:) + * @date 2015/8/11 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#include "NexSlider.h" + +/** + * Constructor,inherited NexTouch's constructor function. + * + */ +NexSlider::NexSlider(NexPid pid, NexCid cid, char *name, + NexTouchEventCb pop, void *pop_ptr) + :NexTouch(pid, cid, name, pop, pop_ptr) +{ +} + +/** + * Get the value of slider. + * + * @param number - an output parameter to save the value of slider. + * + * @retval true - success. + * @retval false - failed. + */ +bool NexSlider::getValue(uint32_t *number) +{ + String cmd = String("get "); + cmd += getObjName(); + cmd += ".val"; + sendCommand(cmd.c_str()); + return recvRetNumber(number); +} + +/** + * Set the value of slider. + * + * @param number - the value of slider. + * + * @retval true - success. + * @retval false - failed. + */ +bool NexSlider::setValue(uint32_t number) +{ + char buf[10] = {0}; + String cmd; + + utoa(number, buf, 10); + cmd += getObjName(); + cmd += ".val="; + cmd += buf; + + sendCommand(cmd.c_str()); + return recvRetCommandFinished(); +} + +/** + * Register slider pop callback function. + * + * @param pop - the pointer to picture pop callback function. + * @param ptr - the parameter to be transmitted to picture pop callback function. + */ +void NexSlider::attachPop(NexTouchEventCb pop, void *ptr) +{ + NexTouch::attachPop(pop, ptr); +} + +/** + * Unload slider pop callback function. + * + */ +void NexSlider::detachPop(void) +{ + NexTouch::detachPop(); +} + diff --git a/NexSlider.h b/NexSlider.h new file mode 100644 index 00000000..11aa2c1 --- /dev/null +++ b/NexSlider.h @@ -0,0 +1,38 @@ +/** + * @file NexSlider.h + * + * API of NexSlider. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#ifndef __NEXSLIDER_H__ +#define __NEXSLIDER_H__ +#ifdef __cplusplus +#include "NexTouch.h" + +/** + * NexSlider,subclass of NexTouch,provides simple methods to control slider component. + * + */ +class NexSlider: public NexTouch +{ +public: /* methods */ + NexSlider(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop = NULL, void *pop_ptr = NULL); + + void attachPop(NexTouchEventCb pop, void *ptr = NULL); + void detachPop(void); + + bool getValue(uint32_t *number); + bool setValue(uint32_t number); +}; + +#endif /* #ifdef __cplusplus */ +#endif /* #ifndef __NEXSLIDER_H__ */ diff --git a/examples/CompSlider/CompSlider.HMI b/examples/CompSlider/CompSlider.HMI new file mode 100644 index 00000000..cbea278 Binary files /dev/null and b/examples/CompSlider/CompSlider.HMI differ diff --git a/examples/CompSlider/CompSlider.ino b/examples/CompSlider/CompSlider.ino new file mode 100644 index 00000000..3e7b530 --- /dev/null +++ b/examples/CompSlider/CompSlider.ino @@ -0,0 +1,53 @@ +/** + * @example CompSlider.ino + * + * @par Show how to use API of class NexSlider. + * + * @author Wu Pengfei (email:) + * @date 2015/8/11 + * @copyright + * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#include "NexText.h" +#include "NexSlider.h" + + +NexText t0 = NexText(0, 2, "t0"); +NexSlider h0 = NexSlider(0, 1, "h0"); + +NexTouch *nex_listen_list[] = +{ + &h0, + NULL +}; + +void h0PopCallback(void *ptr) +{ + uint32_t number = 0; + char temp[10] = {0}; + + dbSerialPrintln("h0PopCallback"); + + h0.getValue(&number); + utoa(number, temp, 10); + t0.setText(temp); +} + + +void setup(void) +{ + nexInit(); + h0.attachPop(h0PopCallback); + dbSerialPrintln("setup done"); +} + +void loop(void) +{ + nexLoop(nex_listen_list); +} + diff --git a/examples/CompSlider/CompSlider.tft b/examples/CompSlider/CompSlider.tft new file mode 100644 index 00000000..e7e9e05 Binary files /dev/null and b/examples/CompSlider/CompSlider.tft differ