Skip to content

Commit 9d7f5c2

Browse files
committed
drv_ds1820_simple.c: Implemented DS1820_SetResolution command
1 parent 6837c8e commit 9d7f5c2

File tree

5 files changed

+48
-4
lines changed

5 files changed

+48
-4
lines changed

sdk/OpenW600

src/driver/drv_ds1820_simple.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ J Standard 410
116116
#define SKIP_ROM 0xCC
117117
#define CONVERT_T 0x44
118118
#define READ_SCRATCHPAD 0xBE
119+
#define WRITE_SCRATCHPAD 0x4E
119120

120121
int OWReset(int Pin)
121122
{
@@ -285,13 +286,56 @@ int DS1820_getTemp()
285286
return t;
286287
}
287288

289+
commandResult_t Cmd_SetResolution(const void* context, const char* cmd, const char* args, int cmdFlags) {
290+
Tokenizer_TokenizeString(args, 0);
291+
if (Tokenizer_CheckArgsCountAndPrintWarning(cmd, 1)) {
292+
return CMD_RES_NOT_ENOUGH_ARGUMENTS;
293+
}
294+
int arg = Tokenizer_GetArgInteger(0);
295+
if (arg > 12 || arg < 9)
296+
return CMD_RES_BAD_ARGUMENT;
297+
298+
if (ds18_family != 0x28) {
299+
DS1820_LOG(ERROR, "DS1820_SetResolution not supported by sensor");
300+
return CMD_RES_UNKNOWN_COMMAND;
301+
}
302+
303+
uint8_t cfg = arg;
304+
cfg = cfg - 9;
305+
cfg = cfg * 32;
306+
cfg |= 0x1F;
307+
308+
if(OWReset(Pin) == 0)
309+
{
310+
DS1820_LOG(ERROR, "WriteScratchpad Reset failed");
311+
return CMD_RES_ERROR;
312+
}
313+
314+
OWWriteByte(Pin, SKIP_ROM);
315+
OWWriteByte(Pin, WRITE_SCRATCHPAD); //Write Scratchpad command
316+
OWWriteByte(Pin, 0x7F); //TH
317+
OWWriteByte(Pin, 0x80); //TL
318+
OWWriteByte(Pin, cfg); //CFG
319+
320+
//temperature conversion was interrupted
321+
dsread = 0;
322+
323+
return CMD_RES_OK;
324+
}
325+
288326
// startDriver DS1820 [conversionPeriod (seconds) - default 15]
289327
void DS1820_driver_Init()
290328
{
291329
ds18_conversionPeriod = Tokenizer_GetArgIntegerDefault(1, 15);
292330
lastconv = 0;
293331
dsread = 0;
294332
ds18_family = 0;
333+
334+
//cmddetail:{"name":"DS1820_SetResolution","args":"[int]",
335+
//cmddetail:"descr":"Sets resolution for connected DS1820 sensor (9/10/11/12 bits)",
336+
//cmddetail:"fn":"Cmd_SetResolution","file":"drv/drv_ds1820_simple.c","requires":"",
337+
//cmddetail:"examples":""}
338+
CMD_RegisterCommand("DS1820_SetResolution", Cmd_SetResolution, NULL);
295339
};
296340

297341
void DS1820_AppendInformationToHTTPIndexPage(http_request_t* request)

0 commit comments

Comments
 (0)