{"id":235,"date":"2018-07-10T18:53:03","date_gmt":"2018-07-10T10:53:03","guid":{"rendered":"https:\/\/fick707.com\/?p=235"},"modified":"2024-08-01T10:23:37","modified_gmt":"2024-08-01T02:23:37","slug":"iotstudy04-lib","status":"publish","type":"post","link":"https:\/\/fick707.com\/?p=235","title":{"rendered":"\u4e00\u4e2ajava\u5de5\u7a0b\u5e08\u7684IOT\u5165\u95e8\u4e4b\u8def04&#8211;\u7c7b\u5e93\u3001\u6570\u636e\u6301\u4e45\u5316"},"content":{"rendered":"<h2>\u4e66\u63a5\u4e0a\u6587<\/h2>\n<p>\u6628\u5929\u5df2\u7ecfhello world\u4e86\uff0c\u6211\u4eec\u5df2\u7ecf\u8fdb\u5165\u4e86\u5d4c\u5165\u5f0f\u5f00\u53d1\u7684\u4e16\u754c\u3002<\/p>\n<h2>\u53d1\u73b0\u95ee\u9898<\/h2>\n<p>\u5f88\u591a\u573a\u666f\uff0c\u9700\u8981\u5c06\u914d\u7f6e\u4fe1\u606f\u4fdd\u5b58\u5230\u677f\u5b50\u4e0a\uff0c\u5373\u4f7f\u65ad\u7535\u4e5f\u65e0\u59a8\u3002\u5982\u4f55\u641e\u5462\uff1f<\/p>\n<h2>\u627e\u7b54\u6848<\/h2>\n<p>\u641c\u7d22\u53d1\u73b0\uff1a<\/p>\n<ol>\n<li>arduino \u7684\u6240\u6709\u677f\u5b50\u90fd\u5185\u7f6e\u6709\u201c\u7535\u53ef\u64e6\u53ef\u7f16\u7a0b\u53ea\u8bfb\u5b58\u50a8\u5668\u201d&#8211;\u4e00\u79cd\u6389\u7535\u540e\u6570\u636e\u4e0d\u4e22\u5931\u7684\u5b58\u50a8\u82af\u7247\u3002\u82f1\u6587\u7b80\u79f0\uff1aEEPROM (Electrically Erasable Programmable Read-Only Memory)\u3002\u4ee5\u6211\u624b\u91cc\u7684r3\u4e3a\u4f8b\uff0c\u5c31\u67091K\u7684\u5b58\u50a8\u7a7a\u95f4\u3002<\/li>\n<li>Arduino \u63d0\u4f9b\u4e86\u7c7b\u5e93\uff1aEEPROM\uff0c\u5b9e\u73b0\u5c06\u6570\u636e\u6301\u4e45\u5316\u5230\u5b58\u50a8\u82af\u7247\u4e2d\u3002<\/li>\n<li>EEPROM API\uff0c\u53ea\u80fd\u5c06\u3010\u5b57\u8282\u578b\u3011\u7684\u6570\u636e\u7684\u5b58\u5165EEPROM\uff0c\u4e5f\u5c31\u662f\u4e00\u6b21\u53ea\u80fd\u5199\u51651\u4e2a\u5b57\u8282\u3002\u5982\u679c\u8981\u5b58\u50a8\u591a\u4e2a\u5b57\u8282\u7684\u6570\u636e\u7c7b\u578b\uff0c\u53c8\u9700\u8981\u600e\u4e48\u505a\u5462\uff1f<\/li>\n<\/ol>\n<h1>\u5b9e\u8df5<\/h1>\n<p>\u6211\u4eca\u5929\u8981\u505a\u7684\u5c31\u662f\u5b9e\u73b0\u6d6e\u70b9\u578b\u6570\u636e\u7684\u5b58\u3001\u53d6\u7c7b\u5e93\uff0c\u5982\u4f55\u5199\u4e00\u4e2a\u7c7b\u5e93\u5462\uff1f<br \/>\n<a href=\"https:\/\/www.arduino.cc\/en\/Hacking\/LibraryTutorial\">\u54c8\u54c8\uff0c\u5b98\u7f51\u6709\u5b8c\u7f8e\u6559\u7a0b<\/a><\/p>\n<p>\u6211\u5148\u6839\u636e\u6559\u7a0b\u5b9e\u73b0\u4e86\u5b83\u7684\u5b98\u65b9\u793a\u4f8b\u7c7b\u5e93\uff1aMorse\uff08\u8ba9LED\u95ea\u51faSOS\u4fe1\u53f7\uff09\u3002<br \/>\n\u518d\u6765\u5b9e\u73b0\u6211\u7684\u7c7b\u5e93\uff0c\u54c8\u54c8<\/p>\n<h2>\u6280\u672f\u65b9\u6848\u9009\u578b<\/h2>\n<p><a href=\"https:\/\/blog.csdn.net\/sdlgq\/article\/details\/51931900\">\u641c\u7d22\u5230\u4e86\u4e00\u7bc7\u6587\u7ae0<\/a>\uff0c\u6587\u4e2d\u4ecb\u7ecd\uff0c\u7528\u201c\u5171\u7528\u4f53\u201d\u53ef\u4ee5\u65b9\u4fbf\u5b9e\u73b0\u6d6e\u70b9\u578b\u6570\u636e\u7684\u5b58\u3001\u53d6\uff1b<\/p>\n<h3>\u4e86\u89e3\u4e00\u4e0b\u6280\u672f\u6982\u5ff5<\/h3>\n<p><code>\u5171\u7528\u4f53<\/code>\uff1a\u5c06\u51e0\u4e2a\u4e0d\u540c\uff08\u7c7b\u578b\u4e0d\u540c\uff0c\u4f46\u957f\u5ea6\u76f8\u540c\uff09\u7684\u53d8\u91cf\u653e\u5230\u540c\u4e00\u6bb5\u5185\u5b58\u4e2d\uff0c\u5171\u540c\u5360\u7528\u8fd9\u4e00\u6bb5\u5185\u5b58\u6570\u636e\uff0c\u4f7f\u5404\u53d8\u91cf\u7684\u5185\u5b58\u6570\u636e\u59cb\u7ec8\u4fdd\u6301\u4e00\u81f4\u3002<\/p>\n<p>\u4f8b\u5982\uff1a\u4e00\u4e2afloat\u7c7b\u578b\u7684\u6570\u636e\uff0c\u9700\u8981\u5360\u75284\u4e2a\u5b57\u8282\u7684\u5b58\u50a8\u7a7a\u95f4\u3002\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u628a\u4e00\u4e2afloat\u62c6\u5206\u4e3a4\u4e2a\u5b57\u8282\uff0c\u7136\u540e\u9010\u5b57\u8282\u7684\u5199\u5165EEPROM\uff0c\u6765\u8fbe\u5230\u4fdd\u5b58float\u6570\u636e\u7684\u76ee\u7684\u3002\u4f46\u662f\u624b\u52a8\u8ba1\u7b97\u7684\u8bdd\uff0c\u6bd4\u8f83\u9ebb\u70e6\u3002<br \/>\n\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528\u5171\u7528\u4f53\uff0c\u901a\u8fc7\u5176\u5b83\u6570\u636e\u7ed3\u679c\uff0c\u5feb\u6377\u7684\u628afloat\u6570\u636e\u62c6\u5206\u4e3a4\u4e2a\u5b57\u8282\u3002<\/p>\n<ol>\n<li>\u9996\u5148\u5b9a\u4e49\u4e00\u4e2a\u540d\u4e3adata\u7684\u5171\u7528\u4f53\u7ed3\u6784\uff0c\u5171\u7528\u4f53\u4e2d\u6709\u4e24\u4e2a\u7c7b\u578b\u4e0d\u540c\u7684\u6210\u5458\u53d8\u91cf\uff1a\n<pre><code class=\"\">union data\n {\n   float a;  \/\/ \u6d6e\u70b9\u578b\uff0c\u5360\u75284\u4e2a\u5b57\u8282\n   byte b[4];  \/\/ \u5b57\u8282\u578b\u6570\u7ec4\uff0c\u5360\u75284\u4e2a\u5b57\u8282\u3002\n   \/\/ \u8fd9\u4e24\u4e2a\u7c7b\u578b\u7684\u53d8\u91cf\u90fd\u662f\u5360\u75284\u4e2a\u5b57\u8282\uff0c\n   \/\/ \u4e14\u662f\u76f8\u540c\u76844\u4e2a\u5b57\u8282\uff0c\u6240\u4ee5\u80fd\u59cb\u7ec8\u4fdd\u6301\u6570\u636e\u4e00\u81f4\uff0c\n   \/\/ \u5176\u4e2d\u4e00\u4e2a\u53d8\u4e86\uff0c\u53e6\u4e00\u4e2a\u4e5f\u968f\u4e4b\u6539\u53d8\u3002\n };\n<\/code><\/pre>\n<\/li>\n<li>\u518d\u7533\u660e\u4e00\u4e2adata\u7c7b\u578b\u7684\u53d8\u91cfcol\uff1a\n<pre><code class=\"\">data col;\n<\/code><\/pre>\n<\/li>\n<li>\u73b0\u5728\u4f60\u53ef\u4ee5\u901a\u8fc7 col.a \u8bbf\u95ee\u8fd9\u4e2a\u5171\u7528\u4f53\u4e2d\u7684 float \u7c7b\u578b\u6210\u5458 a\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7 col.b \u8bbf\u95ee\u8fd9\u4e2a\u5171\u7528\u4f53\u4e2d\u7684 byte \u7c7b\u578b\u6210\u5458 b\u3002<br \/>\ncol.a \u548c col.b \u5171\u540c\u5360\u7528\u56db\u4e2a\u5b57\u8282\u7684\u5730\u5740\u3002<br \/>\n\u7ed9 col.a \u8d4b\u503c\u540e\uff0c\u901a\u8fc7 col.b \u5373\u53ef\u62c6\u5206 float \u4e3a4\u4e2a\u5b57\u8282\u3002<\/p>\n<\/li>\n<\/ol>\n<p>\u597d\u4e86\uff0c\u4e86\u89e3\u4e86\u201c\u5171\u540c\u4f53\u201d\uff0c\u6211\u4eec\u6765\u5199\u8fd9\u4e2a\u7c7b\u5e93\u5427\u3002<\/p>\n<h2>\u9996\u5148\u5b9a\u4e49.h\u6587\u4ef6\uff08\u5934\u6587\u4ef6\uff09<\/h2>\n<p>\u5199C\u7684\u4eba\u5bf9\u8fd9\u4e2a\u90fd\u5f88\u719f\u6089\uff08\u5199java\u7684\u4e5f\u4e0d\u964c\u751f\uff0c\u54c8\u54c8\uff0c\u6bd5\u7adf\u6211\u4eec\u521d\u5b66\u7f16\u7a0b\u8bed\u8a00\u65f6\uff0c\u4e5f\u63a5\u89e6\u4e86C\uff09\uff1b<\/p>\n<p>FloatEepRom.h<\/p>\n<pre><code>    \/**\n     * FloatEepRom.h - Library for writing float data to EEPROM.\n     * Created by Fick Song, Ma6 31, 2018.\n     * For personal use.\n     * \u7528\u4e8e\u6301\u4e45\u5316\/\u8bfb\u53d6\u6d6e\u70b9\u578b\u6570\u636e\n     *\/\n    #ifndef FloatEepRom_h\n    #define FloatEepRom_h\n    #include \"Arduino.h\"\n    union FloatUnionData\n    {\n        float f;    \/\/ \u6d6e\u70b9\u578b\uff0c\u5360\u75284\u4e2a\u5b57\u8282\n        byte b[4];  \/\/ \u5b57\u8282\u578b\u6570\u7ec4\uff0c\u5360\u75284\u4e2a\u5b57\u8282\u3002\n    };\n    class FloatEepRom\n    {\n        public:\n            FloatEepRom(void);\n            void writeFloat(int addr,float value);\n            float readFloat(int addr);\n    };\n\n    #endif\n<\/code><\/pre>\n<h2>\u63a5\u7740\u662fcpp\u6587\u4ef6<\/h2>\n<p>FloatEepRom.cpp<\/p>\n<pre><code>    \/*\n     * FloatEepRom.cpp - Library for flashing Morse code.\n     * Created by Fick Song, May 31, 2018.\n     * For testing Library creating.\n     *\/\n\n    #include \"Arduino.h\"\n    #include \"FloatEepRom.h\"\n    #include &lt;EEPROM.h&gt;\n\n    FloatEepRom::FloatEepRom()\n    {}\n\n    void FloatEepRom::writeFloat(int addr,float value)\n    {\n        if((addr + 4) &gt;= EEPROM.length()){\n            return;\n        }\n        FloatUnionData data;\n        data.f = value;\n        for(int i=0;i&lt;4;i++)\n            EEPROM.update(addr + i, data.b[i]);\n    }\n\n    float FloatEepRom::readFloat(int addr)\n    {\n        if((addr + 4) &gt;= EEPROM.length()){\n            return 0.0;\n        }\n        FloatUnionData data;\n        for(int i=0;i&lt;4;i++){\n            data.b[i]=EEPROM.read(addr + i);\n        }\n        return data.f;\n    }\n<\/code><\/pre>\n<h2>\u7136\u540e\u662fkeywords.txt\u6587\u4ef6<\/h2>\n<p>keywords.txt<\/p>\n<pre><code>    FloatEepRom KEYWORD1\n    writeFloat  KEYWORD2\n    readFloat   KEYWORD2\n<\/code><\/pre>\n<p>\u5982\u679c\u6ca1\u6709\u8fd9\u4e2a\u6587\u4ef6\uff0c\u5728IDE\u91cc\u7528\u6211\u4eec\u7684\u7c7b\u5e93\u53ca\u65b9\u6cd5\u65f6\uff0c\u4e0d\u4f1a\u6709\u9ad8\u4eae\u63d0\u793a\uff0c\u52a0\u4e86\u8fd9\u4e2a\u6587\u4ef6\uff0c\u5c31\u884c\u4e86\u3002<br \/>\n\u5176\u4e2dKEYWORD1\u8868\u793a\uff0cFloatEepRom\u662f\u4e2a\u7c7b\uff1b<br \/>\nKEYWORD2\u8868\u793a\uff0cwriteFloat\uff0creadFloat\u662f\u65b9\u6cd5\uff0cIDE\u5c31\u4f1a\u6839\u636e\u89c4\u5219\u9ad8\u4eae\u663e\u793a\u6210\u9ec4\u8272\u548c\u7070\u8272\uff1b<br \/>\n<font color=red>\u6ce8\u610f\uff0c\u6587\u4ef6\u4e2d\u6bcf\u4e00\u884c\u4e2d\u95f4\u662f\u7528\u5236\u8868\u7b26\u5206\u9694\u7684\u3002\u4e0d\u662f\u7a7a\u683c\u3002<\/font><\/p>\n<h2>\u5c06\u6587\u4ef6\u653e\u5165\u7c7b\u5e93\u76ee\u5f55<\/h2>\n<ol>\n<li>\u5148\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6\u5939FloatEepRom\uff08\u53ef\u4ee5\u81ea\u5b9a\u4e49\u6587\u4ef6\u5939\u7684\u540d\u5b57\uff09\uff0c\u5c06\u4e0a\u8ff0\u4e09\u4e2a\u6587\u4ef6\u653e\u8fdb\u6765\uff1b<\/li>\n<li>\u5c06\u4e0a\u8ff0\u6587\u4ef6\u5939\u6574\u4f53\u653e\u5165Arduino IDE\u7684\u7c7b\u5e93\u6587\u4ef6\u5939\u4e0b\uff0c\u6211\u7684mac\uff0c\u76ee\u5f55\u662f\u201c\/Users\/xxx\/Library\/Arduino15\/packages\/arduino\/hardware\/avr\/1.6.21\/libraries\u201d,<br \/>\n\u52a0\u5230\u8fd9\u4e2a\u76ee\u5f55\u4e0b\uff0cIDE\u4f1a\u663e\u793a\u4e3a\u201c\u5185\u7f6e\u7c7b\u5e93\u201d\uff1b\u53e6\u5916\u4e00\u4e2a\u76ee\u5f55\u662f\u201c\/Users\/xxxx\/Documents\/Arduino\/libraries\u201d,\u8fd9\u4e2a\u76ee\u5f55\u662f\u7528\u6237\u81ea\u5b9a\u4e49\u7c7b\u5e93\u7684\u8def\u5f84\uff1b<\/p>\n<p>\u5982\u679c\u60f3\u627e\u5230\u5185\u7f6e\u7c7b\u5e93\u76ee\u5f55\uff0c\u6253\u5f00Arduino IDE\u8f6f\u4ef6\uff0c\u6253\u5f00\u9996\u9009\u9879\u9875\u9762\uff0c\u518d\u6839\u636e\u914d\u7f6e\u6587\u4ef6\u6240\u5728\u76ee\u5f55\u5f80\u4e0b\u627e\uff0c\u5c31\u53ef\u4ee5\u627e\u5230\u4e86\u3002<\/p>\n<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"\/pics\/iot\/04\/0531_00002.png\" alt=\"&quot;\u6253\u5f00\u9996\u9009\u9879&quot;\" \/><\/p>\n<p>\u70b9\u51fb\u914d\u7f6e\u6587\u4ef6\uff0c\u8fdb\u5165\u5176\u6240\u5728\u76ee\u5f55<br \/>\n<img decoding=\"async\" src=\"\/pics\/iot\/04\/0531_00001.png\" alt=\"\" \/><\/p>\n<p>\u5728\u5f80\u4e0b\u627e\u5373\u53ef,\u76f4\u5230libraries\uff0c\u5373\u662f\u653e\u7c7b\u5e93\u7684\u5730\u65b9\u3002<br \/>\n<img decoding=\"async\" src=\"\/pics\/iot\/04\/0531_00003.png\" alt=\"\" \/><\/p>\n<p>OK\u4e86\uff0c\u7c7b\u5e93\u5df2\u7ecf\u5b8c\u6210\u4e86\u3002\u91cd\u542fIDE\u5c31\u80fd\u7528\u5b83\u4e86\u3002<br \/>\n<img decoding=\"async\" src=\"\/pics\/iot\/04\/0531_00004.png\" alt=\"\" \/><\/p>\n<p>2018.05.31<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e66\u63a5\u4e0a\u6587 \u6628\u5929\u5df2\u7ecfhello world\u4e86\uff0c\u6211\u4eec\u5df2\u7ecf\u8fdb\u5165\u4e86\u5d4c\u5165\u5f0f\u5f00\u53d1\u7684\u4e16\u754c\u3002 \u53d1\u73b0\u95ee\u9898 \u5f88\u591a\u573a\u666f\uff0c\u9700 &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[7],"series":[27],"class_list":["post-235","post","type-post","status-publish","format-standard","hentry","category-iot","tag-iot","series-iot_step_by_step"],"_links":{"self":[{"href":"https:\/\/fick707.com\/index.php?rest_route=\/wp\/v2\/posts\/235"}],"collection":[{"href":"https:\/\/fick707.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fick707.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fick707.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fick707.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=235"}],"version-history":[{"count":1,"href":"https:\/\/fick707.com\/index.php?rest_route=\/wp\/v2\/posts\/235\/revisions"}],"predecessor-version":[{"id":236,"href":"https:\/\/fick707.com\/index.php?rest_route=\/wp\/v2\/posts\/235\/revisions\/236"}],"wp:attachment":[{"href":"https:\/\/fick707.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fick707.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fick707.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=235"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/fick707.com\/index.php?rest_route=%2Fwp%2Fv2%2Fseries&post=235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}