当前位置: 首页 > news >正文

《HeadFirst设计模式(第二版)》第六章代码——命令模式

代码文件目录:

Command
package Chapter6_CommandPattern.Command;/*** @Author 竹心* @Date 2023/8/6**/public interface Command {public void execute();public void undo();//撤销该指令
}
CeilingFan
package Chapter6_CommandPattern.ElectricAppliance;/*** @Author 竹心* @Date 2023/8/6**///吊扇
public class CeilingFan {public static final int HIGH = 3;public static final int MEDIUM = 2;public static final int LOW = 1;public static final int OFF = 0;String location;int speed;public CeilingFan(String location){this.location = location;this.speed = OFF;}public void high(){this.speed = HIGH;System.out.println(this.location+" ceilingFan is on High");}public void medium(){this.speed = MEDIUM;System.out.println(this.location+" ceilingFan is on Medium");}public void low(){this.speed = LOW;System.out.println(this.location+" ceilingFan is on Low");}public void off(){this.speed = OFF;System.out.println(this.location+" ceilingFan is on Off");}public int getSpeed(){return this.speed;}}
CeilingFanHighCommand
package Chapter6_CommandPattern.Command;import Chapter6_CommandPattern.ElectricAppliance.CeilingFan;/*** @Author 竹心* @Date 2023/8/6**/public class CeilingFanHighCommand implements Command{CeilingFan ceilingFan;int prevSpeed;//保存上一个挡位public CeilingFanHighCommand(CeilingFan ceilingFan){this.ceilingFan = ceilingFan;}@Overridepublic void execute() {this.prevSpeed = this.ceilingFan.getSpeed();this.ceilingFan.high();}@Overridepublic void undo() {if(this.prevSpeed==CeilingFan.HIGH){this.ceilingFan.high();}else if(this.prevSpeed == CeilingFan.MEDIUM){this.ceilingFan.medium();}else if(this.prevSpeed == CeilingFan.LOW){this.ceilingFan.low();}else if(this.prevSpeed == CeilingFan.OFF){this.ceilingFan.off();}}
}
Light
package Chapter6_CommandPattern.ElectricAppliance;/*** @Author 竹心* @Date 2023/8/6**/public class Light {String name;public Light(String name){this.name = name;}public void on(){System.out.println(this.name+" light is on!");}public void off(){System.out.println(this.name+" light is off!");}
}
LightOnCommand
package Chapter6_CommandPattern.Command;import Chapter6_CommandPattern.Command.Command;
import Chapter6_CommandPattern.ElectricAppliance.Light;/*** @Author 竹心* @Date 2023/8/6**/public class LightOnCommand implements Command {Light light;public LightOnCommand(Light light){this.light = light;}@Overridepublic void execute() {//当遥控器运行这个指令的时候,并不知道灯是如何实现打开开关的//实现遥控器与电器之间的解耦合this.light.on();}@Overridepublic void undo() {this.light.off();}
}
LightOffCommand
package Chapter6_CommandPattern.Command;import Chapter6_CommandPattern.ElectricAppliance.Light;/*** @Author 竹心* @Date 2023/8/6**/public class LightOffCommand implements Command{Light light;public LightOffCommand(Light light){this.light = light;}@Overridepublic void execute() {this.light.off();}public void undo() {this.light.on();}
}
GarageDoor
package Chapter6_CommandPattern.ElectricAppliance;/*** @Author 竹心* @Date 2023/8/6**/public class GarageDoor {Light light;public GarageDoor(Light light){this.light = light;}public void up(){this.lightOn();System.out.println("the garage door is open!");}public void down(){this.lightOff();System.out.println("the garage door is closed");}private void lightOn(){this.light.on();}private void lightOff(){this.light.off();}
}
GarageDoorOpenCommand
package Chapter6_CommandPattern.Command;import Chapter6_CommandPattern.ElectricAppliance.GarageDoor;/*** @Author 竹心* @Date 2023/8/6**/public class GarageDoorOpenCommand implements Command{GarageDoor garageDoor;public GarageDoorOpenCommand(GarageDoor garageDoor){this.garageDoor = garageDoor;}@Overridepublic void execute() {this.garageDoor.up();}public void undo() {this.garageDoor.down();}
}
GarageDoorCloseCommand
package Chapter6_CommandPattern.Command;import Chapter6_CommandPattern.ElectricAppliance.GarageDoor;/*** @Author 竹心* @Date 2023/8/6**/public class GarageDoorCloseCommand implements Command{GarageDoor garageDoor;public GarageDoorCloseCommand(GarageDoor garageDoor){this.garageDoor = garageDoor;}@Overridepublic void execute() {this.garageDoor.down();}public void undo() {this.garageDoor.down();}
}
Stereo
package Chapter6_CommandPattern.ElectricAppliance;/*** @Author 竹心* @Date 2023/8/6**/public class Stereo {int volume;//音响类public void on(){System.out.println("the stereo is on!");}public void off(){System.out.println("the stereo is off!");}public void setCD(){System.out.println("the stereo can work with CD now!");}public void setDVD(){System.out.println("the stereo can work with DVD now!");}public void setVolume(int volume){//设置音量this.volume = volume;}
}
StereoOnWithCDCommand
package Chapter6_CommandPattern.Command;import Chapter6_CommandPattern.ElectricAppliance.Stereo;/*** @Author 竹心* @Date 2023/8/6**/public class StereoOnWithCDCommand implements Command{Stereo stereo;public StereoOnWithCDCommand(Stereo stereo){this.stereo = stereo;}@Overridepublic void execute() {this.stereo.on();this.stereo.setCD();this.stereo.setVolume(6);}@Overridepublic void undo() {this.stereo.off();}
}
StereoOff
package Chapter6_CommandPattern.Command;import Chapter6_CommandPattern.ElectricAppliance.Stereo;/*** @Author 竹心* @Date 2023/8/6**/public class StereoOff implements  Command{Stereo stereo;public StereoOff(Stereo stereo){this.stereo = stereo;}@Overridepublic void execute() {this.stereo.off();}public void undo() {this.stereo.on();this.stereo.setCD();this.stereo.setVolume(6);}
}
MacroCommand
package Chapter6_CommandPattern.Command;/*** @Author 竹心* @Date 2023/8/6**///宏指令
public class MacroCommand implements Command{Command[] commands;public MacroCommand(Command[] commands){this.commands = commands;}@Overridepublic void execute() {for(int i=0;i<this.commands.length;++i){this.commands[i].execute();}}@Overridepublic void undo() {for(int i=0;i<this.commands.length;++i){this.commands[i].undo();}}
}
NoCommand
package Chapter6_CommandPattern.Command;/*** @Author 竹心* @Date 2023/8/6**/public class NoCommand implements Command{@Overridepublic void execute() {//this command is useless!}@Overridepublic void undo() {}
}
RemoteControl
package Chapter6_CommandPattern;import Chapter6_CommandPattern.Command.Command;
import Chapter6_CommandPattern.Command.NoCommand;import java.util.Arrays;/*** @Author 竹心* @Date 2023/8/6**///遥控器类
public class RemoteControl {Command[] onCommands;Command[] offCommands;Command undoCommand;public RemoteControl(){//为简洁起见,这里遥控器只有3个槽位this.onCommands = new Command[7];this.offCommands = new Command[7];Command noCommand = new NoCommand();//这里使用空对象,是为了后面不用写 if(onCommand[i]==null){...}for(int i =0;i<7;++i){this.onCommands[i] = noCommand;this.offCommands[i] = noCommand;}this.undoCommand = noCommand;}//设置某个电器的开关命令public void setCommand(int slot, Command onCommand, Command offCommand){this.onCommands[slot] = onCommand;this.offCommands[slot] = offCommand;}public void onButtonWasPushed(int slot){this.onCommands[slot].execute();this.undoCommand = this.onCommands[slot];}public void offButtonWasPushed(int slot){this.offCommands[slot].execute();this.undoCommand = this.offCommands[slot];}public void undoButtonWasPushed(){this.undoCommand.undo();}@Overridepublic String toString() {StringBuffer stringBuffer = new StringBuffer();stringBuffer.append("\n---------- Remote Control ----------\n");for(int i = 0;i<this.onCommands.length;i++){stringBuffer.append("[slot "+ i +"] "+String.format("%-30s",this.onCommands[i].getClass().getSimpleName())+String.format("%-30s",this.offCommands[i].getClass().getSimpleName())+"\n");}stringBuffer.append("[undo] "+this.undoCommand.getClass().getSimpleName());return stringBuffer.toString();}
}
RemoteLoader
package Chapter6_CommandPattern;import Chapter6_CommandPattern.Command.*;
import Chapter6_CommandPattern.ElectricAppliance.CeilingFan;
import Chapter6_CommandPattern.ElectricAppliance.GarageDoor;
import Chapter6_CommandPattern.ElectricAppliance.Light;
import Chapter6_CommandPattern.ElectricAppliance.Stereo;/*** @Author 竹心* @Date 2023/8/6**/public class RemoteLoader {public static void main(String[] args) {RemoteControl remoteControl = new RemoteControl();//创建设备Light LivingRoomLight = new Light("LivingRoom");Light KitchenLight = new Light("Kitchen");Light GarageLight = new Light("Garage");GarageDoor garageDoor = new GarageDoor(GarageLight);Stereo stereo = new Stereo();//创建命令对象LightOnCommand livingRoomLightOn =new LightOnCommand(LivingRoomLight);LightOnCommand kitchenLightOn = new LightOnCommand(KitchenLight);GarageDoorOpenCommand garageDoorOpenCommand =new GarageDoorOpenCommand(garageDoor);StereoOnWithCDCommand stereoOnWithCDCommand =new StereoOnWithCDCommand(stereo);LightOffCommand lightOffCommand = new LightOffCommand(LivingRoomLight);LightOffCommand kitchenLightOff = new LightOffCommand(KitchenLight);GarageDoorCloseCommand garageDoorCloseCommand =new GarageDoorCloseCommand(garageDoor);StereoOff stereoOff = new StereoOff(stereo);//将命令加载进入槽位remoteControl.setCommand(0,livingRoomLightOn,lightOffCommand);remoteControl.setCommand(1,kitchenLightOn,kitchenLightOff);remoteControl.setCommand(2,garageDoorOpenCommand,garageDoorCloseCommand);remoteControl.setCommand(3,stereoOnWithCDCommand,stereoOff);//展示
//        System.out.println(remoteControl);remoteControl.onButtonWasPushed(0);remoteControl.onButtonWasPushed(1);remoteControl.onButtonWasPushed(2);remoteControl.onButtonWasPushed(3);remoteControl.offButtonWasPushed(0);remoteControl.offButtonWasPushed(1);remoteControl.offButtonWasPushed(2);remoteControl.offButtonWasPushed(3);//使用lambda简洁编写代码//增加撤销按钮后就不能使用了//这样就不用写一大堆命令类了
//        remoteControl.setCommand(4,()->LivingRoomLight.on(),
//                ()->LivingRoomLight.off());//测试撤销功能System.out.println("\n测试撤销:");remoteControl.onButtonWasPushed(0);remoteControl.undoButtonWasPushed();//测试风扇System.out.println("test fan");CeilingFan ceilingFan = new CeilingFan("livingRoom");CeilingFanHighCommand command = new CeilingFanHighCommand(ceilingFan);remoteControl.setCommand(4,command,command);System.out.println(remoteControl);remoteControl.onButtonWasPushed(4);System.out.println(remoteControl);remoteControl.undoButtonWasPushed();//测试宏指令System.out.println("\n宏指令");Light light1 = new Light("Room1");Light light2 = new Light("Room2");Light light3 = new Light("Room3");Light light4 = new Light("Room4");LightOnCommand lightOnCommand1 = new LightOnCommand(light1);LightOnCommand lightOnCommand2 = new LightOnCommand(light2);LightOnCommand lightOnCommand3 = new LightOnCommand(light3);LightOnCommand lightOnCommand4 = new LightOnCommand(light4);LightOffCommand lightOffCommand1 = new LightOffCommand(light1);LightOffCommand lightOffCommand2 = new LightOffCommand(light2);LightOffCommand lightOffCommand3 = new LightOffCommand(light3);LightOffCommand lightOffCommand4 = new LightOffCommand(light4);Command[] onCommands = {lightOnCommand1,lightOnCommand2,lightOnCommand3,lightOnCommand4};Command[] offCommand = {lightOffCommand1,lightOffCommand2,lightOffCommand3,lightOffCommand4};MacroCommand partyOn = new MacroCommand(onCommands);MacroCommand partyOff = new MacroCommand(offCommand);remoteControl.setCommand(5,partyOn,partyOff);System.out.println(remoteControl);remoteControl.onButtonWasPushed(5);remoteControl.offButtonWasPushed(5);remoteControl.undoButtonWasPushed();}
}
SimpleRemoteControl
package Chapter6_CommandPattern;import Chapter6_CommandPattern.Command.Command;/*** @Author 竹心* @Date 2023/8/6**/public class SimpleRemoteControl {Command slot;//目前该遥控器只支持一个槽位public SimpleRemoteControl(){}public void setCommand(Command command){this.slot = command;}public void buttonWasPressed(){this.slot.execute();}}
RemoteControlTest
package Chapter6_CommandPattern;import Chapter6_CommandPattern.Command.GarageDoorOpenCommand;
import Chapter6_CommandPattern.ElectricAppliance.GarageDoor;
import Chapter6_CommandPattern.ElectricAppliance.Light;/*** @Author 竹心* @Date 2023/8/6**/public class RemoteControlTest {public static void main(String[] args) {SimpleRemoteControl remote = new SimpleRemoteControl();Light light = new Light("garage light");GarageDoor garageDoor = new GarageDoor(light);GarageDoorOpenCommand garageDoorOpen = new GarageDoorOpenCommand(garageDoor);remote.setCommand(garageDoorOpen);remote.buttonWasPressed();}
}
notes.txt
命令模式:把请求封装成为对象,以便对不同的请求、队列或者日志请求来参数化对象,并支持可撤销的操作命令对象只暴露一个方法:execute(),命令的请求者不会知道执行者具体如何实现指令当需要将发出请求的对象和能够实行请求的对象解耦合的时候可以使用命令模式

相关文章:

《HeadFirst设计模式(第二版)》第六章代码——命令模式

代码文件目录&#xff1a; Command package Chapter6_CommandPattern.Command;/*** Author 竹心* Date 2023/8/6**/public interface Command {public void execute();public void undo();//撤销该指令 }CeilingFan package Chapter6_CommandPattern.ElectricAppliance;/*** …...

JS 原型与继承2

//***-、原型、原型链、构造函数 prototype、 proto_、constructor function Foo(){this.a1} var foo new Foo(); Object.getPrototypeOf(foo);//访问对象原型 效果等同于&#xff0c;foo. proto &#xff0c;只是更推荐使用 Es6的 Object.getPrototypeof()方式 // construct…...

账号登录相关的一点随笔

最后更新于2023年8月8日 14:25:32 JWT验证&#xff1a; 简单&#xff1a;一个token验证&#xff1b; 前端发来登录信息&#xff0c;后端验证通过后&#xff0c;将token发回前端&#xff1b; 复杂&#xff1a;Access Token Refresh Token验证&#xff1a; 将Access Token和R…...

常见的一些BUG

常见的一些BUG&#xff0c;但实际上在编写代码时&#xff0c;我们应该尽可能避免这些类型的错误&#xff1a; 变量名与函数名冲突&#xff1a; def main(): print("Hello, World!") main 5 print("The value of main is:", main) 函数参数传递错误&…...

ChatGPT在智能社交网络分析和关系挖掘中的应用如何?

智能社交网络分析和关系挖掘是当今信息时代中的重要研究领域&#xff0c;它们通过运用人工智能、机器学习和数据挖掘技术&#xff0c;从社交网络中提取有价值的信息&#xff0c;洞察用户之间的关系和行为模式。ChatGPT作为一种强大的自然语言处理模型&#xff0c;在智能社交网络…...

你不了解的Dictionary和ConcurrentDictionary

最近在做项目时&#xff0c;多线程中使用Dictionary的全局变量时&#xff0c;发现数据并没有存入到Dictionary中&#xff0c;但是程序也没有报错&#xff0c;经过自己的一番排查&#xff0c;发现Dictionary为非线程安全类型&#xff0c;因此我感觉数据没有写进去的原因是多线程…...

c++类模板,嵌套类模板,模板链表,动态数组

c类模板&#xff0c;嵌套类模板&#xff0c;模板链表&#xff0c;动态数组 一.类模板 1.类模板的书写 代码如下 template<typename T>//模板 class CTest {//类 public:T m_a;CTest(const T&a):m_a(a){}void fun1() {cout << typeid(m_a).name() << …...

【Flutter】【基础】CustomPaint 绘画功能,绘制各种图形(二)

CustomPaint 使用实例和代码&#xff1a; 1.canvas.drawColor 绘制背景颜色 class MyPainter1 extends CustomPainter {overridevoid paint(Canvas canvas, Size size) {//绘制背景颜色&#xff0c;整个UI 现在就是红色的canvas.drawColor(Colors.red, BlendMode.srcATop);}…...

YOLOv5修改注意力机制CBAM

直接上干货 CBAM注意力机制是由通道注意力机制&#xff08;channel&#xff09;和空间注意力机制&#xff08;spatial&#xff09;组成。 传统基于卷积神经网络的注意力机制更多的是关注对通道域的分析&#xff0c;局限于考虑特征图通道之间的作用关系。CBAM从 channel 和 sp…...

计算机网络 网络层 概述

...

算法练习--动态规划 相关

文章目录 走方格的方案 走方格的方案 请计算n*m的棋盘格子&#xff08;n为横向的格子数&#xff0c;m为竖向的格子数&#xff09;从棋盘左上角出发沿着边缘线从左上角走到右下角&#xff0c;总共有多少种走法&#xff0c;要求不能走回头路&#xff0c;即&#xff1a;只能往右和…...

JAVA volatile 关键字

volatile 是JAVA虚拟机提供的轻量级的同步机制&#xff0c;有三大特性 1、保证可见性 2、不保证原子性 3、禁止指令重排 JMM JAVA内存模型本身是一种抽象的概念并不真实存在 它描述的是一组规则或规范&#xff0c;提供这组规范定义了程序中各个变量&#xff08;包括实例变…...

[Leetcode] [Tutorial] 回溯

文章目录 46. 全排列Solution 78. 子集Solution 17. 电话号码的字母组合Solution 39. 组合总和Solution 22. 括号生成Solution 46. 全排列 给定一个不含重复数字的数组 nums &#xff0c;返回其 所有可能的全排列 。你可以 按任意顺序 返回答案。 示例&#xff1a; 输入&…...

STM32 CubeMX USB_MSC(存储设备U盘)

STM32 CubeMX STM32 CubeMX USB_MSC(存储设备U盘&#xff09; STM32 CubeMX前言 《使用内部Flash》——U盘一、STM32 CubeMX 设置USB时钟设置USB使能UBS功能选择FATFS功能 二、代码部分修改代码"usbd_storage_if.c"修改代码"user_diskio.c"main函数初始化插…...

湘大 XTU OJ 1214 A+B IV 题解:数位移动的本质+布尔变量标记+朴素模拟

一、链接 AB IV 二、题目 题目描述 小明喜欢做ab的算术&#xff0c;但是他经常忘记把末位对齐&#xff0c;再进行加&#xff0c;所以&#xff0c;经常会算错。 比如1213&#xff0c;他把12左移了1位&#xff0c;结果变成了133。 小明已经算了一些等式&#xff0c;请计算一下…...

以商业大数据技术助力数据合规流通体系建立,合合信息参编《数据经纪从业人员评价规范》团标

经国务院批准&#xff0c;由北京市人民政府、国家发展和改革委员会、工业和信息化部、商务部、国家互联网信息办公室、中国科学技术协会共同主办的2023 全球数字经济大会于近期隆重召开。由数交数据经纪&#xff08;深圳&#xff09;有限公司为主要发起单位&#xff0c;合合信息…...

【论文阅读】Deep Instance Segmentation With Automotive Radar Detection Points

基于汽车雷达检测点的深度实例分割 一个区别&#xff1a; automotive radar 汽车雷达 &#xff1a; 分辨率低&#xff0c;点云稀疏&#xff0c;语义上模糊&#xff0c;不适合直接使用用于密集LiDAR点开发的方法 &#xff1b; 返回的物体图像不如LIDAR精确&#xff0c;可以…...

易服客工作室:如何创建有用的内容日历

利用技巧和工具优化您的内容营销效率和效果。创建一个内容日历&#xff0c;您的整个团队都会从中受益&#xff01; 欢迎来到熙熙攘攘、瞬息万变的内容营销世界&#xff0c;在这里&#xff0c;截止日期到来的速度比喝咖啡的猎豹还要快。 现在&#xff0c;想象一下在没有地图、…...

Excel革命,基于电子表格开发的新工具,不是Access和Power Fx

深谙其道 在日常工作中&#xff0c;Excel是许多人不可或缺的办公工具。 是微软的旗下产品&#xff0c;属于Microsoft 365套件中的一部分&#xff0c;强大的数据处理和计算功能&#xff0c;被普遍应用在全球各行各业的人群当中&#xff0c;是一款强大且普及的电子表格软件。 于…...

“崩溃”漏洞会影响英特尔 CPU 的使用寿命,可能会泄露加密密钥等

对于 CPU 安全漏洞来说&#xff0c;本周是重要的一周。昨天&#xff0c;不同的安全研究人员发布了两个不同漏洞的详细信息&#xff0c;一个影响多代英特尔处理器&#xff0c;另一个影响最新的 AMD CPU。“ Downfall ”和“ Inception ”&#xff08;分别&#xff09;是不同的错…...

Java 语言特性(面试系列1)

一、面向对象编程 1. 封装&#xff08;Encapsulation&#xff09; 定义&#xff1a;将数据&#xff08;属性&#xff09;和操作数据的方法绑定在一起&#xff0c;通过访问控制符&#xff08;private、protected、public&#xff09;隐藏内部实现细节。示例&#xff1a; public …...

脑机新手指南(八):OpenBCI_GUI:从环境搭建到数据可视化(下)

一、数据处理与分析实战 &#xff08;一&#xff09;实时滤波与参数调整 基础滤波操作 60Hz 工频滤波&#xff1a;勾选界面右侧 “60Hz” 复选框&#xff0c;可有效抑制电网干扰&#xff08;适用于北美地区&#xff0c;欧洲用户可调整为 50Hz&#xff09;。 平滑处理&…...

FastAPI 教程:从入门到实践

FastAPI 是一个现代、快速&#xff08;高性能&#xff09;的 Web 框架&#xff0c;用于构建 API&#xff0c;支持 Python 3.6。它基于标准 Python 类型提示&#xff0c;易于学习且功能强大。以下是一个完整的 FastAPI 入门教程&#xff0c;涵盖从环境搭建到创建并运行一个简单的…...

JVM暂停(Stop-The-World,STW)的原因分类及对应排查方案

JVM暂停(Stop-The-World,STW)的完整原因分类及对应排查方案,结合JVM运行机制和常见故障场景整理而成: 一、GC相关暂停​​ 1. ​​安全点(Safepoint)阻塞​​ ​​现象​​:JVM暂停但无GC日志,日志显示No GCs detected。​​原因​​:JVM等待所有线程进入安全点(如…...

【VLNs篇】07:NavRL—在动态环境中学习安全飞行

项目内容论文标题NavRL: 在动态环境中学习安全飞行 (NavRL: Learning Safe Flight in Dynamic Environments)核心问题解决无人机在包含静态和动态障碍物的复杂环境中进行安全、高效自主导航的挑战&#xff0c;克服传统方法和现有强化学习方法的局限性。核心算法基于近端策略优化…...

day36-多路IO复用

一、基本概念 &#xff08;服务器多客户端模型&#xff09; 定义&#xff1a;单线程或单进程同时监测若干个文件描述符是否可以执行IO操作的能力 作用&#xff1a;应用程序通常需要处理来自多条事件流中的事件&#xff0c;比如我现在用的电脑&#xff0c;需要同时处理键盘鼠标…...

苹果AI眼镜:从“工具”到“社交姿态”的范式革命——重新定义AI交互入口的未来机会

在2025年的AI硬件浪潮中,苹果AI眼镜(Apple Glasses)正在引发一场关于“人机交互形态”的深度思考。它并非简单地替代AirPods或Apple Watch,而是开辟了一个全新的、日常可接受的AI入口。其核心价值不在于功能的堆叠,而在于如何通过形态设计打破社交壁垒,成为用户“全天佩戴…...

Python训练营-Day26-函数专题1:函数定义与参数

题目1&#xff1a;计算圆的面积 任务&#xff1a; 编写一个名为 calculate_circle_area 的函数&#xff0c;该函数接收圆的半径 radius 作为参数&#xff0c;并返回圆的面积。圆的面积 π * radius (可以使用 math.pi 作为 π 的值)要求&#xff1a;函数接收一个位置参数 radi…...

yaml读取写入常见错误 (‘cannot represent an object‘, 117)

错误一&#xff1a;yaml.representer.RepresenterError: (‘cannot represent an object’, 117) 出现这个问题一直没找到原因&#xff0c;后面把yaml.safe_dump直接替换成yaml.dump&#xff0c;确实能保存&#xff0c;但出现乱码&#xff1a; 放弃yaml.dump&#xff0c;又切…...

STM32标准库-ADC数模转换器

文章目录 一、ADC1.1简介1. 2逐次逼近型ADC1.3ADC框图1.4ADC基本结构1.4.1 信号 “上车点”&#xff1a;输入模块&#xff08;GPIO、温度、V_REFINT&#xff09;1.4.2 信号 “调度站”&#xff1a;多路开关1.4.3 信号 “加工厂”&#xff1a;ADC 转换器&#xff08;规则组 注入…...