Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
NoABug
arduino-esp32
提交
1e3717bc
A
arduino-esp32
项目概览
NoABug
/
arduino-esp32
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
arduino-esp32
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
1e3717bc
编写于
2月 15, 2023
作者:
R
Rodrigo Garcia
提交者:
GitHub
2月 15, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adds pseudo random numbers generation (#7848)
上级
8873adb1
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
26 addition
and
4 deletion
+26
-4
cores/esp32/Arduino.h
cores/esp32/Arduino.h
+11
-3
cores/esp32/WMath.cpp
cores/esp32/WMath.cpp
+15
-1
未找到文件。
cores/esp32/Arduino.h
浏览文件 @
1e3717bc
...
...
@@ -137,9 +137,19 @@ typedef unsigned int word;
void
setup
(
void
);
void
loop
(
void
);
// The default is using Real Hardware random number generator
// But when randomSeed() is called, it turns to Psedo random
// generator, exactly as done in Arduino mainstream
long
random
(
long
);
long
random
(
long
,
long
);
#endif
// Calling randomSeed() will make random()
// using pseudo random like in Arduino
void
randomSeed
(
unsigned
long
);
// Allow the Application to decide if the random generator
// will use Real Hardware random generation (true - default)
// or Pseudo random generation (false) as in Arduino MainStream
void
useRealRandomGenerator
(
bool
useRandomHW
);
#endif
long
map
(
long
,
long
,
long
,
long
,
long
);
#ifdef __cplusplus
...
...
@@ -207,8 +217,6 @@ void setToneChannel(uint8_t channel = 0);
void
tone
(
uint8_t
_pin
,
unsigned
int
frequency
,
unsigned
long
duration
=
0
);
void
noTone
(
uint8_t
_pin
);
// WMath prototypes
long
random
(
long
);
#endif
/* __cplusplus */
#include "pins_arduino.h"
...
...
cores/esp32/WMath.cpp
浏览文件 @
1e3717bc
...
...
@@ -29,10 +29,22 @@ extern "C" {
}
#include "esp32-hal-log.h"
// Allows the user to choose between Real Hardware
// or Software Pseudo random generators for the
// Arduino random() functions
static
bool
s_useRandomHW
=
true
;
void
useRealRandomGenerator
(
bool
useRandomHW
)
{
s_useRandomHW
=
useRandomHW
;
}
// Calling randomSeed() will force the
// Pseudo Random generator like in
// Arduino mainstream API
void
randomSeed
(
unsigned
long
seed
)
{
if
(
seed
!=
0
)
{
srand
(
seed
);
s_useRandomHW
=
false
;
}
}
...
...
@@ -46,7 +58,9 @@ long random( long howbig )
if
(
howbig
<
0
)
{
return
(
random
(
0
,
-
howbig
));
}
return
esp_random
()
%
howbig
;
// if randomSeed was called, fall back to software PRNG
uint32_t
val
=
(
s_useRandomHW
)
?
esp_random
()
:
rand
();
return
val
%
howbig
;
}
long
random
(
long
howsmall
,
long
howbig
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录