repo_name
stringlengths 5
122
| path
stringlengths 3
232
| text
stringlengths 6
1.05M
|
|---|---|---|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSInventoryGoodsController.h
|
//
// FSInventoryGoodsController.h
// myhome
//
// Created by FudonFuchina on 2018/2/3.
// Copyright © 2018年 fuhope. All rights reserved.
//
#import "FSBaseController.h"
#import "FSGoodsModel.h"
@interface FSInventoryGoodsController : FSBaseController
@property (nonatomic,copy) void (^selectedGoods)(FSInventoryGoodsController *bVC,FSGoodsModel *bModel);
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSSeeImageView.h
|
<reponame>fuchina/FSPassword
//
// FSSeeImageView.h
// Picture
//
// Created by fudon on 16/8/16.
// Copyright © 2016年 Fudongdong. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface FSSeeImageView : UIView
@property (nonatomic,strong) NSArray<UIImage *> *dataSource; // UIImage 对象数组
@property (nonatomic,assign) NSInteger index; // 展示第(index + 1)张图片
@property (nonatomic,copy) void (^singleBlock)(FSSeeImageView *bView);
@property (nonatomic,copy) void (^indexChangedBlock)(FSSeeImageView *bView,NSInteger bIndex);
@property (nonatomic,strong) UICollectionView *collectionView;
- (instancetype)initWithFrame:(CGRect)frame dataSource:(NSArray<UIImage *> *)dataSource; // 数组传入UIImage对象
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSMultiPeerService.h
|
<reponame>fuchina/FSPassword<filename>FSPasswordSample/Pods/Headers/Public/FSJZBus/FSMultiPeerService.h<gh_stars>0
//
// FSMultiPeerService.h
// myhome
//
// Created by FudonFuchina on 2017/10/21.
// Copyright © 2017年 fuhope. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <MultipeerConnectivity/MultipeerConnectivity.h>
#import "FSMultiPeerTool.h"
#import <FSTuple.h>
@interface FSMultiPeerService : NSObject
@property (nonatomic, strong) MCNearbyServiceAdvertiser *advertiser;
@property (nonatomic, strong) MCSession *session;
@property (nonatomic, strong) MCPeerID *peerID;
@property (nonatomic,copy) void (^receivedData)(id bData);
@property (nonatomic,copy) void (^usersChanged)(NSArray<MCPeerID *> *users);
@property (nonatomic,copy) void (^receiveResource)(NSString *rName,NSString *from,NSProgress *p);
@property (nonatomic,copy) void (^finishedResource)(NSString *rName,NSString *from,NSURL *local,NSError *error);
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSCCMainView.h
|
<filename>FSPasswordSample/Pods/Headers/Public/FSJZBus/FSCCMainView.h
//
// FSCCMainView.h
// NL
//
// Created by fudon on 16/8/4.
// Copyright © 2016年 Fudongdong. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "FSCCDayView.h"
@interface FSCCMainView : UIView
@property (nonatomic,strong) NSDate *firstDay;
@property (nonatomic,copy) CCDayViewBlock block;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSSwitchCell.h
|
//
// FSSwitchCell.h
// Expand
//
// Created by Fudongdong on 2017/11/29.
// Copyright © 2017年 china. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface FSSwitchCell : UITableViewCell
@property (nonatomic,assign) NSInteger on;
@property (nonatomic,copy) void (^block)(UISwitch *s);
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSChineseCalendarController.h
|
//
// FSChineseCalendarController.h
// ShareEconomy
//
// Created by FudonFuchina on 16/8/7.
// Copyright © 2016年 FudonFuchina. All rights reserved.
//
#import "FSBaseController.h"
@interface FSChineseCalendarController : FSBaseController
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSMoreZoneImageCell.h
|
//
// FSMoreZoneImageCell.h
// FSImage
//
// Created by fudon on 2016/10/12.
// Copyright © 2016年 Fudongdong. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "FSIPModel.h"
@interface FSMoreZoneImageCell : UITableViewCell
@property (nonatomic,strong) FSIPModel *model;
@property (nonatomic,strong) NSArray<FSIPModel *> *models;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSWBView.h
|
<reponame>fuchina/FSPassword
//
// FSWBView.h
// ShareEconomy
//
// Created by FudonFuchina on 16/8/13.
// Copyright © 2016年 FudonFuchina. All rights reserved.
//
#import "FSBaseView.h"
@class FSWBView;
typedef void(^FSWBViewBlock)(FSWBView *bView,NSInteger bIndex);
@interface FSWBView : FSBaseView
@property (nonatomic,strong) UILabel *titleLabel;
@property (nonatomic,copy) FSWBViewBlock block;
- (void)showWBView:(BOOL)show;
@end
|
fuchina/FSPassword
|
FSPassword/classes/FSPwdMaker.h
|
<filename>FSPassword/classes/FSPwdMaker.h
//
// FSPwdMaker.h
// Expand
//
// Created by Fudongdong on 2017/8/22.
// Copyright © 2017年 china. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, FSPasswordType) {
FSPasswordTypeDefault = 0, // 8个符号,两大写,两小写,两数字,两特符
FSPasswordTypeSixNumber = 1, // 6个数字
FSPasswordTypeEightNumber = 2, // 8个数字
FSPasswordTypeCharNumber = 3, // 8个符号,两大写,两小写,四数字
FSPasswordTypeTenChar = 4, // 10个符号,两大写,两小写,三数字,三特符
FSPasswordThreeHanzi = 5, // 返回三个汉字
FSPasswordSixChars = 6, // 返回八个字母
};
@interface FSPwdMaker : NSObject
// seed为 1688等任何符号,link为核心密码
+ (NSString *)passwordWithType:(FSPasswordType)type seed:(NSString *)seed link:(NSString *)link;
+ (NSArray *)hundredHanzis;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSCountButton.h
|
<gh_stars>0
//
// FSCountButton.h
// FSImage
//
// Created by fudon on 2016/10/11.
// Copyright © 2016年 Fudongdong. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface FSCountButton : UIView
@property (nonatomic,assign) BOOL enabled;
@property (nonatomic,strong) UILabel *countLabel;
@property (nonatomic,strong) UILabel *textLabel;
@property (nonatomic,copy) void (^tapBlock)(FSCountButton *bButton);
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSInventoryDetailController.h
|
//
// FSInventoryDetailController.h
// myhome
//
// Created by FudonFuchina on 2018/3/9.
// Copyright © 2018年 fuhope. All rights reserved.
//
#import "FSInventoryModel.h"
#import "FSShakeBaseController.h"
@interface FSInventoryDetailController : FSShakeBaseController
@property (nonatomic,strong) FSInventoryModel *model;
@property (nonatomic,strong) NSString *table;
@property (nonatomic,copy) void (^edited)(void);
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FIWebView.h
|
<filename>FSPasswordSample/Pods/Headers/Public/FSJZBus/FIWebView.h
//
// FIWebView.h
// FSMasonry
//
// Created by fudon on 15/12/9.
// Copyright © 2015年 FudonFuchina. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface FIWebView : UIWebView
// 获取某个标签的结点个数
- (int)nodeCountOfTag:(NSString *)tag;
/// 获取当前页面URL
- (NSString *) getCurrentURL;
/// 获取标题
- (NSString *) getTitle;
/// 获取图片
- (NSArray *) getImgs;
/// 获取当前页面所有链接
- (NSArray *) getOnClicks;
/// 改变背景颜色
- (void) setBackgroundColor:(UIColor *) color;
/// 为所有图片添加点击事件(网页中有些图片添加无效)
- (void) addClickEventOnImg;
/// 改变指定标签的字体颜色
- (void) setFontColor:(UIColor *) color withTag:(NSString *)tagName;
/// 改变指定标签的字体大小
- (void) setFontSize:(int) size withTag:(NSString *)tagName;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSPeersController.h
|
<filename>FSPasswordSample/Pods/Headers/Public/FSJZBus/FSPeersController.h
//
// FSPeersController.h
// myhome
//
// Created by FudonFuchina on 2017/10/24.
// Copyright © 2017年 fuhope. All rights reserved.
//
#import "FSBaseController.h"
@interface FSPeersController : FSBaseController
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSMultiPeerTool.h
|
//
// FSMultiPeerTool.h
// myhome
//
// Created by FudonFuchina on 2017/10/21.
// Copyright © 2017年 fuhope. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <MultipeerConnectivity/MultipeerConnectivity.h>
#import <FSKit.h>
#import <FSTuple.h>
static NSString *_send_type = @"JINZHA_MUTILPEER_SEND_TYPE";
@interface FSMultiPeerTool : NSObject
+ (NSString *)deviceNameBytesShorterThan64Bytes;
// ServiceType,不要更改,以免出现不同版本连接不上的问题
+ (NSString *)multiPeerServiceType;
// 发送文字
+ (NSString *)session:(MCSession *)session sendObject:(NSDictionary *)from toUsers:(NSArray<NSString *> *)users withMode:(MCSessionSendDataMode)mode;
// 发送图片
+ (Tuple2*)session:(MCSession *)session sendImageWithURL:(NSURL *)url toUsers:(NSString *)user withMode:(MCSessionSendDataMode)mode completion:(void(^)(NSError *error))completion;
+ (NSMutableArray *)hanleUsers:(NSArray<NSString *> *)users session:(MCSession *)session;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FIMoveButton.h
|
//
// FIMoveButton.h
// FuHope
//
// Created by FudonFuchina on 15/8/29.
// Copyright (c) 2015年 ronglian. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface FIMoveButton : UIView
@property (nonatomic, copy) void (^tapBlock)(FIMoveButton *bView,NSInteger bTaps);
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSMultipeerProcessView.h
|
<gh_stars>0
//
// FSMultipeerProcessView.h
// Expand
//
// Created by Fudongdong on 2017/10/24.
// Copyright © 2017年 china. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface FSMultipeerProcessView : UIView
@property (nonatomic,copy)void (^tapCallback)(FSMultipeerProcessView *view);
- (void)setName:(NSString *)name;
- (void)setFile:(NSString *)file;
- (void)setProcess:(CGFloat)process;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSAddGoodsController.h
|
//
// FSAddGoodsController.h
// myhome
//
// Created by FudonFuchina on 2018/2/3.
// Copyright © 2018年 fuhope. All rights reserved.
//
#import "FSBaseController.h"
@interface FSAddGoodsController : FSBaseController
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSIPModel.h
|
//
// FSIPModel.h
// FSImage
//
// Created by fudon on 2016/11/29.
// Copyright © 2016年 Fudongdong. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <Photos/Photos.h>
@interface FSIPModel : NSObject
@property (nonatomic,strong) PHAsset *asset;
@property (nonatomic,strong) UIImage *image;
@property (nonatomic,strong) NSDictionary *info;
@property (nonatomic,assign) BOOL isMoreClear;
@property (nonatomic,assign) NSInteger length;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSGoodsCell.h
|
<gh_stars>0
//
// FSGoodsCell.h
// myhome
//
// Created by FudonFuchina on 2018/2/4.
// Copyright © 2018年 fuhope. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "FSGoodsModel.h"
@interface FSGoodsCell : UITableViewCell
- (void)assignValue:(FSGoodsModel *)model;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSUrlModel.h
|
//
// FSUrlModel.h
// myhome
//
// Created by FudonFuchina on 2017/7/18.
// Copyright © 2017年 fuhope. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface FSUrlModel : NSObject
@property (nonatomic,strong) NSNumber *aid;
@property (nonatomic,copy) NSString *time;
@property (nonatomic,copy) NSString *name; // 名称,如苹果,亚马逊
@property (nonatomic,copy) NSString *url; // 网址
@property (nonatomic,copy) NSString *type; // 分类,如生活服务,网上银行
@property (nonatomic,copy) NSString *count; // 频率
+ (NSArray<NSString *> *)tableFields;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSCharTBController.h
|
//
// FSCharTBController.h
// myhome
//
// Created by fudon on 2016/11/2.
// Copyright © 2016年 fuhope. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface FSCharTBController : UITabBarController
- (instancetype)initWithClasses:(NSArray<NSString *>*)classes titles:(NSArray<NSString *>*)titles types:(NSArray<NSNumber *>*)types;
@end
|
fuchina/FSPassword
|
FSPassword/classes/FSPasswordCell.h
|
<filename>FSPassword/classes/FSPasswordCell.h<gh_stars>0
//
// FSPasswordCell.h
// myhome
//
// Created by FudonFuchina on 2017/8/17.
// Copyright © 2017年 fuhope. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "FSPwdBookModel.h"
@interface FSPasswordCell : UITableViewCell
@property (nonatomic,strong) FSPwdBookModel *model;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSMoreImageCell.h
|
<gh_stars>0
//
// FSMoreImageCell.h
// FSImage
//
// Created by fudon on 2016/10/10.
// Copyright © 2016年 Fudongdong. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "FSIPModel.h"
#import "FSBeyondButton.h"
@interface FSMoreImageCell : UICollectionViewCell
@property (nonatomic, strong) FSIPModel *model;
@property (nonatomic, copy) void (^btnClickBlock)(FSBeyondButton *bButton,FSIPModel *bModel);
@property (nonatomic, assign) BOOL isSelected;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSLocation/FSLocation.h
|
<filename>FSPasswordSample/Pods/Headers/Public/FSLocation/FSLocation.h
//
// FSLocation.h
// FSLocation
//
// Created by fudon on 2016/12/15.
// Copyright © 2016年 fuhope. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
/*
1.需要在工程plist文件中增加
NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription
NSLocationAlwaysAndWhenInUseUsageDescription
字段
*/
@interface FSLocation : NSObject
/*
获取当前经纬度的母对象数组
@result bError:如果为nil表示成功,不为nil表示出错
*/
+ (void)currentLongitudeAndlatitude:(void(^)(NSArray<CLLocation *> *locations,NSError *bError))completion;
/*
根据location获取地址
*/
+ (void)addressWithLocation:(CLLocation *)location completionHandler:(void (^)(NSArray< CLPlacemark *> *placemarks, NSError *error))completion;
/*
获取当前地址
CLPlacemark对象有个name属性,就是地址的名字,用于显示
*/
+ (void)currentAddressWithCompletionHandler:(void (^)(NSArray< CLPlacemark *> *placemarks, NSError *error))completion;
// 转换为中国习惯的地址顺序
+ (NSString *)chineseAddressWithPlace:(CLPlacemark *)placemark;
+ (CGFloat)distanceLocation:(CLLocation *)location toLocation:(CLLocation *)another;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSAddUrlController.h
|
//
// FSAddUrlController.h
// myhome
//
// Created by FudonFuchina on 2017/7/18.
// Copyright © 2017年 fuhope. All rights reserved.
//
#import "FSBaseController.h"
#import "FSUrlModel.h"
@interface FSAddUrlController : FSBaseController
@property (nonatomic,strong) FSUrlModel *model;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSPwdAPI.h
|
<filename>FSPasswordSample/Pods/Headers/Public/FSJZBus/FSPwdAPI.h<gh_stars>0
//
// FSPwdAPI.h
// myhome
//
// Created by FudonFuchina on 2018/5/1.
// Copyright © 2018年 fuhope. All rights reserved.
//
#import "FSBaseAPI.h"
@interface FSPwdAPI : FSBaseAPI
+ (NSString *)changeCorePasswordWithOld:(NSString *)old new:(NSString *)new password:(NSString *)password;
// 忘记了原密码
+ (NSString *)changeCorePasswordOnlyWithNewPwd:(NSString *)newP password:(NSString *)password;
// 更改环境
+ (void)changeLocalCorePassword:(NSString *)newA;
+ (NSString *)nowPwd;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/FSJZBus/FSJZBus/classes/FSInventoryAllModel.h
|
//
// FSInventoryAllModel.h
// myhome
//
// Created by FudonFuchina on 2018/3/11.
// Copyright © 2018年 fuhope. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface FSInventoryAllModel : NSObject
@property (nonatomic,copy) NSString *cost; // 投入
@property (nonatomic,copy) NSString *sale; // 销售
@property (nonatomic,copy) NSString *bank; // 库存
@property (nonatomic,copy) NSString *sold; // 总售
@property (nonatomic,copy) NSString *cstd; // 总成
@property (nonatomic,copy) NSString *prof; // 利润
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSCacheManager.h
|
<reponame>fuchina/FSPassword<gh_stars>0
//
// FSCacheManager.h
// ShareEconomy
//
// Created by fudon on 16/6/7.
// Copyright © 2016年 FudonFuchina. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface FSCacheManager : NSObject
/**
* 储存字符串到🔑钥匙串
*
* @param sValue 对应的Value
* @param sKey 对应的Key
*/
+ (void)saveKeychainValue:(NSString *)sValue Key:(NSString *)sKey;
/**
* 从🔑钥匙串获取字符串
*
* @param sKey 对应的Key
*
* @return 返回储存的Value
*/
+ (NSString *)readKeychainValue:(NSString *)sKey;
/**
* 从🔑钥匙串删除字符串
*
* @param sKey 对应的Key
*/
+ (void)deleteKeychainValue:(NSString *)sKey;
// 所有缓存的大小
+ (void)allCacheSize:(void(^)(NSUInteger bResult))resultBlock;
// 清除缓存
+ (void)clearAllCache:(void(^)(void))success;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSTransferDatabaseController.h
|
<gh_stars>0
//
// FSTransferDatabaseController.h
// myhome
//
// Created by FudonFuchina on 2017/11/5.
// Copyright © 2017年 fuhope. All rights reserved.
//
#import "FSBaseController.h"
@interface FSTransferDatabaseController : FSBaseController
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSAppManager.h
|
//
// FSAppManager.h
// FSGestureSample
//
// Created by fudongdong on 2018/12/29.
// Copyright © 2018年 fudongdong. All rights reserved.
//
#import <UIKit/UIKit.h>
static NSString *FSAppManagerLockScreenNotification = @"FSAppManagerLockScreenNotification";
@interface FSAppManager : NSObject
+ (instancetype)sharedInstance;
+ (void)setup;
@property (nonatomic,assign) NSInteger delay;// 退到后台后,多久锁屏
@property (assign,nonatomic) BOOL open;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSButtonsView.h
|
<reponame>fuchina/FSPassword<gh_stars>0
//
// FSButtonsView.h
// myhome
//
// Created by FudonFuchina on 2016/12/11.
// Copyright © 2016年 fuhope. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface FSButtonsView : UIView
@property (nonatomic,copy) void (^clickBlock)(FSButtonsView *bView,NSInteger bSelectedIndex);
@property (nonatomic,assign) NSInteger selectedIndex;
- (instancetype)initWithFrame:(CGRect)frame items:(NSArray *)items normalColor:(UIColor *)normalColor selectedColor:(UIColor *)selectedColor;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSWebKitController.h
|
<gh_stars>0
//
// FSWebKitController.h
// myhome
//
// Created by FudonFuchina on 2017/1/4.
// Copyright © 2017年 fuhope. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface FSWebKitController : UIViewController
@property (nonatomic,copy) NSString *urlString; // 网页URL
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSAllImageController.h
|
<filename>FSPasswordSample/Pods/Headers/Public/FSJZBus/FSAllImageController.h
//
// FSAllImageController.h
// FSImage
//
// Created by fudon on 2016/10/14.
// Copyright © 2016年 Fudongdong. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface FSAllImageController : UIViewController
@property (nonatomic,strong) NSArray *dataSource;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSSegmentControl.h
|
//
// FSSegmentControl.h
// ShareEconomy
//
// Created by FudonFuchina on 16/8/7.
// Copyright © 2016年 FudonFuchina. All rights reserved.
//
#import "FSBaseView.h"
@class FSSegmentControl;
typedef void(^FSSegmentControlBlock)(FSSegmentControl *bControl,NSInteger bSelectedIndex);
@interface FSSegmentControl : FSBaseView
@property (nonatomic,copy) FSSegmentControlBlock block;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSPassword/FSPwdCounterController.h
|
//
// FSPwdCounterController.h
// myhome
//
// Created by FudonFuchina on 2017/2/26.
// Copyright © 2017年 fuhope. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger, FSCodeType) {
FSCodeTypeDecode,
FSCodeTypeCode,
FSCodeTypeFourNumbers,
FSCodeTypeSixNumbers,
FSCodeTypeEightNumbers,
FSCodeTypeNumberChars,
FSCodeTypeCharNumbers,
FSCodeTypeThreeChars,
FSCodeTypeSixSystems,
};
@interface FSPwdCounterController : UIViewController
@property (nonatomic,assign) NSInteger type;
@property (nonatomic,copy) void (^callback)(FSPwdCounterController *bVC);
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSKeepLocationController.h
|
//
// FSKeepLocationController.h
// myhome
//
// Created by fudon on 2017/2/24.
// Copyright © 2017年 fuhope. All rights reserved.
//
#import "FSBaseController.h"
#import "FSLocationModel.h"
#import <CoreLocation/CoreLocation.h>
@interface FSKeepLocationController : FSBaseController
@property (nonatomic,strong) FSLocationModel *model;
@property (nonatomic,strong) CLLocation *location;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSStoreManager.h
|
<reponame>fuchina/FSPassword
//
// FSStoreManager.h
// FSStoreManager
//
// Created by fudon on 2016/12/6.
// Copyright © 2016年 fuhope. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, FSUploadChannel) {
FSUploadChannelQiniu, // 七牛
FSUploadChannelFuhope
};
@interface FSStoreManager : NSObject
+ (void)uploadUTF8Data:(NSData *)data key:(NSString *)key completion:(void(^)(void))completion;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSReceiveDatabaseController.h
|
//
// FSReceiveDatabaseController.h
// myhome
//
// Created by FudonFuchina on 2017/11/5.
// Copyright © 2017年 fuhope. All rights reserved.
//
#import "FSBaseController.h"
@interface FSReceiveDatabaseController : FSBaseController
@property (nonatomic,copy) void (^hasReceivedData)(FSReceiveDatabaseController *bVC);
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/FSJZBus/FSJZBus/classes/FSShowDeleteView.h
|
//
// FSShowDeleteView.h
// Expand
//
// Created by Fudongdong on 2017/11/3.
// Copyright © 2017年 china. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface FSShowDeleteView : UIView
- (void)setText:(NSString *)text;
- (void)setNotice:(NSString *)notice;
- (void)startAnimation;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSAppDocumentController.h
|
//
// FSAppDocumentController.h
// FSDocument
//
// Created by fudon on 2016/12/17.
// Copyright © 2016年 fuhope. All rights reserved.
//
/*
//取得一个目录下得所有文件名
NSArray *files = [fm subpathsAtPath: [self dataFilePath] ];
//读取某个文件
NSData *data = [fm contentsAtPath:[self dataFilePath]];
//或者
NSData *data = [NSData dataWithContentOfPath:[self dataFilePath]];
}
*/
#import <UIKit/UIKit.h>
#import "FSBaseController.h"
@interface FSAppDocumentController : UIViewController
@property (nonatomic,copy) NSString *path;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSMoveLabel.h
|
//
// FSMoveLabel.h
// ShareEconomy
//
// Created by FudonFuchina on 16/8/21.
// Copyright © 2016年 FudonFuchina. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface FSMoveLabel : UIView
@property (nonatomic,copy) NSString *text;
@property (nonatomic,strong) UIColor *textColor;
@property (nonatomic,copy) void (^tapBlock)(FSMoveLabel *bLabel);
- (void)start;
- (void)stop;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSInventory.h
|
//
// FSInventory.h
// myhome
//
// Created by FudonFuchina on 2018/2/3.
// Copyright © 2018年 fuhope. All rights reserved.
//
/*
1.计量:
按量减少,可售最小单位。
2.计重:
按重减少,单位:公斤。
3.计价:
只记录成本价;
面向对象管理:
1.库存表
@aid:序号;
@ctime:数据库存储时间;
@cost:原价,总成本,【不要修改】;
@num:计量的数量,计重的重量,【不要修改】;
@sid:商品id;
@name:商品名称;
@type:类型
@time:进货的时间;
@rest:计量的剩余数量,计重的剩余重量,操作时记这个;
@done:售罄;
@sale:收入,每次销售收入的累加;
// 这三个值不需要存库
@profit:收益;【售完后才有值】
@rate:收益率;同上
@yera:年化收益率;
2.辅助表:
@aid:序号;
@ctime:数据库时间;
@name:商品名称;
@time:销售的时间;
@to:卖给谁;
3.商品库
@aid:序号;
@time:数据库时间;
@name:名称;
@from:供应商;
@type:商品类型,计量还是计重;
@unit:单位;
@freq:排序用;
*/
#ifndef FSInventory_h
#define FSInventory_h
#define Notification_Add_Goods_Success @"Notification_Add_Goods_Success"
typedef NS_ENUM(NSInteger, FSInventoryType) {
FSInventoryTypeUnknown = 0, // 未知
FSInventoryTypeNumber = 1, // 计数
FSInventoryTypeWeight = 2, // 计重
FSInventoryTypePrice = 3, // 计价
};
#endif /* FSInventory_h */
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSUseGestureView+Factory.h
|
<reponame>fuchina/FSPassword
//
// FSUseGestureView+Factory.h
// FSCalculator
//
// Created by fudongdong on 2018/12/28.
//
#import "FSUseGestureView.h"
#import "FSAppManager.h"
@interface FSUseGestureView (Factory)
// 校验
+ (void)verify:(UIView *)superView password:(NSString *)password success:(void(^)(FSUseGestureView * view))success;
+ (void)verify:(UIView *)superView password:(NSString *)password success:(void(^)(FSUseGestureView * view))success cancel:(void(^)(void))cancel;
// 修改
+ (void)change:(UIView *)superView password:(NSString *)password completion:(void(^)(FSUseGestureView *view))completion;
// 设置
+ (void)setup:(UIView *)superView completion:(void(^)(FSUseGestureView *view))completion;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSGoodsModel.h
|
//
// FSGoodsModel.h
// myhome
//
// Created by FudonFuchina on 2018/2/3.
// Copyright © 2018年 fuhope. All rights reserved.
//
/*
@time:数据库时间;
@name:名称;
@from:供应商;
@type:商品类型,计量还是计重;
@unit:单位;
*/
#import <Foundation/Foundation.h>
@interface FSGoodsModel : NSObject
@property (nonatomic,strong) NSNumber *aid;
@property (nonatomic,copy) NSString *time;
@property (nonatomic,copy) NSString *name;
@property (nonatomic,copy) NSString *supp;
@property (nonatomic,copy) NSString *type;
@property (nonatomic,copy) NSString *unit;
@property (nonatomic,copy) NSString *freq; // 被选中的频数
+ (NSArray<NSString *> *)tableFields;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSPassword/FSRestartAppController.h
|
//
// FSRestartAppController.h
// myhome
//
// Created by FudonFuchina on 2017/11/7.
// Copyright © 2017年 fuhope. All rights reserved.
//
#import "FSBaseController.h"
@interface FSRestartAppController : FSBaseController
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSDouyingLabel.h
|
//
// FSDouyingLabel.h
// myhome
//
// Created by FudonFuchina on 2018/9/15.
// Copyright © 2018年 fuhope. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface FSDouyingLabel : UILabel
- (void)douyingShow:(NSString *)txt completion:(void (^)(void))completion;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSNoticeViewController.h
|
//
// FSNoticeViewController.h
// myhome
//
// Created by FudonFuchina on 2018/5/9.
// Copyright © 2018年 fuhope. All rights reserved.
//
#import "FSBaseController.h"
@interface FSNoticeViewController : FSBaseController
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSChatFileCell.h
|
//
// FSChatFileCell.h
// myhome
//
// Created by FudonFuchina on 2017/10/28.
// Copyright © 2017年 fuhope. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface FSChatFileCell : UITableViewCell
- (void)setName:(NSString *)name;
- (void)setTime:(NSString *)time;
@end
|
fuchina/FSPassword
|
FSPassword/classes/FSPwdBookController.h
|
<reponame>fuchina/FSPassword
//
// FSPwdBookController.h
// myhome
//
// Created by FudonFuchina on 2017/8/13.
// Copyright © 2017年 fuhope. All rights reserved.
//
#import "FSBaseController.h"
@interface FSPwdBookController : FSBaseController
@property (nonatomic,copy) NSString *zone;
@property (nonatomic,copy) NSString *name;
@property (nonatomic,copy) NSString *password;
// 搜索模式
@property (nonatomic,assign) BOOL isSearchMode;
@property (nonatomic,strong) NSArray *searchResults;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSBaseView.h
|
//
// FSBaseView.h
// ShareEconomy
//
// Created by fudon on 16/5/4.
// Copyright © 2016年 FudonFuchina. All rights reserved.
//
#import "FSBaseController.h"
@interface FSBaseView : UIView
@property (nonatomic,weak)UIViewController *responderController;
@property (nonatomic,copy) void (^backTapBlock)(void);
// 只有在有黑色背影的时候调用这方法,暂时屏蔽左滑手势
- (instancetype)initWithFrame:(CGRect)frame controller:(UIViewController *)controller;
- (void)freeAction;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSCCDayView.h
|
<filename>FSPasswordSample/Pods/Headers/Public/FSJZBus/FSCCDayView.h
//
// FSCCDayView.h
// NL
//
// Created by fudon on 16/8/4.
// Copyright © 2016年 Fudongdong. All rights reserved.
//
#import <UIKit/UIKit.h>
#define CCGreenColor [UIColor colorWithRed:100 / 255.0 green:170 / 255.0 blue:70 / 255.0 alpha:1]
@class FSCCDayView;
typedef void(^CCDayViewBlock)(FSCCDayView *bView);
typedef NS_ENUM(NSInteger, FSCCDayViewStatus) {
FSCCDayViewStatusDefault = 0, // 默认
FSCCDayViewStatusSelected, // 选择
FSCCDayViewStatusToday // 是今天
};
@interface FSCCDayView : UIView
@property (nonatomic,strong) NSDate *date;
@property (nonatomic,strong) UIFont *font;
@property (nonatomic,copy) CCDayViewBlock block;
@property (nonatomic,assign) FSCCDayViewStatus status;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSNextTaskController.h
|
//
// FSNextTaskController.h
// myhome
//
// Created by FudonFuchina on 2017/9/19.
// Copyright © 2017年 fuhope. All rights reserved.
//
#import "FSBaseController.h"
@interface FSNextTaskController : FSBaseController
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSIMBaseModel.h
|
//
// FSIMBaseModel.h
// myhome
//
// Created by FudonFuchina on 2018/2/4.
// Copyright © 2018年 fuhope. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface FSIMBaseModel : NSObject
@property (nonatomic,copy) NSString *readableTime;
@property (nonatomic,copy) NSString *profit; // 利润
@property (nonatomic,copy) NSString *rate; // 收益率
@property (nonatomic,copy) NSString *yera; // 年化收益率
@property (nonatomic,copy) NSString *isp; // 理想售价
@property (nonatomic,copy) NSString *days; // 进货到今天数
@property (nonatomic,copy) NSString *pp; // 售罄时为'利润',否则为'好价'
@property (nonatomic,copy) NSString *tt; // 售罄时为'出货',否则为'距今'
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/MapLabel.h
|
<gh_stars>0
//
// MapLabel.h
// FuSoft
//
// Created by FudonFuchina on 16/1/2.
// Copyright © 2016年 Fuhope. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface MapLabel : UILabel
@property (nonatomic,strong) CLLocation *location;
@property (nonatomic,copy) void (^block)(MapLabel *bLabel);
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSCryptorSupport.h
|
//
// FSCryptorSupport.h
// myhome
//
// Created by Fudongdong on 2017/8/28.
// Copyright © 2017年 fuhope. All rights reserved.
//
/*
A:明文密码;
B:明文密码的MD5;(真正使用的密码)
C:用B加密B后的值;
D:C的MD5,保存在数据库中
D:用一个safe_key加密的保存在本地的密码
*/
#import <Foundation/Foundation.h>
@interface FSCryptorSupport : NSObject
// 保存密码,password为未加密的用户记得的值
+ (BOOL)savePassword:(NSString *)_A;
// 本地的密码
+ (NSString *)localUserDefaultsCorePassword;
// 保存核心密码
+ (void)userDefaultsCorePassword:(NSString *)md5;
+ (void)userDefaultsCorePasswordForA:(NSString *)_A;
+ (void)changeMemoryPassword:(NSString *)_A;
// 获取数据库中存储的核心密码
+ (NSString *)theCorePasswordInSQLite;
+ (void)insertCorePasswordIntoSQLite:(NSString *)_A;
// A->D
+ (NSString *)makeD:(NSString *)_A;
+ (NSString *)md5:(NSString *)_A;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSInventoryController.h
|
<gh_stars>0
//
// FSInventoryController.h
// myhome
//
// Created by FudonFuchina on 2018/2/3.
// Copyright © 2018年 fuhope. All rights reserved.
//
#import "FSShakeBaseController.h"
@interface FSInventoryController : FSShakeBaseController
@property (nonatomic,copy) NSString *table;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSSqlite3BroswerController.h
|
<reponame>fuchina/FSPassword
//
// FSSqlite3BroswerController.h
// FSKit_Example
//
// Created by Fudongdong on 2018/2/6.
// Copyright © 2018年 topchuan. All rights reserved.
//
#import "FSBaseController.h"
@interface FSSqlite3BroswerController : FSBaseController
@property (nonatomic,copy) NSString *path;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSGesture/FSGestureView.h
|
<gh_stars>0
//
// FSGestureView.h
// myhome
//
// Created by FudonFuchina on 2017/8/31.
// Copyright © 2017年 fuhope. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface FSGestureView : UIView
@property (nonatomic,copy) void (^start)(void);
// 结果回调
@property (nonatomic,copy) void (^result)(NSString *bResult);
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSMakeQRController.h
|
//
// FSMakeQRController.h
// ShareEconomy
//
// Created by FudonFuchina on 16/7/3.
// Copyright © 2016年 FudonFuchina. All rights reserved.
//
#import "FSBaseController.h"
@interface FSMakeQRController : FSBaseController
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSWSKCell.h
|
//
// FSWSKCell.h
// FTK
//
// Created by fudon on 2017/2/3.
// Copyright © 2017年 fuhope. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface FSWSKCell : UITableViewCell
@property (nonatomic,strong) NSDictionary *dic;
@property (nonatomic,assign) NSInteger type; // 牌,王为13
@property (nonatomic, copy) void(^addAction)(NSInteger bType,NSInteger bColor); // 增加回调,bType:牌,bColor:黑1梅2红3方4
@property (nonatomic, copy) void(^deleteAction)(NSInteger bType,NSInteger bColor); // 删除回调,bType:牌,bColor:黑1梅2红3方4
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSGridController.h
|
<filename>FSPasswordSample/Pods/Headers/Public/FSJZBus/FSGridController.h
//
// FSGridController.h
// FSGrid
//
// Created by fudon on 2017/1/10.
// Copyright © 2017年 fuhope. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface FSGridController : UIViewController
@property (nonatomic,strong) NSArray<NSDictionary *> *dataSource;
@end
|
fuchina/FSPassword
|
FSPassword/classes/FSPwdModel.h
|
//
// FSPwdModel.h
// FSAccount
//
// Created by FudonFuchina on 2019/8/5.
//
#import "FSAppModel.h"
NS_ASSUME_NONNULL_BEGIN
@interface FSPwdModel : FSAppModel
+ (NSMutableArray *)searchText:(NSString *)text password:(NSString *)password;
@end
NS_ASSUME_NONNULL_END
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSSave.h
|
//
// FSSave.h
// FSSave
//
// Created by fudon on 2017/1/9.
// Copyright © 2017年 fuhope. All rights reserved.
//
/*
原理:存储NSSring/NSArray/NSDictionary/UIImage
总目录 = 可清理目录(图片缓存)+ 支持增删改查的目录 + 仅仅保存和查询的目录 (永久缓存,如保存的日记、提醒数据等)
可清理目录:定期自动清理和手动清理,目前只有图片缓存
不可清理目录:增删改查功能,模仿数据库
*/
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface FSSave : NSObject
// 图片保存
+ (void)saveImage:(UIImage *)image forKey:(NSString *)url;
+ (UIImage *)imageFromCacheWithUrl:(NSString *)url;
// 键值对保存(NSString/NSArray/NSDictionary)
+ (void)saveObject:(id)object forKey:(NSString *)key;
+ (id)objectForKey:(NSString *)key;
// 类数据库保存(NSString/NSDictioanry/NSArray)
// 增加
+ (void)addObject:(id)object table:(NSString *)table;
+ (NSArray *)selectWithTable:(NSString *)table condition:(NSString *)condition;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSDBCardsController.h
|
<gh_stars>0
//
// FSDBCardsController.h
// myhome
//
// Created by FudonFuchina on 2018/3/3.
// Copyright © 2018年 fuhope. All rights reserved.
//
#import "FSBaseController.h"
@interface FSDBCardsController : FSBaseController
@property (nonatomic,copy) NSString *zone;
@property (nonatomic,copy) NSString *name;
@property (nonatomic,copy) NSString *password;
@end
|
fuchina/FSPassword
|
FSPassword/classes/FSMakePasswordController.h
|
<reponame>fuchina/FSPassword
//
// FSMakePasswordController.h
// myhome
//
// Created by FudonFuchina on 2017/8/24.
// Copyright © 2017年 fuhope. All rights reserved.
//
#import "FSBaseController.h"
@interface FSMakePasswordController : FSBaseController
@property (nonatomic,copy) NSString *password;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/UITableViewCell+ShowDelete.h
|
//
// UITableViewCell+ShowDelete.h
// Expand
//
// Created by Fudongdong on 2017/11/3.
// Copyright © 2017年 china. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "FSShowDeleteView.h"
@interface UITableViewCell (ShowDelete)
@property (nonatomic,strong) FSShowDeleteView *view;
- (void)setView:(FSShowDeleteView *)view;
- (FSShowDeleteView *)view;
- (void)showNotice:(BOOL)show textIfShow:(NSString *)text andNotice:(NSString *)notice;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSAlertView.h
|
//
// FSAlertView.h
// Expand
//
// Created by Fudongdong on 2017/10/11.
// Copyright © 2017年 china. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface FSAlertView : UIView
@property (nonatomic,copy) void (^okCallback)(void);
@property (nonatomic,strong) NSArray<NSString *> *contents;
@property (nonatomic,copy) NSString *content;
+ (void)showList:(NSArray<NSString *> *)list callback:(void(^)(void))callback;
+ (void)showString:(NSString *)string callback:(void(^)(void))callback;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSPartListController.h
|
//
// FSPartListController.h
// myhome
//
// Created by fudon on 2017/2/16.
// Copyright © 2017年 fuhope. All rights reserved.
//
#import "FSBaseController.h"
@interface FSPartListController : FSBaseController
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSDouyingController.h
|
<reponame>fuchina/FSPassword<filename>FSPasswordSample/Pods/Headers/Public/FSJZBus/FSDouyingController.h
//
// FSDouyingController.h
// myhome
//
// Created by FudonFuchina on 2018/9/15.
// Copyright © 2018年 fuhope. All rights reserved.
//
#import "FSBaseController.h"
@interface FSDouyingController : FSBaseController
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSNetsController.h
|
<filename>FSPasswordSample/Pods/Headers/Public/FSJZBus/FSNetsController.h
//
// FSNetsController.h
// myhome
//
// Created by FudonFuchina on 2017/7/9.
// Copyright © 2017年 fuhope. All rights reserved.
//
#import "FSBaseController.h"
@interface FSNetsController : FSBaseController
@property (nonatomic,copy) void (^callback)(FSNetsController *bVC,NSString *bUrl);
@end
|
fuchina/FSPassword
|
FSPassword/classes/FSSixSystemController.h
|
//
// FSSixSystemController.h
// myhome
//
// Created by FudonFuchina on 2017/2/26.
// Copyright © 2017年 fuhope. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface FSSixSystemController : UIViewController
@property (nonatomic, strong) UILabel *noteLabel;
@property (nonatomic, strong) UITextField *textField;
@property (nonatomic, assign) NSInteger type;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FSPopupView.h
|
<gh_stars>0
//
// FSPopupView.h
// myhome
//
// Created by FudonFuchina on 2017/9/13.
// Copyright © 2017年 fuhope. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface FSPopupView : UIView
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/Headers/Public/FSJZBus/FuWeb.h
|
//
// FuWeb.h
// Daiyida
//
// Created by fudon on 14-10-17.
// Copyright (c) 2014年 ronglian. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "FSWebUrl.h"
typedef void(^SuccessBlock)(id dic);
typedef void(^FailBlock)(NSString *msg);
typedef enum{
FCReturnTypeDictionary = 0,
FCReturnTypeArray
}FCReturnType;
typedef enum{
FCRequestTypeAsync = 0,
FCRequestTypeSync
}FCRequestType;
@interface FuWeb : NSObject
@property (nonatomic, strong) id syncObject;
@property (nonatomic, assign) FCRequestType requestType;
@property (nonatomic,assign) FCReturnType returnType;
@property (nonatomic, copy) SuccessBlock successBlock;
@property (nonatomic, copy) FailBlock failBlock;
+ (void)requestWithUrl:(NSString *)url params:(NSDictionary *)bDic successBlock:(SuccessBlock)successBlock failBlock:(FailBlock)failBlock;
+ (void)requestWithUrl:(NSString *)url params:(NSDictionary *)bDic fileName:(NSString *)fileName imageData:(NSData *)imageData successBlock:(SuccessBlock)successBlock failBlock:(FailBlock)failBlock;
+ (void)pictureUrl:(NSString *)urlString successBlock:(SuccessBlock)successBlock failBlock:(FailBlock)failBlock;
@end
|
fuchina/FSPassword
|
FSPasswordSample/Pods/FSJZBus/FSJZBus/classes/FSInventoryModel.h
|
<reponame>fuchina/FSPassword
//
// FSInventoryModel.h
// myhome
//
// Created by FudonFuchina on 2018/2/4.
// Copyright © 2018年 fuhope. All rights reserved.
//
#import "FSIMBaseModel.h"
@interface FSInventoryModel : FSIMBaseModel
@property (nonatomic,strong) NSNumber *aid;
@property (nonatomic,copy) NSString *ctime; //数据创建时间
@property (nonatomic,copy) NSString *gid; // 商品id
@property (nonatomic,copy) NSString *name; // 商品名称
@property (nonatomic,copy) NSString *type; // 商品类型
@property (nonatomic,copy) NSString *time; // 进货时间
@property (nonatomic,copy) NSString *cost; // 进价
@property (nonatomic,copy) NSString *num; // 数目
@property (nonatomic,copy) NSString *rest; // 剩余
@property (nonatomic,copy) NSString *done; // 售罄,一个时间秒数
@property (nonatomic,copy) NSString *sale; // 回收
+ (NSArray<NSString *> *)tableFields;
@end
|
fuchina/FSPassword
|
FSPassword/classes/FSOldPasswordSystemController.h
|
<gh_stars>0
//
// FSOldPasswordSystemController.h
// myhome
//
// Created by FudonFuchina on 2018/8/25.
// Copyright © 2018年 fuhope. All rights reserved.
//
#import "FSBaseController.h"
@interface FSOldPasswordSystemController : FSBaseController
@end
|
BitBangGaming/Piggy-Pad-Firmware-Workspace
|
N64_Piggy_Pad_Cable/Inc/io_mapping_stm32f411ce_blackpill_weactstudio_v3_0.h
|
<filename>N64_Piggy_Pad_Cable/Inc/io_mapping_stm32f411ce_blackpill_weactstudio_v3_0.h
#ifndef IO_MAPPING_STM32F411CE_BLACKPILL_WEACTSTUDIO_V3_0_H_
#define IO_MAPPING_STM32F411CE_BLACKPILL_WEACTSTUDIO_V3_0_H_
/* Pins for leds */
#define BLUE_LED_PIN (13U)
#define BLUE_LED_PIN_HAL (GPIO_PIN_13)
#define BLUE_LED_PORT (GPIOC)
#define BLUE_LED_BIT (1 << BLUE_LED_PIN)
/* Pins for n64 communication */
#define COMMS_N64_STOP_PIN (5U)
#define COMMS_N64_STOP_PIN_HAL (GPIO_PIN_5)
#define COMMS_N64_STOP_PORT (GPIOB)
#define COMMS_N64_STOP_BIT (1 << COMMS_N64_STOP_PIN)
#define COMMS_N64_STOP_SET (GPIO_BSRR_BS5)
#define COMMS_N64_STOP_CLEAR (GPIO_BSRR_BR5)
#define COMMS_N64_TX_PIN (6U)
#define COMMS_N64_TX_PIN_HAL (GPIO_PIN_6)
#define COMMS_N64_TX_PORT (GPIOB)
#define COMMS_N64_TX_BIT (1 << COMMS_N64_TX_PIN)
#define COMMS_N64_RX_PIN (7U)
#define COMMS_N64_RX_PIN_HAL (GPIO_PIN_7)
#define COMMS_N64_RX_PORT (GPIOB)
#define COMMS_N64_RX_BIT (1 << COMMS_N64_RX_PIN)
#define COMMS_N64_PULLUP_PIN (8U)
#define COMMS_N64_PULLUP_PIN_HAL (GPIO_PIN_8)
#define COMMS_N64_PULLUP_PORT (GPIOB)
#define COMMS_N64_PULLUP_BIT (1 << COMMS_N64_PULLUP_PIN)
#endif
|
BitBangGaming/Piggy-Pad-Firmware-Workspace
|
N64_Piggy_Pad_Cable/Inc/comms_n64_console.h
|
#ifndef COMMS_N64_CONSOLE_H_
#define COMMS_N64_CONSOLE_H_
#include <stdint.h>
#include "stm32f4xx_hal.h"
#include "io_mapping_stm32f411ce_blackpill_weactstudio_v3_0.h"
// Macros
/* Byte order for N64 controller reponse */
#define N64_A_B 0
#define N64_Z_START 1
#define N64_DU_DD 2
#define N64_DL_DR 3
#define N64_RESET_RESERVED 4
#define N64_L_R 5
#define N64_CU_CD 6
#define N64_CL_CR 7
#define N64_X_AXIS_BIT7_BIT6 8
#define N64_X_AXIS_BIT5_BIT4 9
#define N64_X_AXIS_BIT3_BIT2 10
#define N64_X_AXIS_BIT1_BIT0 11
#define N64_Y_AXIS_BIT7_BIT6 12
#define N64_Y_AXIS_BIT5_BIT4 13
#define N64_Y_AXIS_BIT3_BIT2 14
#define N64_Y_AXIS_BIT1_BIT0 15
/* Byte order for N64 controller registers */
#define N64_BYTE1 0
#define N64_BYTE2 1
#define N64_BYTE3 2
#define N64_BYTE4 3
/* Bit positions for N64 controller registers */
#define N64_BYTE1_DR 0
#define N64_BYTE1_DL 1
#define N64_BYTE1_DD 2
#define N64_BYTE1_DU 3
#define N64_BYTE1_START 4
#define N64_BYTE1_Z 5
#define N64_BYTE1_B 6
#define N64_BYTE1_A 7
#define N64_BYTE2_CR 0
#define N64_BYTE2_CL 1
#define N64_BYTE2_CD 2
#define N64_BYTE2_CU 3
#define N64_BYTE2_R 4
#define N64_BYTE2_L 5
#define N64_BYTE2_RESERVED 6
#define N64_BYTE2_RESET 7
/* The below macros help to translate a uart byte to n64 bits. For
* example, when looking at the n64 controller as a device that has
* built in registers, the structure will look as follows
* (remember, the controller responds with 4 bytes when being polled):
*
* BIT #: 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
* BYTE 1: A | B | Z | START| DU | DD | DL| DR
* BYTE 2: RESET | RESERVED| L | R | CU | CD | CL| CR
* BYTE 3: X AXIS
* BYTE 4: Y AXIS
*
* It's worth noting that the n64 controller sends the information
* from bit 7 to bit 0, as defined above.
*
* If you acquire the controller response and look at the controllerResponse
* array, you can view each element as two n64 bits. The elements of the array
* are mapped to the n64 registers as follows:
*
* controllerResponse[0] = A & B
* controllerResponse[1] = Z & START
* controllerResponse[2] = DU & DD
* controllerResponse[3] = DL & DR
* controllerResponse[4] = RESET & RESERVED
* controllerResponse[5] = L & R
* controllerResponse[6] = CU & CD
* controllerResponse[7] = CL & CR
* controllerResponse[8] = X AXIS BIT 7 & X AXIS BIT 6
* controllerResponse[9] = X AXIS BIT 5 & X AXIS BIT 4
* controllerResponse[10] = X AXIS BIT 3 & X AXIS BIT 2
* controllerResponse[11] = X AXIS BIT 1 & X AXIS BIT 0
* controllerResponse[12] = Y AXIS BIT 7 & X AXIS BIT 6
* controllerResponse[13] = Y AXIS BIT 5 & X AXIS BIT 4
* controllerResponse[14] = Y AXIS BIT 3 & X AXIS BIT 2
* controllerResponse[15] = Y AXIS BIT 1 & X AXIS BIT 0
*
* Taking controllerResponse[1] as an example let's say you find a
* 0xE8 or 0xC8. The macros hints at the binary state of 01. This means
* Z = 0 & START = 1. Or Z = RELEASED & START = PUSHED. The reason for
* two different cases per binary combination is because since this
* code uses a uart to send and receive n64 data, there are edge cases
* in sampling that don't always give a consistent value. If the baud rate
* was set appropriately, this would not be the case. But I was not able
* to find an ideal baud rate. But fortunately the cases are unique to
* their respective binary combinations. This makes parsing possible
* to successful populate the controllerRegisters array.
*/
#define UART_BYTE_2_N64_BITS_00_CASE1 0x08
#define UART_BYTE_2_N64_BITS_00_CASE2 0x88
#define UART_BYTE_2_N64_BITS_01_CASE1 0xE8
#define UART_BYTE_2_N64_BITS_01_CASE2 0xC8
#define UART_BYTE_2_N64_BITS_10_CASE1 0x0F
#define UART_BYTE_2_N64_BITS_10_CASE2 0x8F
#define UART_BYTE_2_N64_BITS_11_CASE1 0xEF
#define UART_BYTE_2_N64_BITS_11_CASE2 0xCF
#define MAX_CONTROLLER_RESPONSE 16
#define MAX_CONTROLLER_REGISTER 4
// Module specific enums
typedef enum
{
N64_NOPULL = 0,
N64_PULLUP
} N64PullupState_t;
// Private Variables
static UART_HandleTypeDef huart1;
/* The controllerRepsonse array is what the uart received from the controller.
* This array needs to be parsed properly to convert the uart bytes into n64 bytes
* in order to make any sense of it. To understand how this is structured, look
* at the macros section of this file.
*/
static uint8_t controllerResponse[MAX_CONTROLLER_RESPONSE];
/* The controllerRegisters array is the result after parsing the controllerResponse
* array. Here is the n64 register structure for convenience:
*
* BIT #: 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
* BYTE 1: A | B | Z | START | DU | DD | DL| DR
* BYTE 2: RESET | RESERVED| L | R | CU | CD | CL| CR
* BYTE 3: X AXIS
* BYTE 4: Y AXIS
*
* Here is the mapping from the controllerResponse array to the n64 registers:
*
* controllerRegisters[0] = BYTE 1
* controllerRegisters[1] = BYTE 2
* controllerRegisters[2] = BYTE 3
* controllerRegisters[3] = BYTE 4
*
* This array structure maintains easy readability when comparing to the
* actual n64 data response when using a logic analyzer and is easy
* to grab input states by bitwise manipulation.
*/
uint8_t controllerRegisters[MAX_CONTROLLER_REGISTER];
// Initializer
void CommsN64Console_Init(void);
// Parsers
void CommsN64Console_ParseContollerInputs(void);
// Setters
void CommsN64Console_SetPullup(N64PullupState_t);
inline void CommsN64Console_SendStopBit(void);
// Getters
inline void CommsN64Console_GetContollerStatus(void);
inline void CommsN64Console_GetContollerInputs(void);
#endif
|
BitBangGaming/Piggy-Pad-Firmware-Workspace
|
N64_Piggy_Pad_Cable/Inc/main.h
|
<filename>N64_Piggy_Pad_Cable/Inc/main.h
#ifndef MAIN_H_
#define MAIN_H_
#include <stdint.h>
#include "stm32f4xx_hal.h"
#include "io_mapping_stm32f411ce_blackpill_weactstudio_v3_0.h"
#include "comms_n64_console.h"
// Macros
/* Bit positions for MSI register */
#define MSI_UPPER_LEFT 0
#define MSI_UPPER_RIGHT 1
#define MSI_UPPER_DOWN 2
#define MSI_UPPER_UP 3
#define MSI_UPPER_START 4
#define MSI_UPPER_SELECT 5
#define MSI_UPPER_HOME 6
#define MSI_UPPER_BIT7 7
#define MSI_LOWER_1P 0
#define MSI_LOWER_2P 1
#define MSI_LOWER_3P 2
#define MSI_LOWER_4P 3
#define MSI_LOWER_1K 4
#define MSI_LOWER_2K 5
#define MSI_LOWER_3K 6
#define MSI_LOWER_4K 7
// Private enums
static GPIO_PinState BLUE_LED_ON = GPIO_PIN_RESET;
static GPIO_PinState BLUE_LED_OFF = GPIO_PIN_SET;
// Private variables
/* Structure of MSI upper byte
* BIT #: 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
* BUTTON: 1 | HOME | SELECT | START | UP | DOWN | RIGHT | LEFT
* N64: 1 | Z | 0 | START | DU | DD | DR | DL
*/
static uint8_t registerMSIupper;
/* Structure of MSI lower byte
* BIT #: 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
* BUTTON: 4K | 3K | 2K | 1K | 4P | 3P | 2P | 1P
* N64: L | CR | CD | A | R | CU | CL | B
*/
static uint8_t registerMSIlower;
/* Structure of LSX upper byte
* BIT #: 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
* BUTTON: 0 | 0 | 0 | 0 | XBIT11 | XBIT10 | XBIT9 | XBIT8
* N64: 0 | 0 | 0 | 0 | 'XBIT11 | 'XBIT10 | 'XBIT9 | 'XBIT8
* Note that the bits from N64 are not one to one. That means
* these bits need to come from a conversion. In other words,
* the 8 bit axis value must be converted to a 12 bit axis value.
*/
static uint8_t registerLSXupper;
/* Structure of LSY upper byte
* BIT #: 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
* BUTTON: XBIT7 | XBIT6 | XBIT5 | XBIT4 | XBIT3 | XBIT2 | XBIT1 | XBIT0
* N64: 'XBIT7 | 'XBIT6 | 'XBIT5 | 'XBIT4 | 'XBIT3 | 'XBIT2 | 'XBIT1 | 'XBIT0
* Note that the bits from N64 are not one to one. That means
* these bits need to come from a conversion. In other words,
* the 8 bit axis value must be converted to a 12 bit axis value.
*/
static uint8_t registerLSYupper;
// Initializer
void Main_Init(void);
// Setters
void Main_SetBlueLed(GPIO_PinState);
void Main_SetRegisters(void);
// Misc
void SystemClock_Config(void);
#endif
|
BitBangGaming/Piggy-Pad-Firmware-Workspace
|
N64_Piggy_Pad_Cable/Src/comms_n64_console.c
|
#include "comms_n64_console.h"
// Initializer
void CommsN64Console_Init()
{
/* Set parameters for n64 communication pins */
// Clocks
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_USART1_CLK_ENABLE();
// Init structure
GPIO_InitTypeDef GPIO_InitStruct_CommsN64Console = {0};
// Stop bit control
GPIO_InitStruct_CommsN64Console.Pin = COMMS_N64_STOP_PIN_HAL;
GPIO_InitStruct_CommsN64Console.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStruct_CommsN64Console.Pull = GPIO_NOPULL;
GPIO_InitStruct_CommsN64Console.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
HAL_GPIO_Init(COMMS_N64_STOP_PORT, &GPIO_InitStruct_CommsN64Console);
COMMS_N64_STOP_PORT->BSRR = COMMS_N64_STOP_SET;
// External pullup control
GPIO_InitStruct_CommsN64Console.Pin = COMMS_N64_PULLUP_PIN_HAL;
GPIO_InitStruct_CommsN64Console.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct_CommsN64Console.Pull = GPIO_NOPULL;
GPIO_InitStruct_CommsN64Console.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(COMMS_N64_PULLUP_PORT, &GPIO_InitStruct_CommsN64Console);
// USART1 TX/RX
GPIO_InitStruct_CommsN64Console.Pin = COMMS_N64_TX_PIN_HAL | COMMS_N64_RX_PIN_HAL;
GPIO_InitStruct_CommsN64Console.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct_CommsN64Console.Alternate = GPIO_AF7_USART1;
GPIO_InitStruct_CommsN64Console.Pull = GPIO_NOPULL;
GPIO_InitStruct_CommsN64Console.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
HAL_GPIO_Init(COMMS_N64_TX_PORT, &GPIO_InitStruct_CommsN64Console);
// Configure USART1
huart1.Instance = USART1;
huart1.Init.BaudRate = 1300000; // Started w/ 1,250,000 but experiments show 1,300,000 is more robust
huart1.Init.WordLength = USART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_8;
HAL_UART_Init(&huart1);
}
void CommsN64Console_SetPullup(N64PullupState_t pull)
{
if(pull == N64_NOPULL)
{
HAL_GPIO_WritePin(COMMS_N64_PULLUP_PORT, COMMS_N64_PULLUP_PIN_HAL, GPIO_PIN_RESET);
}
else if(pull == N64_PULLUP)
{
HAL_GPIO_WritePin(COMMS_N64_PULLUP_PORT, COMMS_N64_PULLUP_PIN_HAL, GPIO_PIN_SET);
}
else
{
// invalid argument
}
}
void CommsN64Console_SendStopBit()
{
/* The timing of the stop bit does not need to be so precise. */
COMMS_N64_STOP_PORT->BSRR = COMMS_N64_STOP_CLEAR;
volatile uint32_t counter = 1;
while(counter--);
COMMS_N64_STOP_PORT->BSRR = COMMS_N64_STOP_SET;
}
// Parsers
void CommsN64Console_ParseContollerInputs()
{
// Helper variables
uint8_t leftBit = 0;
uint8_t rightBit = 0;
/* TODO: Improve the algorithm below. It was made just to ensure functionality
* but it ought to be better coded.
*/
// Update n64 register, byte 1
for(uint8_t j = 0; j < 4; j = j + 1)
{
// Choose "left" and "right" bits
switch(j)
{
case 0:
leftBit = 7;
rightBit = 6;
break;
case 1:
leftBit = 5;
rightBit = 4;
break;
case 2:
leftBit = 3;
rightBit = 2;
break;
case 3:
leftBit = 1;
rightBit = 0;
break;
default:
break;
}
// Manipulate the chosen bits
if( (controllerResponse[j] == UART_BYTE_2_N64_BITS_00_CASE1) ||
(controllerResponse[j] == UART_BYTE_2_N64_BITS_00_CASE2) )
{
controllerRegisters[N64_BYTE1] &= ~(1 << leftBit);
controllerRegisters[N64_BYTE1] &= ~(1 << rightBit);
}
else if( (controllerResponse[j] == UART_BYTE_2_N64_BITS_01_CASE1) ||
(controllerResponse[j] == UART_BYTE_2_N64_BITS_01_CASE2) )
{
controllerRegisters[N64_BYTE1] &= ~(1 << leftBit);
controllerRegisters[N64_BYTE1] |= (1 << rightBit);
}
else if( (controllerResponse[j] == UART_BYTE_2_N64_BITS_10_CASE1) ||
(controllerResponse[j] == UART_BYTE_2_N64_BITS_10_CASE2) )
{
controllerRegisters[N64_BYTE1] |= (1 << leftBit);
controllerRegisters[N64_BYTE1] &= ~(1 << rightBit);
}
else if( (controllerResponse[j] == UART_BYTE_2_N64_BITS_11_CASE1) ||
(controllerResponse[j] == UART_BYTE_2_N64_BITS_11_CASE2) )
{
controllerRegisters[N64_BYTE1] |= (1 << leftBit);
controllerRegisters[N64_BYTE1] |= (1 << rightBit);
}
else
{
// invalid
}
}
// Update n64 register, byte 2
for(uint8_t j = 4; j < 8; j = j + 1)
{
// Choose "left" and "right" bits
switch(j)
{
case 4:
leftBit = 7;
rightBit = 6;
break;
case 5:
leftBit = 5;
rightBit = 4;
break;
case 6:
leftBit = 3;
rightBit = 2;
break;
case 7:
leftBit = 1;
rightBit = 0;
break;
default:
break;
}
// Manipulate the chosen bits
if( (controllerResponse[j] == UART_BYTE_2_N64_BITS_00_CASE1) ||
(controllerResponse[j] == UART_BYTE_2_N64_BITS_00_CASE2) )
{
controllerRegisters[N64_BYTE2] &= ~(1 << leftBit);
controllerRegisters[N64_BYTE2] &= ~(1 << rightBit);
}
else if( (controllerResponse[j] == UART_BYTE_2_N64_BITS_01_CASE1) ||
(controllerResponse[j] == UART_BYTE_2_N64_BITS_01_CASE2) )
{
controllerRegisters[N64_BYTE2] &= ~(1 << leftBit);
controllerRegisters[N64_BYTE2] |= (1 << rightBit);
}
else if( (controllerResponse[j] == UART_BYTE_2_N64_BITS_10_CASE1) ||
(controllerResponse[j] == UART_BYTE_2_N64_BITS_10_CASE2) )
{
controllerRegisters[N64_BYTE2] |= (1 << leftBit);
controllerRegisters[N64_BYTE2] &= ~(1 << rightBit);
}
else if( (controllerResponse[j] == UART_BYTE_2_N64_BITS_11_CASE1) ||
(controllerResponse[j] == UART_BYTE_2_N64_BITS_11_CASE2) )
{
controllerRegisters[N64_BYTE2] |= (1 << leftBit);
controllerRegisters[N64_BYTE2] |= (1 << rightBit);
}
else
{
// invalid
}
}
// Update n64 register, byte 3
for(uint8_t j = 8; j < 12; j = j + 1)
{
// Choose "left" and "right" bits
switch(j)
{
case 8:
leftBit = 7;
rightBit = 6;
break;
case 9:
leftBit = 5;
rightBit = 4;
break;
case 10:
leftBit = 3;
rightBit = 2;
break;
case 11:
leftBit = 1;
rightBit = 0;
break;
default:
break;
}
// Manipulate the chosen bits
if( (controllerResponse[j] == UART_BYTE_2_N64_BITS_00_CASE1) ||
(controllerResponse[j] == UART_BYTE_2_N64_BITS_00_CASE2) )
{
controllerRegisters[N64_BYTE3] &= ~(1 << leftBit);
controllerRegisters[N64_BYTE3] &= ~(1 << rightBit);
}
else if( (controllerResponse[j] == UART_BYTE_2_N64_BITS_01_CASE1) ||
(controllerResponse[j] == UART_BYTE_2_N64_BITS_01_CASE2) )
{
controllerRegisters[N64_BYTE3] &= ~(1 << leftBit);
controllerRegisters[N64_BYTE3] |= (1 << rightBit);
}
else if( (controllerResponse[j] == UART_BYTE_2_N64_BITS_10_CASE1) ||
(controllerResponse[j] == UART_BYTE_2_N64_BITS_10_CASE2) )
{
controllerRegisters[N64_BYTE3] |= (1 << leftBit);
controllerRegisters[N64_BYTE3] &= ~(1 << rightBit);
}
else if( (controllerResponse[j] == UART_BYTE_2_N64_BITS_11_CASE1) ||
(controllerResponse[j] == UART_BYTE_2_N64_BITS_11_CASE2) )
{
controllerRegisters[N64_BYTE3] |= (1 << leftBit);
controllerRegisters[N64_BYTE3] |= (1 << rightBit);
}
else
{
// invalid
}
}
// Update n64 register, byte 3
for(uint8_t j = 12; j < 16; j = j + 1)
{
// Choose "left" and "right" bits
switch(j)
{
case 12:
leftBit = 7;
rightBit = 6;
break;
case 13:
leftBit = 5;
rightBit = 4;
break;
case 14:
leftBit = 3;
rightBit = 2;
break;
case 15:
leftBit = 1;
rightBit = 0;
break;
default:
break;
}
// Manipulate the chosen bits
if( (controllerResponse[j] == UART_BYTE_2_N64_BITS_00_CASE1) ||
(controllerResponse[j] == UART_BYTE_2_N64_BITS_00_CASE2) )
{
controllerRegisters[N64_BYTE4] &= ~(1 << leftBit);
controllerRegisters[N64_BYTE4] &= ~(1 << rightBit);
}
else if( (controllerResponse[j] == UART_BYTE_2_N64_BITS_01_CASE1) ||
(controllerResponse[j] == UART_BYTE_2_N64_BITS_01_CASE2) )
{
controllerRegisters[N64_BYTE4] &= ~(1 << leftBit);
controllerRegisters[N64_BYTE4] |= (1 << rightBit);
}
else if( (controllerResponse[j] == UART_BYTE_2_N64_BITS_10_CASE1) ||
(controllerResponse[j] == UART_BYTE_2_N64_BITS_10_CASE2) )
{
controllerRegisters[N64_BYTE4] |= (1 << leftBit);
controllerRegisters[N64_BYTE4] &= ~(1 << rightBit);
}
else if( (controllerResponse[j] == UART_BYTE_2_N64_BITS_11_CASE1) ||
(controllerResponse[j] == UART_BYTE_2_N64_BITS_11_CASE2) )
{
controllerRegisters[N64_BYTE4] |= (1 << leftBit);
controllerRegisters[N64_BYTE4] |= (1 << rightBit);
}
else
{
// invalid
}
}
}
void CommsN64Console_GetContollerStatus()
{
// Future implementation
}
void CommsN64Console_GetContollerInputs()
{
/* Send send a byte of data to the n64, you must send 4 bytes of data from
* the usart1 module. This means that for every byte sent byte sent by
* usart1, 2 bits are transferred to the n64 data line. Note that at the
* end of the 4th byte sent from usart1, a stop bit must be sent. It is
* possible to send 0xFF from usart1 to achieve this but the n64 controller
* will respond before the usart1 transmission of 0xFF is complete. Instead
* we can tie another open drain output to the n64 data line. When the 4th
* usart1 byte is sent, we can toggle this additional open drain output. Doing
* so will act as a stop but required for the n64 protocol. After this is
* performed, there is about 2.5 microseconds left before the n64 controller
* begins to respond. For a STM32F411CE running at 100MHz, this be more than
* enough time to prepare a way to capture the data.
*/
// Disable the receiver
USART1->CR1 &= ~USART_CR1_RE;
// Make sure the transmit data register is empty before sending next byte
while(!(USART1->SR & USART_SR_TXE)){};
// Send a byte (2 n64 bits)
USART1->DR = (UART_BYTE_2_N64_BITS_00_CASE1 & 0xFF);
// Make sure the transmit data register is empty before sending a byte
while(!(USART1->SR & USART_SR_TXE)){};
// Send a byte (2 n64 bits)
USART1->DR = (UART_BYTE_2_N64_BITS_00_CASE1 & 0xFF);
// Make sure the transmit data register is empty before sending a byte
while(!(USART1->SR & USART_SR_TXE)){};
// Send a byte (2 n64 bits)
USART1->DR = (UART_BYTE_2_N64_BITS_00_CASE1 & 0xFF);
// Make sure the transmit data register is empty before sending a byte
while(!(USART1->SR & USART_SR_TXE)){};
// Send a byte (2 n64 bits)
USART1->DR = (UART_BYTE_2_N64_BITS_01_CASE1 & 0xFF);
// Make sure the last uart byte transmission is complete before sending stop bit
while(!(USART1->SR & USART_SR_TC)){};
CommsN64Console_SendStopBit();
/* Receive 4 n64 bytes from the controller. This means that our uart will
* have to receive 16 bytes because 1 uart byte = 2 n64 bits and therefore
* 4 uart bytes = 1 n64 byte. But remember, the controller will send a stop
* bit after this 4 n64 byte transmission. That means the uart receiver must
* be disabled after the last acquired byte. Of course before grabbing the
* first byte, enabled the uart receiver.
*/
// Enable the uart receiver
USART1->CR1 |= USART_CR1_RE;
// Grab states for A and B
while(!(USART1->SR & USART_SR_RXNE)){};
controllerResponse[N64_A_B] = USART1->DR;
// Grab states for Z and START
while(!(USART1->SR & USART_SR_RXNE)){};
controllerResponse[N64_Z_START] = USART1->DR;
// Grab states for DU and DD
while(!(USART1->SR & USART_SR_RXNE)){};
controllerResponse[N64_DU_DD] = USART1->DR;
// Grab states for DL and DR
while(!(USART1->SR & USART_SR_RXNE)){};
controllerResponse[N64_DL_DR] = USART1->DR;
// Grab states for RESET and RESERVED
while(!(USART1->SR & USART_SR_RXNE)){};
controllerResponse[N64_RESET_RESERVED] = USART1->DR;
// Grab states for L and R
while(!(USART1->SR & USART_SR_RXNE)){};
controllerResponse[N64_L_R] = USART1->DR;
// Grab states for CU and CD
while(!(USART1->SR & USART_SR_RXNE)){};
controllerResponse[N64_CU_CD] = USART1->DR;
// Grab states for CL and CR
while(!(USART1->SR & USART_SR_RXNE)){};
controllerResponse[N64_CL_CR] = USART1->DR;
// Grab states for X-AXIS BIT7 & BIT6
while(!(USART1->SR & USART_SR_RXNE)){};
controllerResponse[N64_X_AXIS_BIT7_BIT6] = USART1->DR;
// Grab states for X-AXIS BIT5 & BIT4
while(!(USART1->SR & USART_SR_RXNE)){};
controllerResponse[N64_X_AXIS_BIT5_BIT4] = USART1->DR;
// Grab states for X-AXIS BIT3 & BIT2
while(!(USART1->SR & USART_SR_RXNE)){};
controllerResponse[N64_X_AXIS_BIT3_BIT2] = USART1->DR;
// Grab states for X-AXIS BIT1 & BIT0
while(!(USART1->SR & USART_SR_RXNE)){};
controllerResponse[N64_X_AXIS_BIT1_BIT0] = USART1->DR;
// Grab states for Y-AXIS BIT7 & BIT6
while(!(USART1->SR & USART_SR_RXNE)){};
controllerResponse[N64_Y_AXIS_BIT7_BIT6] = USART1->DR;
// Grab states for Y-AXIS BIT5 & BIT4
while(!(USART1->SR & USART_SR_RXNE)){};
controllerResponse[N64_Y_AXIS_BIT5_BIT4] = USART1->DR;
// Grab states for Y-AXIS BIT3 & BIT2
while(!(USART1->SR & USART_SR_RXNE)){};
controllerResponse[N64_Y_AXIS_BIT3_BIT2] = USART1->DR;
// Grab states for Y-AXIS BIT1 & BIT0
while(!(USART1->SR & USART_SR_RXNE)){};
controllerResponse[N64_Y_AXIS_BIT1_BIT0] = USART1->DR;
// Disable the receiver
USART1->CR1 &= ~USART_CR1_RE;
/* Debugging code for logic analyzer
* To use this, simply uncomment it, hook up your n64 data
* line to a logic analyzer and observe a byte sent right
* after the n64 controller responds.
*/
// HAL_Delay(2);
// while(!(USART1->SR & USART_SR_TXE)){};
// USART1->DR = (<byte to send> & 0xFF);
// while(!(USART1->SR & USART_SR_TC)){};
// HAL_Delay(5);
}
|
BitBangGaming/Piggy-Pad-Firmware-Workspace
|
N64_Piggy_Pad_Cable/Src/main.c
|
#include "main.h"
int main(void)
{
/* Initialize all required modules and clocks */
HAL_Init();
SystemClock_Config();
CommsN64Console_Init();
Main_Init();
/* Apply a pullup on n64 data line */
CommsN64Console_SetPullup(N64_PULLUP);
/* Give some delay for initialization */
HAL_Delay(100);
/* Main application loop */
while(1)
{
// Add about 100us of delay (mcu clock dependent)
volatile uint32_t counter = 200;
while(counter--);
// Poll for n64 controller state
CommsN64Console_GetContollerInputs();
// Parse inputs from controller
CommsN64Console_ParseContollerInputs();
// Update registers for BBG control board
Main_SetRegisters();
// Send registers to BBG control board
HAL_Delay(2);
while(!(USART1->SR & USART_SR_TXE)){};
USART1->DR = (registerMSIlower & 0xFF);
while(!(USART1->SR & USART_SR_TC)){};
HAL_Delay(2);
}
}
// Setters
void Main_SetBlueLed(GPIO_PinState pinState)
{
HAL_GPIO_WritePin(BLUE_LED_PORT, BLUE_LED_PIN_HAL, pinState);
}
void Main_SetRegisters()
{
// Helper variable
uint8_t bitState;
/* Update the MSI upper byte register */
// BIT7
registerMSIupper |= (1 << MSI_UPPER_BIT7);
// HOME
bitState = (controllerRegisters[0] >> N64_BYTE1_Z) & (0x01);
if(bitState == 0x01)
{
registerMSIupper &= ~(1 << MSI_UPPER_HOME);
}
else
{
registerMSIupper |= (1 << MSI_UPPER_HOME);
}
// SELECT
registerMSIupper &= ~(1 << MSI_UPPER_SELECT);
// START
bitState = (controllerRegisters[0] >> N64_BYTE1_START) & (0x01);
if(bitState == 0x01)
{
registerMSIupper &= ~(1 << MSI_UPPER_START);
}
else
{
registerMSIupper |= (1 << MSI_UPPER_START);
}
// UP
bitState = (controllerRegisters[0] >> N64_BYTE1_DU) & (0x01);
if(bitState == 0x01)
{
registerMSIupper &= ~(1 << MSI_UPPER_UP);
}
else
{
registerMSIupper |= (1 << MSI_UPPER_UP);
}
// DOWN
bitState = (controllerRegisters[0] >> N64_BYTE1_DD) & (0x01);
if(bitState == 0x01)
{
registerMSIupper &= ~(1 << MSI_UPPER_DOWN);
}
else
{
registerMSIupper |= (1 << MSI_UPPER_DOWN);
}
// RIGHT
bitState = (controllerRegisters[0] >> N64_BYTE1_DR) & (0x01);
if(bitState == 0x01)
{
registerMSIupper &= ~(1 << MSI_UPPER_RIGHT);
}
else
{
registerMSIupper |= (1 << MSI_UPPER_RIGHT);
}
// LEFT
bitState = (controllerRegisters[0] >> N64_BYTE1_DL) & (0x01);
if(bitState == 0x01)
{
registerMSIupper &= ~(1 << MSI_UPPER_LEFT);
}
else
{
registerMSIupper |= (1 << MSI_UPPER_LEFT);
}
// 4K
bitState = (controllerRegisters[1] >> N64_BYTE2_L) & (0x01);
if(bitState == 0x01)
{
registerMSIlower &= ~(1 << MSI_LOWER_4K);
}
else
{
registerMSIlower |= (1 << MSI_LOWER_4K);
}
// 3K
bitState = (controllerRegisters[1] >> N64_BYTE2_CR) & (0x01);
if(bitState == 0x01)
{
registerMSIlower &= ~(1 << MSI_LOWER_3K);
}
else
{
registerMSIlower |= (1 << MSI_LOWER_3K);
}
// 2K
bitState = (controllerRegisters[1] >> N64_BYTE2_CD) & (0x01);
if(bitState == 0x01)
{
registerMSIlower &= ~(1 << MSI_LOWER_2K);
}
else
{
registerMSIlower |= (1 << MSI_LOWER_2K);
}
// 1K
bitState = (controllerRegisters[0] >> N64_BYTE1_A) & (0x01);
if(bitState == 0x01)
{
registerMSIlower &= ~(1 << MSI_LOWER_1K);
}
else
{
registerMSIlower |= (1 << MSI_LOWER_1K);
}
// 4P
bitState = (controllerRegisters[1] >> N64_BYTE2_R) & (0x01);
if(bitState == 0x01)
{
registerMSIlower &= ~(1 << MSI_LOWER_4P);
}
else
{
registerMSIlower |= (1 << MSI_LOWER_4P);
}
// 3P
bitState = (controllerRegisters[1] >> N64_BYTE2_CU) & (0x01);
if(bitState == 0x01)
{
registerMSIlower &= ~(1 << MSI_LOWER_3P);
}
else
{
registerMSIlower |= (1 << MSI_LOWER_3P);
}
// 2P
bitState = (controllerRegisters[1] >> N64_BYTE2_CL) & (0x01);
if(bitState == 0x01)
{
registerMSIlower &= ~(1 << MSI_LOWER_2P);
}
else
{
registerMSIlower |= (1 << MSI_LOWER_2P);
}
// 1P
bitState = (controllerRegisters[0] >> N64_BYTE1_B) & (0x01);
if(bitState == 0x01)
{
registerMSIlower &= ~(1 << MSI_LOWER_1P);
}
else
{
registerMSIlower |= (1 << MSI_LOWER_1P);
}
}
// Initializer
void Main_Init()
{
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct_Main = {0};
GPIO_InitStruct_Main.Pin = GPIO_PIN_8;
GPIO_InitStruct_Main.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct_Main.Pull = GPIO_NOPULL;
GPIO_InitStruct_Main.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct_Main.Alternate = GPIO_AF0_MCO;
/* Only enable below if you want to check the clock
* frequency.
*/
//HAL_GPIO_Init(GPIOA, &GPIO_InitStruct_Main);
/* Initialize the blue led */
__HAL_RCC_GPIOC_CLK_ENABLE();
GPIO_InitStruct_Main.Pin = BLUE_LED_PIN_HAL;
GPIO_InitStruct_Main.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct_Main.Pull = GPIO_NOPULL;
GPIO_InitStruct_Main.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(BLUE_LED_PORT, &GPIO_InitStruct_Main);
/* Keep the blue LED on to show the program is running. */
Main_SetBlueLed(BLUE_LED_ON);
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 12;
RCC_OscInitStruct.PLL.PLLN = 96;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 4;
// if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
// {
// Error_Handler();
// }
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
// if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)
// {
// Error_Handler();
// }
HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSI, RCC_MCODIV_1);
}
|
MrtFeng/MFNetworking
|
MFNetWorkTool/MFNetWorkTool.h
|
//
// MFNetWorkTool.h
// Text3
//
// Created by apple on 15/10/18.
// Copyright © 2015年 apple. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef void(^isSuccess)(NSData *data, NSURLResponse *response);
typedef void(^isfail)(NSError *error);
@interface MFNetWorkTool : NSObject
+(instancetype)shareNetWorkTool;
-(NSURLResponse *)getResponseWithFilepath:(NSString *)filePath;
-(NSData *)getHTTPBodyWithFilepath:(NSString *)filePath andFileKey:(NSString *)fileKey andDidFileName:(NSString *)nameString;
-(void)sendPOSTRequestWithUrlString:(NSString *)urlString andParamater:(NSDictionary *)paramater isSuccess:(isSuccess)isSuccess isfail:(isfail)isFail;
-(void)sendPOSTRequestWithTransmitPictureWithURL:(NSString *)urlString andFilePath:(NSString *)filePath andUserFile:(NSString *)userfile andFileName:(NSString *)fileName;
-(NSData *)getHTTPBodyWithPathDict:(NSDictionary *)pathDict andUserFile:(NSString *)userFile andParamater:(NSDictionary *)paramater;
-(void)sendPOSTRequestWithTransmitMorePictureWithURL:(NSString *)urlString andPathDict:(NSDictionary *)pathDict andUserFile:(NSString *)userFile andParamater:(NSDictionary *)paramater andSuccess:(isSuccess)success andfail:(isfail)fail;
@end
|
stlankes/hermit-playground
|
include/hermit/syscall.h
|
/*
* Copyright (c) 2011, <NAME>, RWTH Aachen University
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @author <NAME>
* @file include/hermit/syscall.h
* @brief System call number definitions
*
* This file contains define constants for every syscall's number.
*/
#ifndef __SYSCALL_H__
#define __SYSCALL_H__
#ifdef __KERNEL__
#include <hermit/stddef.h>
#else
#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>
#ifndef NORETURN
#define NORETURN __attribute__((noreturn))
#endif
typedef unsigned int tid_t;
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* Opaque structures (may point to Rust structures or be used to not clash with types defined by the C library) */
struct _HermitItimerval;
typedef struct _HermitItimerval HermitItimerval;
struct _HermitRecursiveMutex;
typedef struct _HermitRecursiveMutex HermitRecursiveMutex;
struct _HermitSemaphore;
typedef struct _HermitSemaphore HermitSemaphore;
struct _HermitSpinlock;
typedef struct _HermitSpinlock HermitSpinlock;
struct _HermitSpinlockIrqSave;
typedef struct _HermitSpinlockIrqSave HermitSpinlockIrqSave;
struct _HermitTimespec;
typedef struct _HermitTimespec HermitTimespec;
struct _HermitTimeval;
typedef struct _HermitTimeval HermitTimeval;
typedef void (*entry_point_t)(void*);
typedef void (*signal_handler_t)(int);
/* Task priorities */
#define HIGH_PRIO 3
#define NORMAL_PRIO 2
#define LOW_PRIO 1
#define IDLE_PRIO 0
/*
* HermitCore is a libOS.
* => classical system calls are realized as normal function
* => forward declaration of system calls as function
*/
tid_t sys_getpid(void);
int sys_fork(void);
int sys_wait(int* status);
int sys_execve(const char* name, char * const * argv, char * const * env);
int sys_getprio(tid_t* id);
int sys_setprio(tid_t* id, int prio);
void NORETURN sys_exit(int arg);
ssize_t sys_read(int fd, char* buf, size_t len);
ssize_t sys_write(int fd, const char* buf, size_t len);
ssize_t sys_sbrk(ssize_t incr);
int sys_open(const char* name, int flags, int mode);
int sys_close(int fd);
void sys_acquire_putchar_lock(void);
void sys_putchar(const unsigned char character);
void sys_release_putchar_lock(void);
int sys_lwip_get_errno();
void sys_lwip_register_tcpip_task(tid_t id);
void sys_lwip_set_errno(int errno);
void sys_usleep(unsigned long usecs);
int sys_nanosleep(const HermitTimespec* rqtp, HermitTimespec* rmtp);
void sys_msleep(unsigned int ms);
int sys_recmutex_init(HermitRecursiveMutex** recmutex);
int sys_recmutex_destroy(HermitRecursiveMutex* recmutex);
int sys_recmutex_lock(HermitRecursiveMutex* recmutex);
int sys_recmutex_unlock(HermitRecursiveMutex* recmutex);
int sys_sem_init(HermitSemaphore** sem, unsigned int value);
int sys_sem_destroy(HermitSemaphore* sem);
int sys_sem_post(HermitSemaphore* sem);
int sys_sem_trywait(HermitSemaphore* sem);
int sys_sem_timedwait(HermitSemaphore *sem, unsigned int ms);
#define sys_sem_wait(sem) sys_sem_timedwait(sem, 0)
int sys_sem_cancelablewait(HermitSemaphore* sem, unsigned int ms);
int sys_spinlock_init(HermitSpinlock** lock);
int sys_spinlock_destroy(HermitSpinlock* lock);
int sys_spinlock_lock(HermitSpinlock* lock);
int sys_spinlock_unlock(HermitSpinlock* lock);
int sys_spinlock_irqsave_init(HermitSpinlockIrqSave** lock);
int sys_spinlock_irqsave_destroy(HermitSpinlockIrqSave* lock);
int sys_spinlock_irqsave_lock(HermitSpinlockIrqSave* lock);
int sys_spinlock_irqsave_unlock(HermitSpinlockIrqSave* lock);
int sys_spawn(tid_t* id, entry_point_t func, void* arg, unsigned char prio, size_t core_id);
int sys_clock_getres(unsigned long clock_id, HermitTimespec* res);
int sys_clock_gettime(unsigned long clock_id, HermitTimespec* tp);
int sys_clock_nanosleep(unsigned long clock_id, int flags, const HermitTimespec* rqtp, HermitTimespec* rmtp);
int sys_clock_settime(unsigned long clock_id, const HermitTimespec* tp);
int sys_clone(tid_t* id, void* ep, void* argv);
int sys_getpagesize(void);
int sys_gettimeofday(HermitTimeval* tp, void* tz);
size_t sys_get_processor_count(void);
unsigned short sys_get_processor_frequency(void);
off_t sys_lseek(int fd, off_t offset, int whence);
int sys_setitimer(int which, const HermitItimerval* value, HermitItimerval* ovalue);
void sys_yield(void);
int sys_kill(tid_t dest, int signum);
int sys_signal(signal_handler_t handler);
unsigned int sys_rand();
struct ucontext;
typedef struct ucontext ucontext_t;
void makecontext(ucontext_t *ucp, void (*func)(), int argc, ...);
int swapcontext(ucontext_t *oucp, const ucontext_t *ucp);
int getcontext(ucontext_t *ucp);
int setcontext(ucontext_t *ucp);
#define __NR_exit 0
#define __NR_write 1
#define __NR_open 2
#define __NR_close 3
#define __NR_read 4
#define __NR_lseek 5
#define __NR_unlink 6
#define __NR_getpid 7
#define __NR_kill 8
#define __NR_fstat 9
#define __NR_sbrk 10
#define __NR_fork 11
#define __NR_wait 12
#define __NR_execve 13
#define __NR_times 14
#define __NR_stat 15
#define __NR_dup 16
#define __NR_dup2 17
#define __NR_msleep 18
#define __NR_yield 19
#define __NR_sem_init 20
#define __NR_sem_destroy 21
#define __NR_sem_wait 22
#define __NR_sem_post 23
#define __NR_sem_timedwait 24
#define __NR_getprio 25
#define __NR_setprio 26
#define __NR_clone 27
#define __NR_sem_cancelablewait 28
#define __NR_get_ticks 29
#ifdef __cplusplus
}
#endif
#endif
|
stlankes/hermit-playground
|
include/hermit/x86_64/arch_limits.h
|
<reponame>stlankes/hermit-playground
/*
* Copyright (c) 2010, <NAME>, RWTH Aachen University
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* author <NAME>
* @file arch/x86/include/asm/limits.h
* @brief Define constants related to numerical value-ranges of variable types
*
* This file contains define constants for the numerical
* ranges of the most typical variable types.
*/
#ifndef __ARCH_LIMITS_H__
#define __ARCH_LIMITS_H__
#ifdef __cplusplus
extern "C" {
#endif
/** Number of bits in a char */
#define CHAR_BIT 8
/** Maximum value for a signed char */
#define SCHAR_MAX 0x7f
/** Minimum value for a signed char */
#define SCHAR_MIN (-0x7f - 1)
/** Maximum value for an unsigned char */
#define UCHAR_MAX 0xff
/** Maximum value for an unsigned short */
#define USHRT_MAX 0xffff
/** Maximum value for a short */
#define SHRT_MAX 0x7fff
/** Minimum value for a short */
#define SHRT_MIN (-0x7fff - 1)
/** Maximum value for an unsigned int */
#define UINT_MAX 0xffffffffU
/** Maximum value for an int */
#define INT_MAX 0x7fffffff
/** Minimum value for an int */
#define INT_MIN (-0x7fffffff - 1)
/** Maximum value for an unsigned long */
#define ULONG_MAX 0xffffffffUL
/** Maximum value for a long */
#define LONG_MAX 0x7fffffffL
/** Minimum value for a long */
#define LONG_MIN (-0x7fffffffL - 1)
/** Maximum value for an unsigned long long */
#define ULLONG_MAX 0xffffffffffffffffULL
/** Maximum value for a long long */
#define LLONG_MAX 0x7fffffffffffffffLL
/** Minimum value for a long long */
#define LLONG_MIN (-0x7fffffffffffffffLL - 1)
#ifdef __cplusplus
}
#endif
#endif
|
stlankes/hermit-playground
|
include/hermit/mailbox.h
|
/*
* Copyright (c) 2010, <NAME>, RWTH Aachen University
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __MAILBOX_H__
#define __MAILBOX_H__
#include <hermit/string.h>
#include <hermit/mailbox_types.h>
#include <hermit/syscall.h>
#include <hermit/errno.h>
#ifdef __cplusplus
extern "C" {
#endif
#define MAILBOX(name, type) \
inline static int mailbox_##name##_init(mailbox_##name##_t* m) { \
if (BUILTIN_EXPECT(!m, 0)) \
return -EINVAL; \
\
memset(m->buffer, 0x00, sizeof(type)*MAILBOX_SIZE); \
m->wpos = m->rpos = 0; \
sys_sem_init(&m->mails, 0); \
sys_sem_init(&m->boxes, MAILBOX_SIZE); \
sys_spinlock_init(&m->rlock); \
sys_spinlock_init(&m->wlock); \
\
return 0; \
}\
\
inline static int mailbox_##name##_destroy(mailbox_##name##_t* m) { \
if (BUILTIN_EXPECT(!m, 0)) \
return -EINVAL; \
\
sys_sem_destroy(m->mails); \
sys_sem_destroy(m->boxes); \
sys_spinlock_destroy(m->rlock); \
sys_spinlock_destroy(m->wlock); \
\
return 0; \
} \
\
inline static int mailbox_##name##_post(mailbox_##name##_t* m, type mail) { \
if (BUILTIN_EXPECT(!m, 0)) \
return -EINVAL; \
\
sys_sem_timedwait(m->boxes, 0); \
sys_spinlock_lock(m->wlock); \
m->buffer[m->wpos] = mail; \
m->wpos = (m->wpos+1) % MAILBOX_SIZE; \
sys_spinlock_unlock(m->wlock); \
sys_sem_post(m->mails); \
\
return 0; \
} \
\
inline static int mailbox_##name##_trypost(mailbox_##name##_t* m, type mail) { \
if (BUILTIN_EXPECT(!m, 0)) \
return -EINVAL; \
\
if (sys_sem_trywait(m->boxes)) \
return -EBUSY; \
sys_spinlock_lock(m->wlock); \
m->buffer[m->wpos] = mail; \
m->wpos = (m->wpos+1) % MAILBOX_SIZE; \
sys_spinlock_unlock(m->wlock); \
sys_sem_post(m->mails); \
\
return 0; \
} \
\
inline static int mailbox_##name##_fetch(mailbox_##name##_t* m, type* mail, uint32_t ms) { \
int err; \
\
if (BUILTIN_EXPECT(!m || !mail, 0)) \
return -EINVAL; \
\
err = sys_sem_timedwait(m->mails, ms); \
if (err) return SYS_ARCH_TIMEOUT; \
sys_spinlock_lock(m->rlock); \
*mail = m->buffer[m->rpos]; \
m->rpos = (m->rpos+1) % MAILBOX_SIZE; \
sys_spinlock_unlock(m->rlock); \
sys_sem_post(m->boxes); \
\
return 0; \
} \
\
inline static int mailbox_##name##_tryfetch(mailbox_##name##_t* m, type* mail) { \
if (BUILTIN_EXPECT(!m || !mail, 0)) \
return -EINVAL; \
\
if (sys_sem_trywait(m->mails) != 0) \
return -EINVAL; \
sys_spinlock_lock(m->rlock); \
*mail = m->buffer[m->rpos]; \
m->rpos = (m->rpos+1) % MAILBOX_SIZE; \
sys_spinlock_unlock(m->rlock); \
sys_sem_post(m->boxes); \
\
return 0; \
}\
MAILBOX(ptr, void*)
#ifdef __cplusplus
}
#endif
#endif
|
stlankes/hermit-playground
|
usr/benchmarks/taskswitch.c
|
// Copyright (c) 2018 <NAME>, RWTH Aachen University
//
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.
///////////////////////////////////////
//// HERMITCORE RUST-SPECIFIC CODE ////
#include <hermit/syscall.h>
inline static void create_second_task(void (*entry_point)(void*))
{
sys_spawn(NULL, entry_point, NULL, HIGH_PRIO, 0);
}
inline static void consume_task_time(void)
{
// Spending >10ms in the second task guarantees that the scheduler
// switches back to the first task on sys_yield().
// Calling sys_msleep(ms) with ms < 10 enforces busy-waiting!
sys_msleep(6);
sys_msleep(6);
}
inline static void switch_task(void)
{
sys_yield();
}
///////////////////////////////////
//// THE ACTUAL BENCHMARK CODE ////
#include <stdbool.h>
#include <stdio.h>
// You can enable this for debugging without any effect on the measurement.
//#define DEBUG_MESSAGES
#define N 1000
static bool finished;
static unsigned long long start;
static unsigned long long sum;
inline static unsigned long long rdtsc(void)
{
unsigned long lo, hi;
asm volatile ("rdtsc" : "=a"(lo), "=d"(hi) :: "memory");
return ((unsigned long long) hi << 32ULL | (unsigned long long) lo);
}
void second_task(void* arg)
{
unsigned long long end;
for(;;)
{
// Calculate the cycle difference and add it to the sum.
end = rdtsc();
sum += (end - start);
// Check if the benchmark has finished and we can end the second task.
if (finished)
{
break;
}
#ifdef DEBUG_MESSAGES
printf("Hello from task 2\n");
#endif
consume_task_time();
// Save the current Time Stamp Counter value and switch back to the
// first task.
start = rdtsc();
switch_task();
}
}
int main(int argc, char** argv)
{
int i;
unsigned long long end;
// Start the second task with the same priority on the boot processor.
create_second_task(second_task);
// Initialize the benchmark.
printf("taskswitch test\n");
printf("===============\n");
finished = false;
sum = 0;
// Warm up
switch_task();
switch_task();
// Run the benchmark.
sum = 0;
for(i = 0; i < N; i++)
{
#ifdef DEBUG_MESSAGES
printf("Hello from task 1\n");
#endif
consume_task_time();
// Save the current Time Stamp Counter value and switch to the second
// task.
start = rdtsc();
switch_task();
// Calculate the cycle difference and add it to the sum.
end = rdtsc();
sum += (end - start);
}
// Calculate and print the results.
// In every loop iteration, task 1 switches to task 2 and task 2 switches
// back to task 1.
// Therefore, the total number needs to be divided by 2.
printf("Average time for a task switch: %lld cycles\n", sum / (N * 2));
// Finish the second task gracefully.
finished = true;
switch_task();
return 0;
}
|
stlankes/hermit-playground
|
include/hermit/stdlib.h
|
/*
* Copyright (c) 2010, <NAME>, RWTH Aachen University
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @author <NAME>
* @file include/hermit/stdlib.h
* @brief Kernel space malloc and free functions and conversion functions
*
* This file contains some memory alloc and free calls for the kernel
* and conversion functions.
*/
#ifndef __STDLIB_H__
#define __STDLIB_H__
#include <hermit/stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @brief String to long
*
* @return Long value of the parsed numerical string
*/
long _strtol(const char* str, char** endptr, int base);
#define strtol(str, endptr, base) _strtol((str), (endptr), (base))
/** @brief String to unsigned long
*
* @return Unsigned long value of the parsed numerical string
*/
unsigned long _strtoul(const char* nptr, char** endptr, int base);
#define strtoul(nptr, endptr, base) _strtoul((nptr), (endptr), (base))
/** @brief ASCII to integer
*
* Convenience function using strtol().
*
* @return Integer value of the parsed numerical string
*/
static inline int atoi(const char *str)
{
return (int)_strtol(str, (char **)NULL, 10);
}
/** @brief Checks whether c is a hexdecimal digit character.
*
* @return A value different from zero if indeed c is a hexadecimal digit.
* Zero otherwise.
*/
static inline int isxdigit(int c)
{
if ((c >= '0') && (c <= '9'))
return 1;
else if ((c >= 'A') && (c <= 'F'))
return 1;
else if ((c >= 'a') && (c <= 'f'))
return 1;
return 0;
}
#ifdef __cplusplus
}
#endif
#endif
|
stlankes/hermit-playground
|
usr/tests/hello.c
|
/*
* Copyright (c) 2010, <NAME>, RWTH Aachen University
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
* http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
* http://opensource.org/licenses/MIT>, at your option. This file may not be
* copied, modified, or distributed except according to those terms.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#define N 255
int main(int argc, char** argv)
{
int i, random;
FILE* file;
printf("Hello World!!!\n");
for(i=0; environ[i]; i++)
printf("environ[%d] = %s\n", i, environ[i]);
for(i=0; i<argc; i++)
printf("argv[%d] = %s\n", i, argv[i]);
file = fopen("/etc/hostname", "r");
if (file)
{
char fname[N] = "";
fscanf(file, "%s", fname);
printf("Hostname: %s\n", fname);
fclose(file);
} else fprintf(stderr, "Unable to open file /etc/hostname\n");
file = fopen("/tmp/test.txt", "w");
if (file)
{
fprintf(file, "Hello World!!!\n");
fclose(file);
} else fprintf(stderr, "Unable to open file /tmp/test.txt\n");
return 0;
}
|
stlankes/hermit-playground
|
usr/benchmarks/basic.c
|
<reponame>stlankes/hermit-playground
/*
* Copyright (c) 2016, <NAME>, RWTH Aachen University
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
* http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
* http://opensource.org/licenses/MIT>, at your option. This file may not be
* copied, modified, or distributed except according to those terms.
*/
#ifndef __hermit__
#define _GNU_SOURCE
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sched.h>
#include <pthread.h>
#ifndef __hermit__
#include <sys/syscall.h>
static inline long mygetpid(void)
{
return syscall(__NR_getpid);
}
#else
static inline long mygetpid(void)
{
return getpid();
}
int sched_yield(void);
#define PAGE_SIZE (4ULL*1024ULL)
#endif
#define N 10000000
#define M (256+1)
#define BUFFSZ (1ULL*1024ULL*1024ULL)
static char* buff[M];
#if 0
inline static unsigned long long rdtsc(void)
{
unsigned long lo, hi;
asm volatile ("lfence; rdtsc; lfence" : "=a"(lo), "=d"(hi) :: "memory");
return ((unsigned long long) hi << 32ULL | (unsigned long long) lo);
}
#else
inline static unsigned long long rdtsc(void)
{
unsigned int lo, hi;
unsigned int id;
asm volatile ("rdtscp; lfence" : "=a"(lo), "=c"(id), "=d"(hi));
return ((unsigned long long)hi << 32ULL | (unsigned long long)lo);
}
#endif
static void* thread_func(void* arg)
{
return (void*) rdtsc();
}
int main(int argc, char** argv)
{
long i, j, ret;
unsigned long long sum, start, end;
const char str[] = "H";
const size_t len = strlen(str);
pthread_t thr_handle;
printf("Determine systems performance\n");
printf("=============================\n");
// cache warm-up
ret = mygetpid();
ret = mygetpid();
start = rdtsc();
for(i=0; i<N; i++)
ret = mygetpid();
end = rdtsc();
printf("Average time for getpid: %lld cycles, pid %ld\n", (end - start) / N, ret);
// cache warm-up
sched_yield();
sched_yield();
start = rdtsc();
for(i=0; i<N; i++)
sched_yield();
end = rdtsc();
printf("Average time for sched_yield: %lld cycles\n", (end - start) / N);
sum = 0;
for(i=0; i<10000; i++) {
start = rdtsc();
pthread_create(&thr_handle, NULL, thread_func, NULL);
sched_yield();
pthread_join(thr_handle, (void**)&start);
sum += rdtsc() - start;
}
printf("Average time to create a thread: %lld cycles\n", sum / 10000);
#if 0
write(2, (const void *)str, len);
write(2, (const void *)str, len);
start = rdtsc();
for(i=0; i<N; i++)
write(2, (const void *)str, len);
end = rdtsc();
printf("\nAverage time for write: %lld cycles\n", (end - start) / N);
#endif
return 0;
}
|
stlankes/hermit-playground
|
usr/benchmarks/rdtsc.c
|
<filename>usr/benchmarks/rdtsc.c
/*
* =====================================================================================
*
* Filename: rdtsc.c
*
* Description:
*
* Version: 1.0
* Created: 31.01.2011 10:56:58
* Revision: none
* Compiler: gcc
*
* Author: <NAME> (gw) (),
* Company:
*
* =====================================================================================
*/
#define _SVID_SOURCE
#define _XOPEN_SOURCE 500
#include <sys/time.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include "rdtsc.h"
#ifdef __hermit__
#include <hermit/syscall.h>
#endif
static inline void cpuid(unsigned func, unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *edx) {
__asm__ volatile ("cpuid" : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) : "a"(func));
}
static inline uint32_t cpuid_edx(uint32_t code) {
uint32_t eax, ebx, ecx, edx;
cpuid(code, &eax, &ebx, &ecx, &edx);
return edx;
}
static uint64_t tps = 0;
#if 0
/*
* === FUNCTION ======================================================================
* Name: second()
* Description: returns a double representation of gettimeofday (seconds.microseconds)
* =====================================================================================
*/
static inline double second()
{
struct timeval tv;
gettimeofday(&tv, 0);
return tv.tv_sec + 1e-6*tv.tv_usec;
}
/*
* === FUNCTION ======================================================================
* Name: selectsleep(us)
* Description: calls select() to sleep (wait) the given microseconds
* =====================================================================================
*/
static inline void selectsleep(unsigned us)
{
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = us;
select(0,0,0,0,&tv); // portable way to sleep with subsecond precision
}
/*
* === FUNCTION ======================================================================
* Name: rdtsc_ticks_per_sec()
* Description: uses least squares regressen to measure the frequency of the TSC
* =====================================================================================
*/
uint64_t rdtsc_ticks_per_sec(void)
{
double sumx = 0, sumy = 0;
double sumxx = 0, sumxy = 0;
double slope;
// least squared linear regression taken from mcert/misc/realfeed/realfeel.c
const unsigned n = 30;
unsigned i;
for (i=0; i<n; i++) {
double breal, real, ticks;
uint64_t bticks = 0, aticks = 0;
rdtsc(&bticks);
breal = second();
selectsleep((unsigned)(10000 + drand48() * 20000));
rdtsc(&aticks);
real = second() -breal;
ticks = (double)(aticks - bticks);
sumx += real;
sumxx += real * real;
sumxy += real * ticks;
sumy += ticks;
}
slope = ((sumxy - (sumx*sumy) / n) / (sumxx - (sumx*sumx) / n));
tps = (uint64_t)slope;
return tps;
}
#endif
uint64_t rdtsc_ticks_per_sec(void)
{
#ifdef __hermit__
uint64_t tps = (uint64_t) sys_get_processor_frequency() * 1000000ULL;
return tps;
#else
uint64_t t1, t2, t3, t4;
struct timeval tv1, tv2;
uint64_t diff_tsc, diff_usec;
rdtsc(&t1);
gettimeofday(&tv1, 0);
rdtsc(&t2);
usleep(500000); // 0.5 sec
rdtsc(&t3);
gettimeofday(&tv2, 0);
rdtsc(&t4);
//printf("t2-t1 : %llu\n", (unsigned long long)t2-t1);
//printf("t4-t3 : %llu\n", (unsigned long long)t4-t3);
t1 = (t1+t2)/2;
t2 = (t3+t4)/2;
diff_tsc = t2-t1;
//printf("diff tsc: %llu\n", (unsigned long long)diff_tsc);
diff_usec = (tv2.tv_sec - tv1.tv_sec) * 1000000;
if (tv2.tv_usec > tv1.tv_usec)
diff_usec += tv2.tv_usec - tv1.tv_usec;
else
diff_usec += tv1.tv_usec - tv2.tv_usec;
//printf("diff usec: %llu\n",
// (unsigned long long)diff_usec);
return (diff_tsc*1000000) / diff_usec;
#endif
}
/*
* === FUNCTION ======================================================================
* Name: rdtsc_max_freq(id)
* Description: reads the maximum frequency of given CPU-ID from /sys/.../cpuN/cpufreq
* Changes: WASSEN, 24.5.2011: taken from hourglass via irqlab
* =====================================================================================
*/
uint64_t rdtsc_max_freq(int id)
{
uint64_t mhz = -1;
char fname[BUFSIZ];
char processor[BUFSIZ];
char *buffer, *loc;
FILE *fp;
double tmhz;
int ret;
sprintf(fname, "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", id);
if (NULL == (fp = fopen(fname, "r"))) {
fprintf(stderr, "Can't open <%s>.\n", fname);
fprintf(stderr, "Trying </proc/cpuinfo> (not as accurate)\n");
if(NULL == (fp = fopen("/proc/cpuinfo","r"))) {
fprintf(stderr, "Can't open </proc/cpuinfo>.\n");
return -1;
}
buffer = (void *) malloc(sizeof(char) * 1024 * 512);
ret = fread(buffer, sizeof(char), 1024 * 512, fp);
if (ret == 0) {
fprintf(stderr, "fread() returned 0: %s\n", strerror(errno));
return -1;
}
sprintf(processor, "processor\t: %d", id);
if(NULL == (loc = strstr(buffer, processor))) {
fprintf(stderr, "Unable to parse /proc/cpuinfo\n");
return -1;
}
if(NULL == (loc = strstr(loc, "cpu MHz"))) {
fprintf(stderr, "Unable to parse /proc/cpuinfo\n");
return -1;
}
loc += strlen("cpu MHz");
while(!isdigit(*loc))
loc++;
loc--;
sscanf(loc, "%lf", &tmhz);
mhz = (uint64_t)(tmhz);
mhz*=1000;
free(buffer);
} else {
ret = fscanf(fp, "%lld", (unsigned long long*)&mhz);
if (ret == 0) {
fprintf(stderr, "fscanf() returned 0: %s\n", strerror(errno));
return -1;
}
fclose(fp);
}
return mhz*1000;
}
/*
* === FUNCTION ======================================================================
* Name: rdtsc_loop(ticks)
* Description: waits actively for given TSC ticks
* =====================================================================================
*/
void rdtsc_loop(uint64_t ticks)
{
uint64_t t_now = 0, t_end;
rdtsc(&t_now);
t_end = t_now + ticks;
while (t_now < t_end) {
rdtsc(&t_now);
}
}
/*
* === FUNCTION ======================================================================
* Name: rdtsc_loop_sec(ticks)
* Description: waits actively for given seconds
* ATTN: needs rdtsc_ticks_per_sec() unless that function was previously
* called (this function MIGHT use syscalls!)
* =====================================================================================
*/
void rdtsc_loop_sec(unsigned seconds)
{
uint64_t t_now = 0, t_end;
rdtsc(&t_now);
if (tps == 0) rdtsc_ticks_per_sec();
t_end = t_now + (uint64_t)seconds * tps;
while (t_now < t_end) {
rdtsc(&t_now);
}
}
/*
* test if TSC is invariant (return value 1)
*/
int rdtsc_is_invariant(void) {
if (cpuid_edx(0x80000007) & (1 << 8)) { // TSC is invariant
return 1;
}
return 0;
}
/*
* measure overhead of *not* serialized rdtsc() (SHL, MOV, OR)
*/
uint64_t rdtsc_get_overhead(const uint64_t iterations) {
uint64_t c;
uint64_t tsc_overhead_notserial = 0;
uint64_t tsc_start;
uint64_t tsc_end;
if (iterations == 0) {
return 0;
}
for (c = 0; c < iterations; c++) {
#if ! __MIC__
__asm__ volatile("lfence");
#else
__asm__ volatile("lock; add $0, 0(%%rsp)" ::: "memory");
#endif
rdtsc(&tsc_start);
rdtsc(&tsc_end);
tsc_overhead_notserial += tsc_end - tsc_start;
}
return tsc_overhead_notserial / iterations;
}
/*
* measure overhead of serialized rdtsc_serialized() (LFENCE, SHL, MOV, OR, LFENCE)
*/
uint64_t rdtsc_get_overhead_serialized(const uint64_t iterations) {
uint64_t c;
uint64_t tsc_overhead_serial = 0;
uint64_t tsc_start;
uint64_t tsc_end;
if (iterations == 0) {
return 0;
}
for (c = 0; c < iterations; c++) {
rdtsc_serialized(&tsc_start);
rdtsc_serialized(&tsc_end);
tsc_overhead_serial += tsc_end - tsc_start;
}
return tsc_overhead_serial / iterations;
}
|
stlankes/hermit-playground
|
usr/openmpbench/syncbench.c
|
<reponame>stlankes/hermit-playground<gh_stars>10-100
/****************************************************************************
* *
* OpenMP MicroBenchmark Suite - Version 3.1 *
* *
* produced by *
* *
* <NAME>, <NAME> and <NAME> *
* *
* at *
* *
* Edinburgh Parallel Computing Centre *
* *
* email: <EMAIL> or <EMAIL> *
* *
* *
* This version copyright (c) The University of Edinburgh, 2015. *
* *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* *
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <omp.h>
#ifdef XRAY
#include <xray.h>
#endif
#include "common.h"
#include "syncbench.h"
omp_lock_t lock;
int main(int argc, char **argv) {
#ifdef XRAY
struct XRayTraceCapture* trace = XRayInit(
20, // max. call depth
16 * 1000 * 1000, // memory for report
13, // frame count
"syncbench.map");
#endif
// Start Paraver tracing
#ifdef PARAVERTRACE
Extrae_init();
#endif
init(argc, argv);
omp_init_lock(&lock);
#ifdef XRAY
/* GENERATE REFERENCE TIME */
XRayStartFrame(trace);
reference("reference time 1", &refer);
XRayEndFrame(trace);
/* TEST PARALLEL REGION */
XRayStartFrame(trace);
benchmark("PARALLEL", &testpr);
XRayEndFrame(trace);
/* TEST FOR */
XRayStartFrame(trace);
benchmark("FOR", &testfor);
XRayEndFrame(trace);
/* TEST PARALLEL FOR */
XRayStartFrame(trace);
benchmark("PARALLEL FOR", &testpfor);
XRayEndFrame(trace);
/* TEST BARRIER */
XRayStartFrame(trace);
benchmark("BARRIER", &testbar);
XRayEndFrame(trace);
/* TEST SINGLE */
XRayStartFrame(trace);
benchmark("SINGLE", &testsing);
XRayEndFrame(trace);
/* TEST CRITICAL*/
XRayStartFrame(trace);
benchmark("CRITICAL", &testcrit);
XRayEndFrame(trace);
/* TEST LOCK/UNLOCK */
XRayStartFrame(trace);
benchmark("LOCK/UNLOCK", &testlock);
XRayEndFrame(trace);
/* TEST ORDERED SECTION */
XRayStartFrame(trace);
benchmark("ORDERED", &testorder);
XRayEndFrame(trace);
/* GENERATE NEW REFERENCE TIME */
XRayStartFrame(trace);
reference("reference time 2", &referatom);
XRayEndFrame(trace);
/* TEST ATOMIC */
XRayStartFrame(trace);
benchmark("ATOMIC", &testatom);
XRayEndFrame(trace);
/* GENERATE NEW REFERENCE TIME */
XRayStartFrame(trace);
reference("reference time 3", &referred);
XRayEndFrame(trace);
/* TEST REDUCTION (1 var) */
XRayStartFrame(trace);
benchmark("REDUCTION", &testred);
XRayEndFrame(trace);
#endif
#ifdef PARAVERTRACE
Extrae_fini();
#endif
#ifdef XRAY
XRaySaveReport(trace,
"syncbench.xray", // report file
0.05f, // Only output funcs that have higher runtime [%]
1000); // Only output funcs that have higher runtime [cycles]
XRayShutdown(trace);
#endif
finalise();
return EXIT_SUCCESS;
}
void refer() {
int j;
for (j = 0; j < innerreps; j++) {
delay(delaylength);
}
}
void referatom(){
int j;
double aaaa = 0.0;
double epsilon = 1.0e-15;
double b, c;
b = 1.0;
c = (1.0 + epsilon);
for (j = 0; j < innerreps; j++) {
aaaa += b;
b *= c;
}
if (aaaa < 0.0)
printf("%f\n", aaaa);
}
void referred() {
int j;
int aaaa = 0;
for (j = 0; j < innerreps; j++) {
delay(delaylength);
aaaa += 1;
}
}
void testpr() {
int j;
#ifdef XRAY
static int n = 1;
XRayAnnotate("n = %i", n);
n++;
#endif
for (j = 0; j < innerreps; j++) {
#pragma omp parallel
{
delay(delaylength);
}
}
}
void testfor() {
int i, j;
#pragma omp parallel private(j)
{
for (j = 0; j < innerreps; j++) {
#pragma omp for
for (i = 0; i < nthreads; i++) {
delay(delaylength);
}
}
}
}
void testpfor() {
int i, j;
#ifdef XRAY
static int n = 1;
XRayAnnotate("n = %i", n);
n++;
#endif
for (j = 0; j < innerreps; j++) {
#pragma omp parallel for
for (i = 0; i < nthreads; i++) {
delay(delaylength);
}
}
}
void testbar() {
int j;
#pragma omp parallel private(j)
{
for (j = 0; j < innerreps; j++) {
delay(delaylength);
#pragma omp barrier
}
}
}
void testsing() {
int j;
#pragma omp parallel private(j)
{
for (j = 0; j < innerreps; j++) {
#pragma omp single
delay(delaylength);
}
}
}
void testcrit() {
int j;
#pragma omp parallel private(j)
{
for (j = 0; j < innerreps / nthreads; j++) {
#pragma omp critical
{
delay(delaylength);
}
}
}
}
void testlock() {
int j;
#pragma omp parallel private(j)
{
for (j = 0; j < innerreps / nthreads; j++) {
omp_set_lock(&lock);
delay(delaylength);
omp_unset_lock(&lock);
}
}
}
void testorder() {
int j;
#pragma omp parallel for ordered schedule (static,1)
for (j = 0; j < (int)innerreps; j++) {
#pragma omp ordered
delay(delaylength);
}
}
void testatom() {
int j;
double aaaa = 0.0;
double epsilon = 1.0e-15;
double b,c;
b = 1.0;
c = (1.0 + epsilon);
#pragma omp parallel private(j) firstprivate(b)
{
for (j = 0; j < innerreps / nthreads; j++) {
#pragma omp atomic
aaaa += b;
b *= c;
}
}
if (aaaa < 0.0)
printf("%f\n", aaaa);
}
void testred() {
int j;
int aaaa = 0;
for (j = 0; j < innerreps; j++) {
#pragma omp parallel reduction(+:aaaa)
{
delay(delaylength);
aaaa += 1;
}
}
}
|
RNG65536/MCRT
|
src/examples/bssrdf/octree.h
|
#ifndef octree_h__
#define octree_h__
#include <functional>
#include "vectors.h"
// TODO: to actually store area for all levels of irradiance samples,
// and use sumArea / L^2 to approximate the solid angle subtended by the levels
// #define DIVIDE_BY_FOUR_PI /(4.0*M_PI)
// #define MULTIPLY_BY_FOUR_PI *4*M_PI // * 4 //* (4 * PI)
// #define MULTIPLY_BY_FOUR_PI //*4*M_PI // * 4 //* (4 * PI)
//////////////////////////////////////////////////////////////////////////
// assuming uniform sampling, so area weighting need not be considered
struct OctreeSample {
// to evaluate dirpole bssrdf, need { position, normal, direction }
vec3 centroid; // position
vec3 meanIrradiance; // average irradiance
float sumArea;
vec3 weightedNormal; // normal
vec3 weightedLightDir; // direction
OctreeSample(const vec3& position, const vec3& normal, const vec3& direction, const vec3& rad, float area);
vec3 getRadiantExitance(vec3 position, vec3 normal, vec3 direction /* view ray */, std::function<vec3(const vec3&, const vec3&, const vec3&, const vec3&, const vec3&, const vec3&)> kernel);
};
class Octree {
vec3 origin, halfDimension;
vec3 bmin, bmax;
Octree *children[8]; // Children
OctreeSample* payload; // Possible use : 1) instances stored at a leaf 2) aggregation at interior nodes
/*
child: 0 1 2 3 4 5 6 7
x: - - - - + + + +
y: - - + + - - + +
z: - + - + - + - +
*/
Octree(const Octree& tree);
int getOctantContainingPoint(const vec3& point) const;
bool isLeafNode() const;
float luminance(const vec3& c) const;
float weightingFucntion(const vec3& position, const vec3& normal, const vec3& direction, const OctreeSample* sample) const;
void buildAggregationRecursive();
float meanIrradianceRecursive() const;
public:
Octree(const vec3& origin, const vec3& halfDimension);
~Octree();
void insert(OctreeSample* point);
void finalize();
//Barnes-Hut algorithm
vec3 fastsumRadiance(const vec3& p, const vec3& nl, const vec3& dir, float traversal_threshold, std::function<vec3(const vec3&, const vec3&, const vec3&, const vec3&, const vec3&, const vec3&)> kernel) const;
};
#endif // octree_h__
|
RNG65536/MCRT
|
src/examples/vcm/vcm_scene.h
|
<reponame>RNG65536/MCRT
// Disclaimer: This demo is adapted from smallvcm http://www.smallvcm.com/
#pragma once
#include <glm/gtc/matrix_transform.hpp>
#include "intersection.h"
#include "aabb.h"
#include "scene.h"
#include "scenebvh.h"
#include "vectors.h"
#include "mesh.h"
#include "numeric.h"
#include "camera.h"
#include "light.h"
typedef HitInfo HitInfo_debug;
#if 0
class API_Scene
{
class Sphere_debug
{
public:
float rad;
vec3 p;
Sphere_debug(float r_, vec3 p_)
: rad(r_), p(p_)
{
}
float intersect(const Ray &r) const
{
// returns distance
vec3d op = vec3d(p) - vec3d(r.o);
double t, b = dot(op, vec3d(r.d)), det = b * b - dot(op, op) + rad * rad;
if (det < 0)
{
return 1e20;
}
else
{
det = sqrt(det);
}
return (t = b - det) > 1e-4 ? t : ((t = b + det) > 1e-4 ? t : 1e20);
}
vec3 sample() const
{
return p + sampleSphereUniform(randf(), randf()) * (rad * 2);
}
};
std::vector<Sphere_debug> m_geometry;
std::vector<int> material_ids;
public:
void finalize(SceneSphere& _sceneSphere)
{
AABB scene_bbox;
for (auto& s : m_geometry)
{
AABB tri_bbox = AABB(s.p - vec3(s.rad), s.p + vec3(s.rad));
scene_bbox.expandBy(tri_bbox);
}
_sceneSphere.m_cenetr = scene_bbox.getCenter();
_sceneSphere.m_radius = scene_bbox.diagonal().length() * 0.5f;
_sceneSphere.m_inv_radius_sqr = 1.0f / sq(_sceneSphere.m_radius);
}
HitInfo_debug intersect(const Ray& ray) const
{
float t;
int id = -1;
//ray-sphere intersect.
int n = m_geometry.size();
float d, inf = 1e20;
t = inf;
for (int i = 0; i < n; i++)
{
d = m_geometry[i].intersect(ray);
if (d < t)
{
t = d;
id = i;
}
}
HitInfo_debug ret;
ret.setDistance(t);
ret.setShadingNormal(normalize(ray.at(t) - m_geometry[id].p));
ret.setPrimitiveID(id);
ret.setMaterialID(id >= 0 ? material_ids[id] : -1);
return ret;
}
bool occluded(const Ray& ray, float tfar) const
{
//ray-sphere intersect.
int n = m_geometry.size();
for (int i = 0; i < n; i++)
{
float d = m_geometry[i].intersect(ray);
if (d < tfar)
{
return true;
}
}
return false;
}
void addSphere(float radius, const vec3& center, int mat_id)
{
m_geometry.push_back(Sphere_debug(radius, center));
material_ids.push_back(mat_id);
}
};
#else
class API_Scene
{
SceneBVH *bvh = nullptr;
std::vector<TriangleObject> m_triangles;
std::vector<int> material_ids;
public:
API_Scene()
{
}
~API_Scene()
{
delete bvh;
}
void finalize(SceneSphere& _sceneSphere)
{
bvh = new SceneBVH(m_triangles);
AABB scene_bbox;
for (auto& s : m_triangles)
{
AABB tri_bbox = s.boundingBox();
scene_bbox.expandBy(tri_bbox);
}
_sceneSphere.m_cenetr = scene_bbox.center();
_sceneSphere.m_radius = scene_bbox.diagonal().length() * 0.5f;
_sceneSphere.m_inv_radius_sqr = 1.0f / sq(_sceneSphere.m_radius);
}
HitInfo_debug intersect(const Ray& ray) const
{
HitInfo_debug ret = bvh->intersect(ray);
int pid = ret.primitiveID();
ret.setMaterialID(pid >= 0 ? material_ids[pid] : -1);
return ret;
}
bool occluded(const Ray& ray, float tfar) const
{
return bvh->occluded(ray, tfar);
}
void addSphere(float radius, const vec3& center, int mat_id)
{
Mesh obj("unitsph.obj");
{
glm::mat4 translation = glm::translate(glm::mat4(1.0f), glm::vec3(center.x, center.y, center.z));
glm::mat4 scaling = glm::scale(glm::mat4(1.0f), glm::vec3(radius));
for (int n = 0; n < obj.m_verts.size(); n++)
{
glm::vec4 v = glm::vec4(obj.m_verts[n].x, obj.m_verts[n].y, obj.m_verts[n].z, 1.0f);
v = translation * scaling * v;
obj.m_verts[n] = vec3(v.x, v.y, v.z);
}
obj.genNormals();
}
for (int i = 0; i < obj.m_faces.size(); i++)
{
int a = obj.m_faces[i].x;
int b = obj.m_faces[i].y;
int c = obj.m_faces[i].z;
TriangleObject tri(
vec3(obj.m_verts[a].x, (obj.m_verts[a].y), obj.m_verts[a].z),
vec3(obj.m_verts[b].x, (obj.m_verts[b].y), obj.m_verts[b].z),
vec3(obj.m_verts[c].x, (obj.m_verts[c].y), obj.m_verts[c].z),
vec3(obj.m_vertex_normals[a].x, (obj.m_vertex_normals[a].y), obj.m_vertex_normals[a].z),
vec3(obj.m_vertex_normals[b].x, (obj.m_vertex_normals[b].y), obj.m_vertex_normals[b].z),
vec3(obj.m_vertex_normals[c].x, (obj.m_vertex_normals[c].y), obj.m_vertex_normals[c].z)
);
tri.setMaterialID(mat_id);
m_triangles.push_back(tri);
material_ids.push_back(mat_id);
}
}
void addTriangle(const vec3& a, const vec3& b, const vec3& c, float scale, int mat_id)
{
vec3 n = normalize(cross(b - a, c - a));
TriangleObject tri(a * scale, b * scale, c * scale, n, n, n);
tri.setMaterialID(mat_id);
m_triangles.push_back(tri);
material_ids.push_back(mat_id);
}
};
#endif
class Scene_debug
{
public:
API_Scene m_scene;
Camera *m_camera = nullptr;
std::vector<Material_debug> m_materials;
std::unordered_map<int, int> m_material2Light;
SceneSphere m_sceneSphere;
std::vector<AbstractLight*> m_lights;
BackgroundLight* m_background = nullptr;
public:
Scene_debug()
{
build_scene_1();
std::cout << "lights : " << m_lights.size() << std::endl;
BuildSceneSphere();
}
void addLight(const vec3& a, const vec3& b, const vec3& c, float scale, int mat_id, float brightness)
{
AreaLight *l = new AreaLight(a * scale, b * scale, c * scale);
l->m_intensity = vec3(brightness);
m_lights.push_back(l);
m_material2Light.insert(std::make_pair(mat_id, (int)m_lights.size() - 1));
m_scene.addTriangle(a, b, c, scale, mat_id);
}
void build_scene_0()
{
// care the material id
m_scene.addSphere(6.0f, vec3(10, 70, 51.6f), 2);// light
// m_scene.addSphere(1e5, vec3(1e5 + 1, 40.8, 81.6), 2);// walls
// m_scene.addSphere(1e5, vec3(-1e5 + 99, 40.8, 81.6), 3);
// m_scene.addSphere(1e5, vec3(50, 40.8, 1e5), 4);
// m_scene.addSphere(1e5, vec3(50, 40.8, -1e5 + 350), 4);
// m_scene.addSphere(1e5, vec3(50, 1e5, 81.6), 4);
// m_scene.addSphere(1e5, vec3(50, -1e5 + 81.6, 81.6), 4);
if (1)
{
m_scene.addSphere(1e5f, vec3(1e5f + 1 - 2e5f, 40.8f, 81.6f), 2);// walls
m_scene.addSphere(1e5f, vec3(-1e5 + 99 + 2e5f, 40.8f, 81.6f), 3);
m_scene.addSphere(1e5f, vec3(50, 40.8f, 1e5f - 2e5f), 4);
m_scene.addSphere(1e5f, vec3(50, 40.8f, -1e5f + 350 + 2e5f), 4);
m_scene.addSphere(1e5f, vec3(50, 1e5f - 2e5f, 81.6f), 4);
m_scene.addSphere(1e5f, vec3(50, -1e5f + 81.6f + 2e5f, 81.6f), 4);
}
m_scene.addSphere(20, vec3(50, 20, 50), 5);// objects
m_scene.addSphere(16.5f, vec3(19, 16.5f, 25), 6);
m_scene.addSphere(16.5f, vec3(77, 16.5f, 78), 7);
// Camera
m_camera = new Camera(vec3(50.0f, 40.8f, 220.0f), vec3(50.0f, 40.8f, 0.0f), vec3(0, 1, 0), 512, 512, 40.0f);
//////////////////////////////////////////////////////////////////////////
// Materials
Material_debug mat;
// 0) light1, will only emit
m_materials.push_back(mat);
// 1) light2, will only emit
m_materials.push_back(mat);
// 2) red diffuse
mat.Reset();
mat.m_diffuseReflectance = vec3(0.75, 0.25, 0.25);
// mat.m_phongReflectance = vec3(0.0f);
// mat.m_phongExponent = 90.f;
m_materials.push_back(mat);
// 3) blue diffuse
mat.Reset();
mat.m_diffuseReflectance = vec3(0.25, 0.25, 0.75);
m_materials.push_back(mat);
// 4) white diffuse
mat.Reset();
mat.m_diffuseReflectance = vec3(0.75, 0.75, 0.75);
m_materials.push_back(mat);
// 5) green diffuse
mat.Reset();
mat.m_diffuseReflectance = vec3(0.25, 0.75, 0.25);
m_materials.push_back(mat);
// 6) mirror ball
mat.Reset();
mat.m_mirrorReflectance = vec3(1.0f);
m_materials.push_back(mat);
// 7) glass ball
mat.Reset();
mat.m_mirrorReflectance = vec3(1.0f);
mat.m_IOR = 1.6f;
m_materials.push_back(mat);
// 8) spherical light
mat.Reset();
m_materials.push_back(mat);
//////////////////////////////////////////////////////////////////////////
// Lights
if (1)
{
// // With light box
// m_lights.resize(2);
// AreaLight *l = new AreaLight(m_geometry[0].sample(), m_geometry[0].sample(), m_geometry[0].sample());
// //l->mIntensity = Vec3f(0.95492965f);
// l->m_intensity = vec3(1.03329895614464f);
// m_lights[0] = l;
// m_material2Light.insert(std::make_pair(0, 0));
//
// l = new AreaLight(m_geometry[0].sample(), m_geometry[0].sample(), m_geometry[0].sample());
// //l->mIntensity = Vec3f(0.95492965f);
// l->m_intensity = vec3(1.03329895614464f);
// m_lights[1] = l;
// m_material2Light.insert(std::make_pair(1, 1));
}
if (0)
{
SphericalLight *l = new SphericalLight(vec3(10, 70, 51.6f), 6.0f);
l->m_intensity = vec3(1, 1, 1) / NUM_PI * sq(l->m_radius);
m_lights.push_back(l);
m_material2Light.insert(std::make_pair(8, (int)m_lights.size() - 1));
}
if (0)
{
DirectionalLight *l = new DirectionalLight(vec3(-1.0f, 1.5f, -1.0f));
l->m_intensity = vec3(0.5f, 0.2f, 0.0f) * 20.0f;
m_lights.push_back(l);
}
if (1)
{
PointLight *l = new PointLight(vec3(50, 60, 51.6f));
l->m_intensity = vec3(8000.0f * (0.25f / NUM_PI));
m_lights.push_back(l);
}
if (0)
{
BackgroundLight *l = new BackgroundLight;
l->m_scale = 1.0f;
m_lights.push_back(l);
m_background = l;
}
}
void build_scene_1()
{
const float scale = 0.1f;
const float brightness = 10;// 20; //
#if 1
// care the material id
vec3 cbox_luminaire[] = {
vec3(343, 548.79999f - 0.5f, 227),
vec3(343, 548.79999f - 0.5f, 332),
vec3(213, 548.79999f - 0.5f, 332),
vec3(213, 548.79999f - 0.5f, 227) };
addLight(cbox_luminaire[0], cbox_luminaire[1], cbox_luminaire[2], scale, 8, brightness);
addLight(cbox_luminaire[0], cbox_luminaire[2], cbox_luminaire[3], scale, 9, brightness);
// vec3 cbox_luminaire[] = {
// vec3(343, 548.79999 - 0.5 - 100, 227),
// vec3(343, 548.79999 - 0.5 - 100, 332),
// vec3(213, 548.79999 - 0.5 - 100, 332),
// vec3(213, 548.79999 - 0.5 - 100, 227) };
// addLight(cbox_luminaire[0], cbox_luminaire[2], cbox_luminaire[1], scale, 8, brightness);
// addLight(cbox_luminaire[0], cbox_luminaire[3], cbox_luminaire[2], scale, 9, brightness);
//////////////////////////////////////////////////////////////////////////
vec3 cbox_redwall[] = {
vec3(556, 0, 0),
vec3(556, 0, 559.20001f),
vec3(556, 548.79999f, 559.20001f),
vec3(556, 548.79999f, 0) };
m_scene.addTriangle(cbox_redwall[0], cbox_redwall[1], cbox_redwall[2], scale, 1);
m_scene.addTriangle(cbox_redwall[0], cbox_redwall[2], cbox_redwall[3], scale, 1);
//////////////////////////////////////////////////////////////////////////
vec3 cbox_greenwall[] = {
vec3(0, 0, 559.20001f),
vec3(0, 0, 0),
vec3(0, 548.79999f, 0),
vec3(0, 548.79999f, 559.20001f) };
m_scene.addTriangle(cbox_greenwall[0], cbox_greenwall[1], cbox_greenwall[2], scale, 2);
m_scene.addTriangle(cbox_greenwall[0], cbox_greenwall[2], cbox_greenwall[3], scale, 2);
//////////////////////////////////////////////////////////////////////////
vec3 cbox_floor[] = {
vec3(556, 0, 0),
vec3(0, 0, 0),
vec3(0, 0, 559.20001f),
vec3(556, 0, 559.20001f) };
m_scene.addTriangle(cbox_floor[0], cbox_floor[1], cbox_floor[2], scale, 3);
m_scene.addTriangle(cbox_floor[0], cbox_floor[2], cbox_floor[3], scale, 3);
//////////////////////////////////////////////////////////////////////////
vec3 cbox_back[] = {
vec3(556, 0, 559.20001f),
vec3(0, 0, 559.20001f),
vec3(0, 548.79999f, 559.20001f),
vec3(556, 548.79999f, 559.20001f) };
m_scene.addTriangle(cbox_back[0], cbox_back[1], cbox_back[2], scale, 4);
m_scene.addTriangle(cbox_back[0], cbox_back[2], cbox_back[3], scale, 4);
//////////////////////////////////////////////////////////////////////////
vec3 cbox_ceiling[] = {
vec3(556, 548.79999f, 0),
vec3(556, 548.79999f, 559.20001f),
vec3(0, 548.79999f, 559.20001f),
vec3(0, 548.79999f, 0) };
m_scene.addTriangle(cbox_ceiling[0], cbox_ceiling[1], cbox_ceiling[2], scale, 5);
m_scene.addTriangle(cbox_ceiling[0], cbox_ceiling[2], cbox_ceiling[3], scale, 5);
//////////////////////////////////////////////////////////////////////////
vec3 cbox_smallbox[] = {
vec3(130.000000, 165.000000, 65.000000),
vec3(82.000000, 165.000000, 225.000000),
vec3(240.000000, 165.000000, 272.000000),
vec3(290.000000, 165.000000, 114.000000),
vec3(290.000000, 0.000000, 114.000000),
vec3(290.000000, 165.000000, 114.000000),
vec3(240.000000, 165.000000, 272.000000),
vec3(240.000000, 0.000000, 272.000000),
vec3(130.000000, 0.000000, 65.000000),
vec3(130.000000, 165.000000, 65.000000),
vec3(290.000000, 165.000000, 114.000000),
vec3(290.000000, 0.000000, 114.000000),
vec3(82.000000, 0.000000, 225.000000),
vec3(82.000000, 165.000000, 225.000000),
vec3(130.000000, 165.000000, 65.000000),
vec3(130.000000, 0.000000, 65.000000),
vec3(240.000000, 0.000000, 272.000000),
vec3(240.000000, 165.000000, 272.000000),
vec3(82.000000, 165.000000, 225.000000),
vec3(82.000000, 0.000000, 225.000000),
vec3(290.000000, 0.000000, 114.000000),
vec3(240.000000, 0.000000, 272.000000),
vec3(82.000000, 0.000000, 225.000000),
vec3(130.000000, 0.000000, 65.000000) };
m_scene.addTriangle(cbox_smallbox[ 0], cbox_smallbox[ 1], cbox_smallbox[ 2], scale, 6);
m_scene.addTriangle(cbox_smallbox[ 0], cbox_smallbox[ 2], cbox_smallbox[ 3], scale, 6);
m_scene.addTriangle(cbox_smallbox[ 4], cbox_smallbox[ 5], cbox_smallbox[ 6], scale, 6);
m_scene.addTriangle(cbox_smallbox[ 4], cbox_smallbox[ 6], cbox_smallbox[ 7], scale, 6);
m_scene.addTriangle(cbox_smallbox[ 8], cbox_smallbox[ 9], cbox_smallbox[10], scale, 6);
m_scene.addTriangle(cbox_smallbox[ 8], cbox_smallbox[10], cbox_smallbox[11], scale, 6);
m_scene.addTriangle(cbox_smallbox[12], cbox_smallbox[13], cbox_smallbox[14], scale, 6);
m_scene.addTriangle(cbox_smallbox[12], cbox_smallbox[14], cbox_smallbox[15], scale, 6);
m_scene.addTriangle(cbox_smallbox[16], cbox_smallbox[17], cbox_smallbox[18], scale, 6);
m_scene.addTriangle(cbox_smallbox[16], cbox_smallbox[18], cbox_smallbox[19], scale, 6);
m_scene.addTriangle(cbox_smallbox[20], cbox_smallbox[21], cbox_smallbox[22], scale, 6);
m_scene.addTriangle(cbox_smallbox[20], cbox_smallbox[22], cbox_smallbox[23], scale, 6);
//////////////////////////////////////////////////////////////////////////
vec3 cbox_largebox[] = {
vec3(423.000000, 330.000000, 247.000000),
vec3(265.000000, 330.000000, 296.000000),
vec3(314.000000, 330.000000, 456.000000),
vec3(472.000000, 330.000000, 406.000000),
vec3(423.000000, 0.000000, 247.000000),
vec3(423.000000, 330.000000, 247.000000),
vec3(472.000000, 330.000000, 406.000000),
vec3(472.000000, 0.000000, 406.000000),
vec3(472.000000, 0.000000, 406.000000),
vec3(472.000000, 330.000000, 406.000000),
vec3(314.000000, 330.000000, 456.000000),
vec3(314.000000, 0.000000, 456.000000),
vec3(314.000000, 0.000000, 456.000000),
vec3(314.000000, 330.000000, 456.000000),
vec3(265.000000, 330.000000, 296.000000),
vec3(265.000000, 0.000000, 296.000000),
vec3(265.000000, 0.000000, 296.000000),
vec3(265.000000, 330.000000, 296.000000),
vec3(423.000000, 330.000000, 247.000000),
vec3(423.000000, 0.000000, 247.000000),
vec3(472.000000, 0.000000, 406.000000),
vec3(314.000000, 0.000000, 456.000000),
vec3(265.000000, 0.000000, 296.000000),
vec3(423.000000, 0.000000, 247.000000) };
m_scene.addTriangle(cbox_largebox[ 0], cbox_largebox[ 1], cbox_largebox[ 2], scale, 7);
m_scene.addTriangle(cbox_largebox[ 0], cbox_largebox[ 2], cbox_largebox[ 3], scale, 7);
m_scene.addTriangle(cbox_largebox[ 4], cbox_largebox[ 5], cbox_largebox[ 6], scale, 7);
m_scene.addTriangle(cbox_largebox[ 4], cbox_largebox[ 6], cbox_largebox[ 7], scale, 7);
m_scene.addTriangle(cbox_largebox[ 8], cbox_largebox[ 9], cbox_largebox[10], scale, 7);
m_scene.addTriangle(cbox_largebox[ 8], cbox_largebox[10], cbox_largebox[11], scale, 7);
m_scene.addTriangle(cbox_largebox[12], cbox_largebox[13], cbox_largebox[14], scale, 7);
m_scene.addTriangle(cbox_largebox[12], cbox_largebox[14], cbox_largebox[15], scale, 7);
m_scene.addTriangle(cbox_largebox[16], cbox_largebox[17], cbox_largebox[18], scale, 7);
m_scene.addTriangle(cbox_largebox[16], cbox_largebox[18], cbox_largebox[19], scale, 7);
m_scene.addTriangle(cbox_largebox[20], cbox_largebox[21], cbox_largebox[22], scale, 7);
m_scene.addTriangle(cbox_largebox[20], cbox_largebox[22], cbox_largebox[23], scale, 7);
#endif
//////////////////////////////////////////////////////////////////////////
// Camera
m_camera = new Camera(vec3(278, 273, -800) * scale, vec3(278, 273, -799) * scale, vec3(0, 1, 0), 512, 512, 39.3077f);
//////////////////////////////////////////////////////////////////////////
// Materials
Material_debug mat;
// 0) black diffuse
mat.Reset();
mat.m_diffuseReflectance = vec3(0);
m_materials.push_back(mat);
// 1) red diffuse
mat.Reset();
mat.m_diffuseReflectance = vec3(0.75, 0.25, 0.25);
// mat.m_phongReflectance = vec3(0.0f);
// mat.m_phongExponent = 90.f;
m_materials.push_back(mat);
// 2) green diffuse
mat.Reset();
mat.m_diffuseReflectance = vec3(0.25, 0.75, 0.25);
m_materials.push_back(mat);
// 3) white diffuse
mat.Reset();
mat.m_diffuseReflectance = vec3(1);
m_materials.push_back(mat);
// 4) white diffuse
mat.Reset();
mat.m_diffuseReflectance = vec3(1);
m_materials.push_back(mat);
// 5) white diffuse
mat.Reset();
mat.m_diffuseReflectance = vec3(1);
m_materials.push_back(mat);
// 6) glass ball
mat.Reset();
mat.m_mirrorReflectance = vec3(1.0f);
mat.m_IOR = 1.33f; // 1.6f;
m_materials.push_back(mat);
// 7) mirror ball
mat.Reset();
mat.m_mirrorReflectance = vec3(1.0f);
m_materials.push_back(mat);
// 8) light, will only emit
mat.Reset();
m_materials.push_back(mat);
// 9) light, will only emit
mat.Reset();
m_materials.push_back(mat);
//////////////////////////////////////////////////////////////////////////
// Lights
if (0)
{
SphericalLight *l = new SphericalLight(vec3(10, 70, 51.6f) * scale, 6.0f);
l->m_intensity = vec3(1, 1, 1) / NUM_PI * sq(l->m_radius);
m_lights.push_back(l);
m_material2Light.insert(std::make_pair(8, (int)m_lights.size() - 1));
}
if (0)
{
DirectionalLight *l = new DirectionalLight(vec3(-1.0f, 1.5f, -1.0f));
l->m_intensity = vec3(0.5f, 0.2f, 0.0f) * 20.0f;
m_lights.push_back(l);
}
if (0)
{
PointLight *l = new PointLight(vec3(300, 450, 2.5) * scale);
l->m_intensity = vec3(8000.0f * (0.25f / NUM_PI));
m_lights.push_back(l);
}
if (0)
{
BackgroundLight *l = new BackgroundLight;
l->m_scale = 1.0f;
m_lights.push_back(l);
m_background = l;
}
}
~Scene_debug()
{
for (size_t i = 0; i < m_lights.size(); i++)
{
delete m_lights[i];
}
}
int toLightID(int mat_id) const
{
std::unordered_map<int, int>::const_iterator it =
m_material2Light.find(mat_id);
if (it != m_material2Light.end())
{
return it->second;
}
else
{
return -1;
}
}
HitInfo_debug intersect(const Ray& ray) const
{
HitInfo_debug ret = m_scene.intersect(ray);
return ret;
}
bool Occluded(
const vec3 &_point,
const vec3 &_dir,
float _TMax) const
{
// return false;
Ray ray;
ray.orig = _point + _dir * NUM_EPS_RAY;
ray.dir = _dir;
float tfar = _TMax - NUM_EPS_RAY;
return m_scene.occluded(ray, tfar);
}
const Material_debug& GetMaterial(const int _materialIdx) const
{
return m_materials[_materialIdx];
}
int GetMaterialCount() const
{
return (int)m_materials.size();
}
const AbstractLight* GetLightPtr(int _lightIdx) const
{
_lightIdx = std::min<int>(_lightIdx, static_cast<int>(m_lights.size()) - 1);
return m_lights[_lightIdx];
}
int GetLightCount() const
{
return (int)m_lights.size();
}
const BackgroundLight* GetBackground() const
{
return m_background;
}
void BuildSceneSphere()
{
m_scene.finalize(m_sceneSphere);
std::cout << "scene sphere : ( "
<< m_sceneSphere.m_cenetr.x << ", "
<< m_sceneSphere.m_cenetr.y << ", "
<< m_sceneSphere.m_cenetr.z << " ), "
<< m_sceneSphere.m_radius << std::endl;
}
};
|
RNG65536/MCRT
|
src/examples/splitbvh/debugintersection.h
|
<filename>src/examples/splitbvh/debugintersection.h
#pragma once
#include "ray.h"
// Moller-Trumbore for ray-triangle intersection
// and BVH acceleration for ray-mesh intersection
class Intersection
{
public:
virtual float intersectWith(const Ray& ray) const = 0;
};
|
RNG65536/MCRT
|
src/examples/bssrdf/mesh_sample.h
|
#ifndef meshsample_h__
#define meshsample_h__
#include <vector>
struct Position {
float x, y, z;
struct Payload { int triangle_idx; float u; float v; } payload;
Position();
Position(float x, float y, float z);
// Position(float x, float y, float z, const Payload& p) : x(x), y(y), z(z), payload(p) {}
// Position(const Position& a) : x(a.x), y(a.y), z(a.z), payload(a.payload) {}
static float distanceSquared(const Position& a, const Position& b);
};
int poissonSample(const std::vector<Position>& p_in, std::vector<Position>& p_out, float min_dist);
void check_min_distance(std::vector<Position>& pp);
#endif // meshsample_h__
|
RNG65536/MCRT
|
src/core/constants.h
|
<filename>src/core/constants.h
#pragma once
extern const float NUM_INFINITY;
extern const float NUM_PI;
extern const float NUM_EPS;
extern const float NUM_EPS_DET;
extern const float NUM_EPS_RAY;
extern const float NUM_EPS_COSINE;
// $TODO : rename to avoid conflict
#ifdef M_PI
#undef M_PI
#endif
#ifdef M_PI_2
#undef M_PI_2
#endif
#ifdef M_1_PI
#undef M_1_PI
#endif
#ifdef M_4PI
#undef M_4PI
#endif
#ifdef M_1_4PI
#undef M_1_4PI
#endif
#ifdef M_1_4PIPI
#undef M_1_4PIPI
#endif
extern const float M_PI;
extern const float M_PI_2;
extern const float M_1_PI;
extern const float M_4PI;
extern const float M_1_4PI;
extern const float M_1_4PIPI;
|
RNG65536/MCRT
|
src/examples/bssrdf/bssrdf.h
|
<reponame>RNG65536/MCRT
#ifndef bssrdf_h__
#define bssrdf_h__
#include "vectors.h"
class BSSRDF
{
public:
virtual ~BSSRDF();
virtual vec3 evaluate(const vec3& xi, const vec3& ni, const vec3& wi,
const vec3& xo, const vec3& no, const vec3& wo) = 0;
virtual float evaluate_channel(const vec3& xi, const vec3& ni, const vec3& wi,
const vec3& xo, const vec3& no, const vec3& wo, int i) = 0;
};
class DirectionalDipoleBSSRDF
{
vec3 sigma_s, sigma_a;
float g;
vec3 eta;
vec3 Cp_norm, Cp, Ce, A; // Refractive
vec3 Fdt;
public:
DirectionalDipoleBSSRDF(const vec3& sigma_s, const vec3& sigma_a, float g, const vec3& eta);
vec3 evaluate(const vec3& xi, const vec3& ni, const vec3& wi,
const vec3& xo, const vec3& no, const vec3& wo);
float evaluate_channel(const vec3& xi, const vec3& ni, const vec3& wi,
const vec3& xo, const vec3& no, const vec3& wo, int i);
};
class StandardDipoleBSSRDF
{
vec3 sigma_s, sigma_a;
float g;
vec3 eta;
vec3 Cp, A;
vec3 Fdt;
public:
StandardDipoleBSSRDF(const vec3& sigma_s, const vec3& sigma_a, float g, const vec3& eta);
vec3 evaluate(const vec3& xi, const vec3& ni, const vec3& wi,
const vec3& xo, const vec3& no, const vec3& wo);
float evaluate_channel(const vec3& xi, const vec3& ni, const vec3& wi,
const vec3& xo, const vec3& no, const vec3& wo, int i);
};
#endif // bssrdf_h__
|
RNG65536/MCRT
|
src/core/acceleration/splitbvh.h
|
#pragma once
// NVIDIA split BVH
// Spatial Splits in Bounding Volume Hierarchies
#include <cassert>
#include <iostream>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "aabb.h"
#include "boundedtriangle.h"
#include "logger.h"
#include "constants.h"
#define DEBUG_BINS 0
#define DEBUG_INFO 0
#define ENABLE_MEDIAN_OBJECT_SPLIT 1
#define ENABLE_SAH_OBJECT_SPLIT 1
#define ENABLE_SAH_SPATIAL_SPLIT 1
constexpr int k_x_axis = 0;
constexpr int k_y_axis = 1;
constexpr int k_z_axis = 2;
constexpr int k_sbvh_leaf_node_size = 4;
constexpr int k_sbvh_num_binning_buckets =
16; // 256;
constexpr float k_edge_split_threshold = 1e-3f;
struct SplitBVHNode
{
std::shared_ptr<AABB> bounding_box;
uint32_t debug_level;
std::string debug_tag;
// TOOD : avoid this
virtual bool intersect(Ray& ray, HitInfo& hit_info) const = 0;
};
struct SplitBVHLeafNode : public SplitBVHNode
{
std::shared_ptr<BoundedTriangle> primitive[k_sbvh_leaf_node_size];
bool intersect(Ray& ray, HitInfo& hit_info) const override;
};
struct SplitBVHBranchNode : public SplitBVHNode
{
std::shared_ptr<SplitBVHNode> left_child;
std::shared_ptr<SplitBVHNode> right_child;
int split_axis;
// TODO : remove redundant logics
bool intersect(Ray& ray, HitInfo& hit_info) const override;
};
//////////////////////////////////////////////
// splitting techniques
//////////////////////////////////////////////
struct ClippedBoundCenterComparator
{
ClippedBoundCenterComparator(int split_axis);
bool operator()(const std::shared_ptr<BoundedTriangle>& a,
const std::shared_ptr<BoundedTriangle>& b);
int m_split_axis;
};
struct MedianSplitBVHSplitter
{
MedianSplitBVHSplitter(
const std::vector<std::shared_ptr<BoundedTriangle> >& triangles,
const AABB& node_bound);
float cost() const;
void sort(int& axis,
std::vector<std::shared_ptr<BoundedTriangle> >& left_branch,
std::vector<std::shared_ptr<BoundedTriangle> >& right_branch);
float m_cost = NUM_INFINITY;
int m_split_axis = -1;
int m_mid = -1;
std::vector<std::shared_ptr<BoundedTriangle> > m_triangles;
const AABB& m_node_bound;
};
struct SAHBVHBinningBucket
{
AABB m_bounding_box;
int m_num_entries = 0;
int m_is_valid = 0;
};
struct SAHBVHSplitter
{
SAHBVHSplitter(
const std::vector<std::shared_ptr<BoundedTriangle> >& triangles,
const AABB& node_bound);
float cost() const;
void sort(int& axis,
std::vector<std::shared_ptr<BoundedTriangle> >& left_branch,
std::vector<std::shared_ptr<BoundedTriangle> >& right_branch);
float m_min_cost;
int m_min_axis; // min cost split axis
int m_min_bin; // min cost split bin, index of the first bucket in the
// second child
std::vector<std::shared_ptr<BoundedTriangle> > m_triangles;
const AABB& m_node_bound;
float m_edge[3];
};
struct SplitBVHBinningBucket
{
AABB m_bounding_box;
int m_num_entries = 0;
int m_num_exits = 0;
int m_is_valid = 0;
};
struct SplitBVHSplitter
{
SplitBVHSplitter(
const std::vector<std::shared_ptr<BoundedTriangle> >& triangles,
const AABB& node_bound);
float cost() const;
void sort(int& axis,
std::vector<std::shared_ptr<BoundedTriangle> >& left_branch,
std::vector<std::shared_ptr<BoundedTriangle> >& right_branch);
float m_min_cost;
int m_min_axis; // min cost split axis
int m_min_bin; // min cost split bin, index of the first bucket in the
// second child
const std::vector<std::shared_ptr<BoundedTriangle> >& m_triangles;
const AABB& m_node_bound;
float m_edge[3];
};
class SplitBVH
{
public:
SplitBVH(const std::vector<Triangle>& mesh);
static std::shared_ptr<SplitBVHNode> build(
const std::vector<std::shared_ptr<BoundedTriangle> >& triangles,
uint32_t level,
const std::string& direction);
bool intersect(Ray& ray, HitInfo& hit_info) const;
private:
std::vector<std::shared_ptr<Triangle> > m_triangles;
std::vector<std::shared_ptr<BoundedTriangle> > m_triangle_refs;
std::shared_ptr<SplitBVHNode> m_rootNode;
};
|
RNG65536/MCRT
|
src/core/timer.h
|
#pragma once
class Timer
{
public:
Timer(void);
// get elapsed time from last reset() or class construction. return The
// elapsed time
float getTime(void);
// reset the timer
void reset(void);
~Timer();
private:
void* m_ctx;
};
|
RNG65536/MCRT
|
src/core/volumetric.h
|
#pragma once
#include "vectors.h"
class Ray;
float sampleSegment(float epsilon, float sigma);
vec3 sampleHG(float g /* mean cosine */, float e1, float e2);
float scatter(const Ray& r,
Ray& sRay,
float sigma_s,
float& s,
float e0,
float e1,
float e2);
struct VolumetricProps
{
VolumetricProps();
float scale;
vec3 sigma_s, sigma_a;
vec3 final_sigma_t; // extinction coefficient
vec3 final_sigma_s;
vec3 final_sigma_a;
vec3 albedo; // single scattering albedo
int maxDepths[3];
};
extern VolumetricProps default_medium;
extern const int SSS_DEPTH;
|
RNG65536/MCRT
|
src/core/geometry.h
|
#pragma once
#include <string>
#include "vectors.h"
class Vert;
class OrthonormalFrame
{
vec3 m_x; // tangent
vec3 m_y; // bitangent
vec3 m_z; // normal
public:
OrthonormalFrame();
OrthonormalFrame(const vec3& nl);
void setFromNormal(const vec3& nl);
vec3 toWorld(const vec3& coords) const;
vec3 toLocal(const vec3& coords) const;
const vec3& getTangent() const;
const vec3& getBitangent() const;
const vec3& getNormal() const;
};
vec3 reflectWorld(const vec3& wi, const vec3& nl);
vec3 reflectLocal(const vec3& wi);
float cosineFactor(const vec3 wi, const vec3& nl);
float fresnelReflectance(float cos_theta_i, float ior);
// local sampling PDFs and standard terms
float geometryTerm(const Vert& e0, const Vert& e1);
float geometryTerm(const vec3& p0,
const vec3& n0,
const vec3& p1,
const vec3& n1);
// pdf conversion, r^2 falloff
float directionToArea(const Vert& current, const Vert& next);
//////////////////////////////////////////////////////////////////////////
// Utilities for converting PDF between Area (A) and Solid angle (W)
// WtoA = PdfW * cosine / distance_squared
// AtoW = PdfA * distance_squared / cosine
// -- cosThere = cosine on the emitter
// -- pdfW = 1 / Omega = r^2 / (Omega * r^2) = pdfA_proj * r^2 = pdfA / cos *
// r^2
// -- A_proj = A * cos, and pdf is reciprocal to A for the same sample space
float pdfWtoA(const vec3& v0, const vec3& v1, const vec3& n1);
float pdfAtoW(const vec3& v0, const vec3& v1, const vec3& n1);
float pdfWtoA(float pdfW, float dist, float cosineThere);
float pdfAtoW(float pdfA, float dist, float cosineThere);
float __pdfWtoA(float pdfW, float dist_sq, float cosineThere);
float __pdfAtoW(float pdfA, float dist_sq, float cosineThere);
bool isAligned(const vec3& a, const vec3& b);
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.